Bewerken

Delen via


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*
    // BSTR is not compatible with wchar_t, need to allocate.
    BSTR path = SysAllocString(L"path");
    pWbemSvc->GetObject(path, 0, 0, &pObj, 0);
    SysFreeString(path);

Inheritance

The IWbemServices interface inherits from the IUnknown interface. IWbemServices also has these types of members:

Methods

The IWbemServices interface has these methods.

 
IWbemServices::CancelAsyncCall

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

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

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

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

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

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

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

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

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.
IWbemServices::ExecMethod

Executes a method exported by a CIM object.
IWbemServices::ExecMethodAsync

Asynchronously executes a method exported by a CIM object.
IWbemServices::ExecNotificationQuery

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.
IWbemServices::ExecNotificationQueryAsync

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.
IWbemServices::ExecQuery

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

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

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

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

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

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.
IWbemServices::PutClassAsync

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

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

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.
IWbemServices::QueryObjectSink

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

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

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 (
            CLSID_WbemAdministrativeLocator,
            NULL ,
            CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER , 
            IID_IUnknown ,
            ( void ** ) &pIWbemLocator
            ) ;

IWbemServices *pWbemServices = NULL;

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

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

    // Use pWbemServices

}

// Clean up
pWbemServices->Release();

Requirements

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

See also

COM API for WMI

Creating WMI Providers

Manipulating Class and Instance Information

Supplying Data to WMI by Writing a Provider