Working with Windows Management Instrumentation

Windows Management Instrumentation (WMI) is a COM based technology used to get system-related information. Such information may include hardware resources like, the motherboard, memory, disk, etc. You can use WMI to communicate with the Windows OS, the hardware devices, running processes, COM+ components, etc. In this article we will discuss the basics of WMI and then explore how we can make use of WMI in our applications.

Windows Management Instrumentation (WMI)

Windows Management Instrumentation (WMI) provides a robust, low-level communication with the Windows Operating System from the managed environment. You can use WMI to communicate with the system’s hardware and still leverage the benefit of the CLR's managed environment, automated memory management, garbage collection, etc.  Actually, Windows Management Instrumentation (WMI) provides a set of extensions to the Windows Driver Model. These extensions can be accessed from the managed environment.

WMI includes the following providers:

Win32 Provider

WDM Provider

Event Log Provider

Registry Provider

SNMP Provider

View Provider

Performance Counter Provider

Active Directory Provider

Windows Installer Provider

The WMI Query Language

The WMI Query Language, a subset of the American National Standard Query Language (ANSI SQL), is much the same as any other standard query language and is used to retrieve system management information.

The following query retrieves the information of all the logical disk drives in your system.

Select * from Win32_LogicalDisk

To retrieve processor details in your computer system, you’ll need to write the following query:

SELECT * FROM Win32_Processor

Note that all WMI classes follow a language format known as the Managed Object Format (MOF).

To use WMI in your applications, you’ll need to include the following namespaces:




Programming WMI

In this section we will explore WMI – we will use WMI to retrieve CPU ID, MAC ID and Volume Serial Number of a drive in your system. The CPU ID identifies the CPU of the computer's central processor. The information includes model number, processor family, cache size, clock speed, and also the manufacturer codename. The Media Access Control or MAC address is the Network Interface Card address. It is composed of 12 hexadecimal characters (0-9, A-F) and is defined as a unique identifier used to identify most network equipment. Note that every network device has a unique MAC address. The Volume Serial Number of a drive is a running serial number that is generated for every format of the drive.

The following code snippet illustrates how you can display the drive information of your system:

ManagementObjectSearcher managementObjectSearcherQuery = new ManagementObjectSearcher
    ("SELECT * From Win32_LogicalDisk ");
ManagementObjectCollection managementObjectCollectionQueryCollection = managementObjectSearcherQuery.Get(); 
foreach ( ManagementObject managementObject in managementObjectCollectionQueryCollection) 
    switch (int.Parse( managementObject["DriveType"].ToString())) 
        case Removable: //Removable drives 
        case LocalDisk: //Local drives 
        case CD: //CD drives 
        case Network: //Network drives 
      Console.WriteLine("Drive: " + managementObject["Name"].ToString()); 

To retrieve the volume serial number of any drive in your system you can write the following code:

                                public string GetVolumeSerial(string strDriveLetter)
                if( strDriveLetter=="" || strDriveLetter==null) strDriveLetter="C";
                ManagementObject disk = 
                     new ManagementObject("win32_logicaldisk.deviceid=\"" + strDriveLetter +":\"");
                return disk["VolumeSerialNumber"].ToString();

To retrieve the MAC address of the first network card in your system, you can write the following code;

                                public string GetMACAddress()
                ManagementClass managementClass = new ManagementClass("Win32_NetworkAdapterConfiguration");
                ManagementObjectCollection managementObjectCollection = managementClass.GetInstances();
                string MACAddress=String.Empty;
                foreach(ManagementObject managementObject in managementObjectCollection)
                           if((bool)managementObject["IPEnabled"] == true) 
                           MACAddress= managementObject["MacAddress"].ToString() ;
                MACAddress = MACAddress.Replace(":","");
                return MACAddress;

To retrieve the processor id of the first processor, you can write the following code:

                                public string GetProcessorID()
                string cpuInfo =  String.Empty;
                ManagementClass managementClass = new ManagementClass("Win32_Processor");
                ManagementObjectCollection managementObjectCollection = managementClass.GetInstances();
                foreach(ManagementObject managementObject in managementObjectCollection)
                         cpuInfo = managementObject.Properties["ProcessorId"].Value.ToString();                         
                return cpuInfo;



WMI, an implementation of the WBEM standards, is a key component of Microsoft Windows management services and provides a framework for accessing system level information from the managed environment. This article presented an overview of WMI, WMI Query Language and an idea on how we can leverage WMI in our applications. Happy reading!

Related Articles


  • Wholesale Oakley M Frame sale for cheap

    Posted by qpetssjbe on 06/25/2013 06:46am

    Cheap Ray Bans ,Oakley sunglasses created to change each year, exactly like another style?? However, your choices are very different game situations, there is no truly fashion. Product design or collection of materials, happen to be some advanced scientific experiments and testing to guarantee its comfort and excellent, high level of integration as well as the function and fashion. Cheap Oakley Sunglasses ,Oakley sunglasses, adjusted for changes in per year resembles other ways. However, the alternatives are very different, there isn't any real fashion lovers the prospect. That summertime is resulting, it will always be a better plan, looking to find the many outdoor activities, protection, and cheap Oakley sunglasses. Oakley Holbrook ,Oakley sunglasses are not only steer clear of the sun, however the other hit the decorative surface. The trendy appearance and fashion style, it's going to be your sensible choice. How you can protect their eyes? The correct answer is in glasses. Select the sunglasses, beyond just the sunglasses can protect you, it ought to be a fashion and lifestyle. Know used sheet metal sunglasses, for a period of time could be slightly deformed, the industry normal phenomenon. Dealer Executive to adjust to. Oakley sports sunglasses better sunglasses sold to locate. You'll find a framework and coated lenses to adjust to every face type. From one to exist in a sun will not take away the hazard, however marked complexion and eyes from the proliferation of lengthy, long-term harm to UV to lessen a person's eye, which became stop the harm for the eye compared to the amount of ultraviolet illumination from the individual's life may be great for. If your UV radiation intensity is just right visual turbidity, it can be the result of the well-being in the ultraviolet light of solar power. Oakley sunglasses shape and metal metal injection molding, developing a convenient button to discharge each shot, the handle to the smallest detail. A contemporary gradient with Oakley sunglasses for female: they provide 100% Ultraviolet shield, luxury and ambitions are clear. Whether you should modify?? You to adjust to your sunglasses, which may be done by a similar company, it may guarantee a similar service quality, mixing style and practicality. Oakley sunglasses, you'll pick a qualified sunglasses, Oakley sunglasses popular Oakley sunglasses are selling on earth.

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • As all sorts of data becomes available for storage, analysis and retrieval - so called 'Big Data' - there are potentially huge benefits, but equally huge challenges...
  • The agile organization needs knowledge to act on, quickly and effectively. Though many organizations are clamouring for "Big Data", not nearly as many know what to do with it...
  • Cloud-based integration solutions can be confusing. Adding to the confusion are the multiple ways IT departments can deliver such integration...

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date