|
-
Sep 19th, 2003, 01:55 AM
#1
Thread Starter
Lively Member
Implementing a method that can be called with WMI *dead but unresolved*
Here is what I have right now:
Code:
//Class1.cs
using System;
using System.Management;
using System.Configuration.Install;
using System.Management.Instrumentation;
namespace WmiTest
{
[System.ComponentModel.RunInstaller(true)]
public class MyInstaller : DefaultManagementProjectInstaller {}
class Class1
{
//[STAThread]
public static int Main(string[] args)
{
InstanceClass instClass = new InstanceClass();
instClass.Name = "Hello World 01";
instClass.Number = 1;
Instrumentation.Publish(instClass);
InstanceClass instClass2 = new InstanceClass();
instClass2.Name = "Hello World 02";
instClass2.Number = 2;
Instrumentation.Publish(instClass);
Instrumentation.Publish(instClass2);
Console.WriteLine("Instance now visible through WMI");
Console.ReadLine();
Instrumentation.Revoke(instClass); //optional
Instrumentation.Revoke(instClass2); //optional
return 0;
}
}
[InstrumentationClass(InstrumentationType.Instance)]
public class InstanceClass
{
public string Name = "";
public int Number = 0;
public void TestMethod()
{
Console.WriteLine("asdf");
}
}
Code:
//AssemblyInfo.cs
//This also was added to this file.
using System.Management.Instrumentation;
[assembly:Instrumented("root/test")]
I'm trying to call the method TestMethod from a wmi script and it says it doesn't exist, however I can access the Name or Number properties!
Here is my wmi script:
Code:
' put this code in a file with an extension .vbs to run it
set wmi = GetObject("winmgmts:root/test")
wql = "SELECT * from InstanceClass"
set result = wmi.ExecQuery(wql)
For Each instance in result
MsgBox instance.Name & ": " & instance.Number
instance.TestMethod
Next
Thanks guys,
Mitchel
Last edited by toto; Oct 10th, 2003 at 12:10 AM.
-
Sep 25th, 2003, 01:52 AM
#2
Thread Starter
Lively Member
*bump*
I really need help with this!
Thanks again guys,
Mitchel
-
Sep 25th, 2003, 03:16 PM
#3
What's WMI?
Maybe you need some attribute on the function too?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 25th, 2003, 03:24 PM
#4
Try giving it a different name using ManagedNameAttribute, maybe it finds it by that name.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Sep 26th, 2003, 02:08 PM
#5
Thread Starter
Lively Member
WMI is Windows Management Instrumentation it's something windows software implements for simple management. IIS uses it and with a simple script you can add and remove IIS websites for example without using a DLL.
I'll look into that attribute.. thanks.
Mitchel
-
Oct 10th, 2003, 12:10 AM
#6
Thread Starter
Lively Member
* one last bump * =)
If it isn't possible I guess I'll just have to give up on it.
Thanks anyways guys,
Mitchel
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|