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);

Methods

The IWbemServices interface inherits the methods of the IUnknown interface.

In addition, IWbemServices defines the following methods.

MethodDescription

OpenNamespace

Opens a specific child namespace for operations.

CancelAsyncCall

Cancels a currently executing asynchronous call.

QueryObjectSink

Allows a caller to obtain a notification handler sink.

GetObject

Retrieves an object—an instance or class definition.

GetObjectAsync

Asynchronously retrieves an object—an instance or class definition.

PutClass

Creates or updates a class definition.

PutClassAsync

Asynchronously creates or updates a class definition.

DeleteClass

Deletes a class.

DeleteClassAsync

Deletes a class and receives confirmation asynchronously.

CreateClassEnum

Creates a class enumerator.

CreateClassEnumAsync

Creates a class enumerator that executes asynchronously.

PutInstance

Creates or updates an instance of a specific class.

PutInstanceAsync

Asynchronously creates or updates an instance of a specific class.

DeleteInstance

Deletes a specific instance of a class.

DeleteInstanceAsync

Deletes an instance and provides confirmation asynchronously.

CreateInstanceEnum

Creates an instance enumerator.

CreateInstanceEnumAsync

Creates an instance enumerator that executes asynchronously.

ExecQuery

Executes a query to retrieve classes or instances.

ExecQueryAsync

Executes a query to retrieve classes or instances asynchronously.

ExecNotificationQuery

Executes a query to receive events.

ExecNotificationQueryAsync

Executes a query to receive events asynchronously.

ExecMethod

Executes an object method.

ExecMethodAsync

Executes an object method asynchronously.

 

Remarks

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.

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 <iostream>
using namespace std;
#include <wbemidl.h>
# 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();

Requirements

Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderWbemcli.h (include Wbemidl.h)
LibraryWbemuuid.lib
DLLFastprox.dll, Esscli.dll, Framedyn.dll, Ntevt.dll, Stdprov.dll, Viewprov.dll, Wbemcomn.dll, Wbemcore.dll, Wbemess.dll, Wbemsvc.dll, Wmipicmp.dll, Wmidcprv.dll, Wmipjobj.dll, Wmiprvsd.dll

See Also

COM API for WMI
Manipulating Class and Instance Information

Send comments about this topic to Microsoft

Build date: 11/3/2009

Tags :


Page view tracker