WMI Collections and Queries

As discussed in the previous section, you can connect to the WMI service on the local computer or a remote computer and obtain a WMI object at any of three levels in the namespace hierarchy:

You can connect at the level of the entire namespace with a path such as \root\CIMV2. The resulting object is called an SWbemServices object, which has methods and properties that let you obtain lower-level objects representing the parts of Windows you want to manage. One of its methods lets you extract information from WMI using a special query language called the Windows Management Instrumentation Query Language (WQL).

You can connect to a specific management object with a path such as \root\CIMV2:Win32_DiskDrive. The resulting object is an SWbemObject object, but it represents a category, not a real manageable item. To obtain objects that represent items in the category, you can use its Instances_ property to obtain a collection called SWbemObjectSet.

You can connect to a specific instance of a management object with a path such as \root\CIMV2:Win32_DiskDrive="C". This isn't always easy, because some of the qualifying parameters are very strange. I'll discuss this in a moment. These instances are represented by SWbemObject, whose properties and methods let you manage the part of Windows the object represents.