SELECT Statement for Schema Queries
Schema data queries use the SELECT statement with a syntax similar to that for data queries. The difference is the use of a special class called "meta_class", which identifies the query as a schema query.
The following example requests all class definitions that are within the current namespace.
SELECT * FROM meta_class
Schema queries only support "*". To narrow the scope of the definitions returned, a provider can add a WHERE clause that specifies a particular class.
The following example shows how to add a WHERE clause to specify a particular class.
SELECT * FROM meta_class WHERE __this ISA "Win32_LogicalDisk"
The special property called __this identifies the target class for a schema query. Note that the ISA operator must be used with the __this property to request definitions for the subclasses of the target class. The preceding query returns the definition for the Win32_LogicalDisk class and definitions for all of its subclasses.
The following example shows how to request a class definition for a single class by using the __Class system property.
SELECT * FROM meta_class WHERE __Class = "Win32_LogicalDisk"
This query is equivalent to calling the IWbemServices::GetObject or the IWbemServices::GetObjectAsync method with the object path parameter set to "Win32_LogicalDisk".
Send comments about this topic to Microsoft
Build date: 3/9/2012
__Dynasty WMI system property holds the name of the top-level class from which a class is derived. You can use it to retrieve all classes in a namespace derived from a top level class, including that class. Here is a VBScript sample:
' VBScript source code
' Retrieve immediate child classes for Cim_DataFile
Set objWmi = GetObject ("winmgmts:root\cimv2")
Set colClasses = objWmi.ExecQuery _
("Select * From meta_class " _
& "Where __Dynasty = 'Win32_CurrentTime'")
For Each objClass In colClasses
WScript.Echo objClass.SystemProperties_("__Class")
Next
The output is:
Win32_CurrentTime
Win32_LocalTime
Win32_UTCTime
- 5/31/2009
- urkec
The following query allows you to retrieve immediate child classes for a WMI class:
Select * From meta_class Where __SuperClass = "Cim_DataFile"
This VBScript sample gets all the immediate child classes for Cim_DataFile class:
' VBScript source code
' Retrieve immediate child classes for Cim_DataFile
Set objWmi = GetObject ("winmgmts:root\cimv2")
Set colClasses = objWmi.ExecQuery _
("Select * From meta_class " _
& "Where __Superclass = 'Cim_DataFile'")
For Each objClass In colClasses
WScript.Echo objClass.SystemProperties_("__Class")
Next
The script produces the following output (Windows Xp SP3):
Win32_ShortcutFile
Win32_CodecFile
Win32_NTEventlogFile
Win32_PageFile
For all the top level classes in a WMI namespece the __Superclass system property is Null, so it is possible to retrieve them using this query:
Select * From meta_class Where __Superclass Is Null
Here is a VBScript sample that retrieves all the top classes in Root\Cimv2 WMI namespace:
' VBScript source code
' Retrieve top level classes in root\cimv2
Set objWmi = GetObject ("winmgmts:root\cimv2")
Set colClasses = objWmi.ExecQuery _
("Select * From meta_class Where __Superclass Is Null")
For Each objClass In colClasses
WScript.Echo objClass.SystemProperties_("__Class")
Next