IWbemServices interface (wbemcli.h)

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 from the IUnknown interface. IWbemServices also has these types of members:


The IWbemServices interface has these methods.


The IWbemServices::CancelAsyncCall method cancels any currently pending asynchronous calls based on the IWbemObjectSink pointer, which was originally passed to the asynchronous method.

The IWbemServices::CreateClassEnum method returns an enumerator for all classes that satisfy selection criteria.

The IWbemServices::CreateClassEnumAsync method returns an enumeration of all classes that the class provider supports.

The IWbemServices::CreateInstanceEnum method creates an enumerator that returns the instances of a specified class according to user-specified selection criteria.

The IWbemServices::CreateInstanceEnumAsync method creates an enumerator that asynchronously returns the instances of a specified class according to user-specified selection criteria.

The IWbemServices::DeleteClass method deletes the specified class from the current namespace.

The IWbemServices::DeleteClassAsync method deletes the specified class from the current namespace.

The IWbemServices::DeleteInstance method deletes an instance of an existing class in the current namespace.

The IWbemServices::DeleteInstanceAsync method asynchronously deletes an instance of an existing class in the current namespace. The confirmation or failure of the operation is reported through the IWbemObjectSink interface implemented by the caller.

Executes a method exported by a CIM object.

Asynchronously executes a method exported by a CIM object.

The IWbemServices::ExecNotificationQuery method executes a query to receive events. The call returns immediately, and the user can poll the returned enumerator for events as they arrive. Releasing the returned enumerator cancels the query.

The IWbemServices::ExecNotificationQueryAsync method performs the same task as IWbemServices::ExecNotificationQuery except that events are supplied to the specified response handler until CancelAsyncCall is called to stop the event notification.

The IWbemServices::ExecQuery method executes a query to retrieve objects.

The IWbemServices::ExecQueryAsync method executes a query to retrieve objects asynchronously.

The IWbemServices::GetObject method retrieves a class or instance. This method only retrieves objects from the namespace associated with the current IWbemServices object.

The IWbemServices::GetObjectAsync method retrieves an object, either a class definition or instance, based on its path.

The IWbemServices::OpenNamespace method provides the caller with a new IWbemServices pointer that has the specified child namespace as its operating context.

The IWbemServices::PutClass method creates a new class or updates an existing one. The class specified by the pObject parameter must have been correctly initialized with all of the required property values.

The IWbemServices::PutClassAsync method creates a new class, or updates an existing one.

The IWbemServices::PutInstance method creates or updates an instance of an existing class. The instance is written to the WMI repository.

The IWbemServices::PutInstanceAsync method asynchronously creates or updates an instance of an existing class. Update confirmation or error reporting is provided through the IWbemObjectSink interface implemented by the caller.

The IWbemServices::QueryObjectSink method allows the caller to obtain a notification handler that is exported by Windows Management.


Providers that implement the IWbemServices interface must follow the documented semantics of each method that they implement; and providers must support the specified error return codes. WMI implements all of the methods, and typically, each provider implements a small subset of the available functionality on the interface. Providers must return WBEM_E_PROVIDER_NOT_CAPABLE for any method that they do not implement.

All outbound interface pointers from any IWbemServices method should be initialized to NULL before calling the interface method. For example, calls to the IWbemServices::GetObject method return an IWbemClassObject interface pointer that should be pre-initialized to NULL before the IWbemServices::GetObject method call.


For multiple C++ examples that use IWbemServices, see the WMI C++ Application Examples section.

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 <iostream>
using namespace std;
#include <wbemidl.h>
#pragma comment(lib, "wbemuuid.lib")
IWbemLocator *pIWbemLocator = NULL;

HRESULT hRes = CoCreateInstance (
            NULL ,
            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

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

// Use pWbemServices


// Clean up


Minimum supported client Windows Vista
Minimum supported server Windows Server 2008
Target Platform Windows
Header wbemcli.h (include Wbemidl.h)

See also


Creating WMI Providers

Manipulating Class and Instance Information

Supplying Data to WMI by Writing a Provider