This Blog Has Been Moved !

This Blog Has been moved to http://aleemkhan.wordpress.com

Finally posting after so many days J.

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);

            }

      }

      Console.ReadLine();

}

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.

Comments

0 comments have been posted.