WMI - IWbemServices Interface

IWbemServices Interface

The IWbemServices interface is used by clients and providers to access WMI services. The interface is implemented by WMI and WMI providers, and is the primary WMI interface.

IWbemClassObject *pObj = NULL;

//The pWbemSvc pointer is of type IWbemServices*
pWbemSvc->GetObject(L"path", 0, 0, &pObj, 0);

The IWbemServices interface inherits the methods of the IUnknown interface.

You can use the WMI Component Object Model (COM) API to write management client applications or create a new WMI provider. The COM API reference provides information for advanced system administrators, as well as developers who are writing client and provider applications.

For more information about writing WMI enterprise management applications, see Creating a WMI Application Using C++.

Examples

The following code example shows how a provider can get an IWbemServices pointer. The code requires the following #include statements and references to compile.

#include
using namespace std;
#include
# pragma comment(lib, "wbemuuid.lib")

IWbemLocator *pIWbemLocator = NULL;

HRESULT hRes = CoCreateInstance (
CLSID_WbemAdministrativeLocator,
NULL ,
CLSCTX_INPROC_SERVER CLSCTX_LOCAL_SERVER ,
IID_IUnknown ,
( void ** ) &pIWbemLocator
) ;

IWbemServices *pWbemServices = NULL;

if (SUCCEEDED(hRes))
{
hRes = pIWbemLocator->ConnectServer(
L"root\\CIMV2", // Namespace
NULL, // Userid
NULL, // PW
NULL, // Locale
0, // flags
NULL, // Authority
NULL, // Context
&pWbemServices
);

pIWbemLocator->Release(); // Free memory resources.

// Use pWbemServices

}

// Clean up
pWbemServices->Release();


References:
Creating a WMI Application Using C++ :
http://msdn.microsoft.com/en-us/library/aa389762(VS.85).aspx