Export (0) Print
Expand All

IEnumWbemClassObject interface

The IEnumWbemClassObject interface is used to enumerate Common Information Model (CIM) objects and is similar to a standard COM enumerator.

An object of type IEnumWbemClassObject is received from calls to the following methods:

CIM objects are retrieved from an enumeration as objects of type IWbemClassObject by calling the Next method. You can reset an enumeration back to the beginning by calling the Reset method.

Members

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

Methods

The IEnumWbemClassObject interface has these methods.

MethodDescription
Clone

Makes a copy of the enumerator.

Next

Retrieves the next object or objects in the enumeration starting from the current position.

NextAsync

Retrieves the next object or objects using asynchronous integration with IWbemObjectSink.

Reset

Resets an enumeration sequence back to the beginning.

Skip

Causes the enumeration to skip ahead so that future calls to the Next method retrieve objects one, or more, ahead of the current location in the enumeration.

 

Remarks

IEnumWbemClassObject is the object returned from a WMI query, and is used to enumerate through the returned values. For more information on how to use this class, see Querying WMI and Enumerating WMI.

Examples

The following C++ code sample describes how to retrieve an IEnumWbemClassObject.


void ExecQuerySync(IWbemServices *pSvc)
{
    // Query for all users and groups.

    BSTR Language = SysAllocString(L"WQL");
    BSTR Query = SysAllocString(L"SELECT * FROM __Namespace");

    // Initialize the IEnumWbemClassObject pointer.
    IEnumWbemClassObject *pEnum = 0;

    // Issue the query.
    HRESULT hRes = pSvc->ExecQuery(
        Language,
        Query,
        WBEM_FLAG_FORWARD_ONLY,         // Flags
        0,                              // Context
        &pEnum
        );

    SysFreeString(Query);
    SysFreeString(Language);

    if (hRes != 0)
    {
        printf("Error\n");
        return;
    }
    
    ULONG uTotal = 0;

    // Retrieve the objects in the result set.
    for (;;)
    {
        IWbemClassObject *pObj = 0;
        ULONG uReturned = 0;

        hRes = pEnum->Next(
            0,                  // Time out
            1,                  // One object
            &pObj,
            &uReturned
            );

        uTotal += uReturned;

        if (uReturned == 0)
            break;

        // Use the object.
        
        // ...
        
        // Release it.
        // ===========
        
        pObj->Release();    // Release objects not owned.            
    }

    // All done.
    pEnum->Release();
}


Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2003

Header

Wbemcli.h (include Wbemidl.h)

Library

Wbemuuid.lib

DLL

Fastprox.dll

See also

COM API for WMI
Enumerating WMI

 

 

Show:
© 2014 Microsoft