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




Reply With Quote