Help Center

InstancesOffunction

Creates an enumerator that returns the instances of a specified class according to the user-specified selection criteria.

COMfunctionCWmiDisp.incdoc-orphan
No implementation located. This member is documented, but the source scan found no matching declaration. It is likely declared in a header this scan does not resolve, or provided by a macro.

Syntax

FUNCTION InstancesOf (BYREF wszClass AS WSTRING, BYVAL iFlags AS LONG = wbemFlagReturnImmediately) AS HRESULT

Parameters

NameDescription
wszClassRequired. A string that contains the name of the class for which instances are desired. This parameter cannot be blank.
iFlagsOptional. This parameter determines how detailed the call enumerates and if this call returns immediately. The default value for this parameter is wbemFlagReturnImmediately. This parameter can accept the following values.

Return value

S_OK on success or an error code.

Description

Creates an enumerator that returns the instances of a specified class according to the user-specified selection criteria. This method implements a simple query. More complex queries may require the use of the ExecQuery method. By default, the method is called in the semisynchronous mode.

Example

#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"

' // Retrieve the instances of DIM hr AS HRESULT = pServices.InstancesOf("Win32_Printer")

' // Enumerate the objects using the standard IEnumVARIANT enumerator (NextObject method) ' // and retrieve the properties using the CDispInvoke class. DIM pDispServ AS CDispInvoke DO pDispServ = pServices.NextObject IF pDispServ.DispPtr = NULL THEN EXIT DO PRINT "Caption: "; pDispServ.Get("Caption") PRINT "Capabilities "; pDispServ.Get("Capabilities") LOOP

Reference