Retrieving a Class
The first type of object you can retrieve is a WMI class. When retrieving a WMI class, you actually retrieve a class definition, which is a listing of the properties, qualifiers, and methods that fully describe the class. However, a class definition is basically the class itself.
You can retrieve a class definition in VBScript in a similar way to retrieving a specific instance.
To retrieve a class definition in VBScript
- Call SWbemServices.Get but do not identify a specific instance in the object path for the class.
The following code example retrieves the class definition for the class that describes logical drives on your computer.
Windows Script Host (WSH) also supports the following.
- A class or instance can also be specified, in which case the returned object is a WMI object, for example, an instance of Win32_LogicalDisk, rather than a services object. Note that you cannot use the VBScript GetObject functions to create an instance of the generic object SWbemObject.
- In HTML pages running in Microsoft Internet Explorer (IE), GetObject and CreateObject can fail because WMI scripting objects, like ActiveX controls, are not marked as safe for scripting. The one exception is the SWbemDateTime object. The only way that these calls can succeed is when you lower the IE security settings, which is not recommended.
To retrieve a class definition in C++
- Call the IWbemServices::GetObject or IWbemServices::GetObjectAsync methods to retrieve the definition of a class.
- One class can have multiple class definitions, which happens typically when you have more than one class provider loaded into one namespace. When a class has multiple class definitions, WMI returns the first definition discovered and the WBEM_S_DUPLICATE_OBJECTS status code.