Редактиране

Споделяне чрез


Describing a Class Object Path

A class object path describes the location of a class within a namespace.

You can use the following methods to specify an object path:

  • A full object path to a class appends the class name to a namespace path.

    The following example shows the location of the Win32_LogicalDisk class within the \root\cimv2 namespace on the server named Admin.

    \\Admin\Root\CimV2:Win32_LogicalDisk
    
  • A relative object path represents a class that resides in the current namespace. A relative object path to a class contains only the class name.

    The following example shows the relative path to the Win32_LogicalDisk class.

    Win32_LogicalDisk
    

When you query for a class name but specify no instances, WMI returns the class definition. The following procedure describes how to retrieve a class definition in VBScript.

To retrieve a class definition in VBScript

  • You can use the moniker connection either with a query or GetObject. You can also use SWbemServices.Get.

    The following example shows how to use GetObject to get a class definition.

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
       & "{impersonationLevel=impersonate}!\\" _
       & strComputer & "\root\cimv2:Win32_Printer")
    

    The following example shows how to query for a class definition.

    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
        & "{impersonationLevel=impersonate}!\\" _
        & strComputer & "\root\cimv2")
    Set colInstalledPrinters =  objWMIService.ExecQuery _
        ("Select * from Win32_Printer")
    

You can retrieve a class definition in C++ by specifying only the class name and no path to a particular instance. The following procedure describes how to retrieve a class definition in C++.

To retrieve a class definition in C++

  • Make a call to the IWbemServices::GetObject or IWbemServices::GetObjectAsync functions.

    The following example shows how to call theIWbemServices::GetObject function.

    IWbemServices* pSvcs = 0;
    
    BSTR Path = SysAllocString(L"Win32_LogicalDisk");
    IWbemClassObject *pDiskClass = 0;
    pSvcs->GetObject(Path, 0, 0, &pDiskClass, 0);
    

    The previous code example requires the following #include statement to compile correctly.

    #include <wbemidl.h>