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:

System.Diagnostics

System.Management

System.Management.Instrumentation

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:

Conclusion

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!