Describing an Instance Object Path
An instance object path describes the location of an instance of a given class within a specific namespace.
You can have several different kinds of instance object paths:
A full instance object path appends the name and value of the key property for the class to a full class object path.
The following example shows the definition of the full instance object path.
A relative object path refers to an instance located in the current namespace on the current server. The relative path consists of the class name followed by the names and values of the key properties of this instance.
The following example shows the definition of the relative instance object path.
Relative with a single key
For classes with only one property designated as the key, you can omit the name of the key property.
The following example shows the definition of the relative instance object path with a single key.
Relative with multiple keys
Use a comma to distinguish between the keys of an instance with multiple keys.
The following example shows the definitions of the relative instance object path with multiple keys.
Relative for a singleton class
The relative object path for a singleton class consists of the class name followed by the "=@" notation.
The following example shows the definition of the relative instance object path for a singleton class.
The following procedure describes how to retrieve a class instance.
To retrieve a class instance
- Initialize a string that contains the object path with a call to the SysAllocString function.
- Initialize an object that will receive the instance.
The following #include statement is required for the code that is listed later in this topic to compile correctly.
The following code example describes how to retrieve a class instance using an object path.
IWbemServices* pWbemSvcs = 0; BSTR Path = SysAllocString(L"ComPort=2"); IWbemClassObject *pComPort = 0; pWbemSvcs->GetObject(Path, 0, 0, &pComPort, 0);
For instances of classes that specify multiple properties as the key, WMI requires no specific ordering of key properties in object paths. You need only specify the value of each of the properties in the object path.
The following code example describes two equivalent key descriptions.