In addition to providing access to the namespace and the
Win32_ComputerSystem object of a computer system, the
IWMIExtension interface also provides access to the path for the
Win32_ComputerSystem object. By accessing the
WMIObjectPath property that contains the WMI object path, developers can use the path in calls to other methods. Like
GetWMIObject, Directory Services currently supports
WMIObjectPath on Directory Services Computer objects only.
Note For more information about support and installation of this component on a specific operating system, see Operating System Availability of WMI Components.
The following procedure describes how to access the object path for a remote Win32_ComputerSystem object.
To access the object path for a remote Win32_ComputerSystem object
- Determine the name of the computer that contains the
Win32_ComputerSystem path you wish to access.
You need the name of the computer to locate the computer on the enterprise. The most common way to locate a computer is to query Active Directory. For more information, see
Directory Services. Active Directory uses the current Directory Services security settings for the user. Make sure the user has the correct level of access before attempting to use Active Directory.
- Query Active Directory for the location of the remote computer.
Visual Basic programmers can call the GetObject function. Microsoft Visual C++ programmers should use ADsGetObject.
The WMI ADSI extension sets the value of
WMIObjectPath for Visual Basic when
GetObject returns the instantiated ADSI object.
- Use
WMIObjectPath or get_WMIObjectPath to access the moniker containing the object path.
Visual Basic programmers can call
WMIObjectPath directly on the returned object. Visual C++ programmers can call get_WMIObjectPath on a pointer to the WMI object.
The WMI ASDI extension sets the value of
WMIObjectPath for Visual C++ when you call the QueryInterface method for
IWMIExtension.
Directory Services uses the current WMI user security settings to access the Computer object.
The following example shows how to access the WMIObjectProperty property using Visual Basic.
Dim ADSObject As IADs
' Query Active Directory for your computer.
Set ADSObject = GetObject("LDAP://CN=<computer name>, _
CN=Computers,DC=<domain>,DC=<company>,DC=com")
Debug.Print "WMI Object Path: " + ADSObject.WMIObjectPath
The following example shows how to access the WMIObjectProperty property using Visual C++.
IADs *pComputer = NULL;
IWMIExtension *pWMI = NULL;
wchar_t Obj[80] = L"LDAP://CN=<computer name,CN=Computers,DC=<domain>,DC=<company>,DC=com";
CoInitialize (NULL);
//Query Active Directory to get your computer.
HRESULT hRes = ADsGetObject( Obj, IID_IADs,
(void**)&pComputer );
//Get the WMI ADSI extension interface on this object.
hRes = pComputer->QueryInterface(
IID_IWMIExtension, (void**)&pWMI);
//Use the get_function of WMIObjectPath
// to get the property value
// from WMIObjectPath.
BSTR strObjectPath;
hRes = pWMI->get_WMIObjectPath(&strObjectPath);
wprintf(L"WMIObjectPath: %s\n", strObjectPath);
SysFreeString(strObjectPath);
//Cleanup
pWMI->Release();
pComputer->Release();
The C++ code requires the following references and #include statements to compile correctly.
# pragma comment(lib, "wbemuuid.lib")
#include <iostream>
using namespace std;
#include <Iads.h>
#include <Wbemads.h>
#include <Adshlp.h>
See Also
- Managing Objects on a Network
Send comments about this topic to Microsoft
Build date: 11/3/2009