Click to Rate and Give Feedback
MSDN
MSDN Library
WMI Reference
COM API for WMI
IWbemServices
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);

Syntax

interface IWbemServices : IUnknown

Methods

The IWbemServices interface inherits the methods of the IUnknown interface.

In addition, IWbemServices defines the following methods.

Method Description

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 [C++]

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

Client Requires Windows Vista, Windows XP, Windows 2000 Professional, Windows NT Workstation 4.0 SP4 and later, Windows Me, Windows 98, or Windows 95.
Server Requires Windows Server 2008, Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0 SP4 and later.
Header

Declared in Wbemcli.h; include Wbemidl.h.

Library

Use Wbemuuid.lib.

DLL

Requires Fastprox.dll.

Requires Esscli.dll.

Requires Framedyn.dll.

Requires Ntevt.dll.

Requires Stdprov.dll.

Requires Viewprov.dll.

Requires Wbemcomn.dll.

Requires Wbemcore.dll.

Requires Wbemess.dll.

Requires Wbemsvc.dll.

Requires Wmipicmp.dll.

Requires Wmidcprv.dll.

Requires Wmipjobj.dll.

Requires Wmiprvsd.dll.

See Also

COM API for WMI
Manipulating Class and Instance Information


Send comments about this topic to Microsoft

Build date: 8/20/2008

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker