Using WMI in .NET

Finally posting after so many days 🙂

Recently, I had to work with the WMI (Windows Management Instrumentation) and its support in the .NET. I had to evaluate all the services running in the System and other information related to the processor etc.

WMI is a really wonderful API to use but is mysterious about its working, but Win32 API’s are always mysterious. You don’t know what is happening and how? All you get from the MSDN is the info about how to use them with an ordinary code example which in most cases is not useful at all and doesn’t seem to explain anything.

So here is a little code in .NET

static void Main(string[] args)


System.Management.ManagementObjectSearcher searcher =

new ManagementObjectSearcher

(“SELECT * FROM Win32_SystemProcesses”);

foreach (ManagementObject service in searcher.Get())


foreach(System.Management.PropertyData pData in service.Properties)


                  Console.WriteLine(pData.Name + ” = ” + pData.Value);





This code lists all the attribute names and their values associated with a typical WMI class. You can replace other WMI Classes available with the Win32_SystemProcesses in the above code to obtain other information. There are a number of WMI classes Win32_SystemBIOS, Win32_SystemDesktop, Win32_Processor and many others.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s