NextObjectfunction
Retrieves the next item in the enumeration sequence.
Syntax
FUNCTION NextObject () AS DVARIANT
Return value
Te retrieved object.
Description
Retrieves the next item in the enumeration sequence.
Note: The first time that you call this method, it retrieves the first item.
Examples
#include "AfxNova/CWmiDisp.inc" USING AfxNova
' // Connect to WMI using a moniker ' // Note: $ is used to avoid the pedantic warning of the compiler about escape characters DIM pServices AS CWmiServices = $"winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2"
' // Execute a query DIM hr AS HRESULT = pServices.ExecQuery("SELECT Caption, SerialNumber FROM Win32_BIOS")
' // Get the number of objects retrieved DIM nCount AS LONG = pServices.ObjectsCount print "Count: ", nCount
' // Enumerate the objects using the standard IEnumVARIANT enumerator (NextObject method) ' // and retrieve the properties using the CDispInvoke class. DIM pDispServ AS CDispInvoke = pServices.NextObject PRINT "Caption: "; pDispServ.Get("Caption") PRINT "Serial number: "; pDispServ.Get("SerialNumber")
#include "AfxNova/CWmiDisp.inc" USING AfxNova
' // Connect to WMI using a moniker ' // Note: $ is used to avoid the pedantic warning of the compiler about escape characters DIM pServices AS CWmiServices = $"winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2"
' // Execute a query DIM hr AS HRESULT = pServices.ExecQuery("SELECT Caption, SerialNumber FROM Win32_BIOS", 48)
' // Enumerate the objects using the standard IEnumVARIANT enumerator (NextObject method) ' // and retrieve the properties using the CDispInvoke class. DIM pDispServ AS CDispInvoke = pServices.NextObject PRINT "Caption: "; pDispServ.Get("Caption") PRINT "Serial number: "; pDispServ.Get("SerialNumber")
To improve enumeration performance set the iFlags parameter of the ExecQuery method to WbemFlagReturnImmediately and WbemFlagForwardOnly (the combined value of these flags is 48) to allow semisynchronous return of the data with an enumerator that discards each item from WMI as it is delivered. In this case don't call the ObjectsCount method because it will return 0, since the operation has not been completed.
Reference
- Include file
CWmiDisp.inc - Documented in COM/CWmiDisp Class.md
- Topic: Windows Management Instrumentation (WMI)