C# .NET - C# WMI_Process namespace methods - Asked By Perry on 31-Aug-10 10:03 AM

Hi, could anyone please tell me how would I get the all methods available in WMI_Process (or in general any WMI namespace) namespace?

Thanks.

Super Man replied to Perry on 31-Aug-10 10:32 AM

Hi tried to get using by writing this code:

   

        ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_BIOS");

 

        foreach (ManagementObject mo in mos.Get())

        {

          Type mytype = mo.GetType();

          MethodInfo[] mi = mytype.GetMethods();

          foreach (MethodInfo m in mi)

          {

            listBox2.Items.Add(m.Name);

          }

          break;

 

        }

but it doesn't works,

it gives method of management object.

you can see all the method here,"

http://msdn.microsoft.com/en-us/library/aa394372(VS.85).aspx

 

Perry replied to Super Man on 31-Aug-10 10:43 AM
I think you are correct. We can get them using Reflaction but yes, the code you have given is not working. Not sure but we need to find some method that get called on ManagementObject class which returns the set of methods.

The link is helpful but I am looking for generic solution so that it can be applied to any WMI namespace to get the method names.

Regards.
Super Man replied to Perry on 31-Aug-10 12:02 PM
i know about wmi classes,

i always use Invokemethod of managementobject class, never try to get method name programmatically

i will try it, if i got solution , i will post here.

if you get it, then post for me & others.


thanks.
Perry replied to Super Man on 31-Aug-10 12:04 PM
Sure. Will do without fail.

In general, how did you get the methods available in WMI namespace then?

Regards.
Perry replied to Super Man on 02-Sep-10 04:15 AM
Khan, here is the solution. You need to use metadata.

ManagementObjectSearcher q = new ManagementObjectSearcher(@"SELECT * FROM meta_class WHERE __this ISA ""Win32_Process""");

Dictionary<string, List<string>> classes = new Dictionary<string, List<string>>();

foreach (ManagementClass c in q.Get())

{

Console.WriteLine(c.Path.ClassName);

foreach (MethodData m in c.Methods)

Console.WriteLine(" " + m.Name);

}

Output:

Win32_Process
   Create
   Terminate
   GetOwner
   GetOwnerSid
   SetPriority
   AttachDebugger

Cheers!

Super Man replied to Perry on 03-Sep-10 12:33 PM
thanks raj...