Export (0) Print
Expand All

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.

Aa393244.wedge(en-us,VS.85).gifTo retrieve a class definition in VBScript

  1. Call SWbemServices.Get but do not identify a specific instance in the object path for the class.
  2. The following code example retrieves the class definition for the class that describes logical drives on your computer.

    
    Set objinst = GetObject("WinMgmts:Win32_LogicalDisk")
    
    

    Windows Script Host (WSH) also supports the following.

    
    <OBJECT id="myLocator" progid="WbemScripting.SWbemLocator"></OBJECT>
    
    

    On Active Server Pages (ASP) use GetObject or CreateObject in the server-side script. For more information, see Creating Active Server Pages for WMI.

  3. 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.
  4. 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.

When retrieving a class in C++, call the IWbemServices version of GetObject.

Aa393244.wedge(en-us,VS.85).gifTo retrieve a class definition in C++

  1. Call the IWbemServices::GetObject or IWbemServices::GetObjectAsync methods to retrieve the definition of a class.
  2. 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.

 

 

Show:
© 2014 Microsoft