Upravit

Sdílet prostřednictvím


SWbemServices.InstancesOf method

The InstancesOf method of the SWbemServices object 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 SWbemServices.ExecQuery.

The method is called in the semisynchronous mode. For more information, see Calling a Method.

For an explanation of this syntax, see Document Conventions for the Scripting API.

Syntax

objWbemObjectSet = .InstancesOf( _
  ByVal strClass, _
  [ ByVal iFlags ], _
  [ ByVal objWbemNamedValueSet ] _
)

Parameters

strClass

Required. String that contains the name of the class for which instances are desired. This parameter cannot be blank.

iFlags [optional]

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.

wbemFlagForwardOnly (32 (0x20))

Causes a forward-only enumerator to be returned. Forward-only enumerators are generally much faster and use less memory than conventional enumerators, but they do not allow calls to SWbemObject.Clone_.

wbemFlagBidirectional (0 (0x0))

Causes WMI to retain pointers to objects of the enumeration until the client releases the enumerator.

wbemFlagReturnImmediately (16 (0x10))

Default value for this parameter. This flag causes the call to return immediately.

wbemFlagReturnWhenComplete (0 (0x0))

Causes this call to block until the query has completed. This flag calls the method in the synchronous mode.

wbemQueryFlagShallow (1 (0x1))

Forces the enumeration to include only immediate subclasses of the specified parent class.

wbemQueryFlagDeep (0 (0x0))

Default value for this parameter. This value forces the enumeration to include all classes in the hierarchy.

wbemFlagUseAmendedQualifiers (131072 (0x20000))

Causes WMI to return class amendment data with the base class definition. For more information, see Localizing WMI Class Information.

objWbemNamedValueSet [optional]

Typically, this is undefined. Otherwise, this is an SWbemNamedValueSet object whose elements represent the context information that can be used by the provider that is servicing the request. A provider that supports or requires such information must document the recognized value names, data type of the value, allowed values, and semantics.

Return value

If successful, the method returns an SWbemObjectSet.

Error codes

Upon the completion of the InstancesOf method, the Err object may contain one of the error codes in the following list.

Note

A returned enumerator with zero elements is not an error.

wbemErrAccessDenied - 2147749891 (0x80041003)

Current user does not have the permission to view instances of the specified class.

wbemErrFailed - 2147749889 (0x80041001)

Unspecified error occurred.

wbemErrInvalidClass - 2147749904 (0x80041010)

Specified class is not valid.

wbemErrInvalidParameter - 2147749896 (0x80041008)

A specified parameter is not valid.

wbemErrOutOfMemory - 2147749894 (0x80041006)

Not enough memory to complete the operation.

Remarks

The InstancesOf method only works for class objects.

By default, InstancesOf performs a deep retrieval. That is, InstancesOf retrieves all instances of the managed resource you identify and all instances of all the subclasses defined beneath the target class. For example, the following script retrieves all of the resources modeled by all of the dynamic classes defined beneath the CIM_Service abstract class.

strComputer = "."
Set objSWbemServices = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colSWbemObjectSet = objSWbemServices.InstancesOf("CIM_Service")
For Each objSWbemObject In colSWbemObjectSet
    Wscript.Echo "Object Path: " & objSWbemObject.Path_.Path
Next

If you run this script, you will get information back. However, this information will not be limited to the services installed on a computer. Instead, it will include information from all child classes of CIM_Service, including Win32_SystemDriver and Win32_ApplicationService.

Requirements

Requirement Value
Minimum supported client
Windows Vista
Minimum supported server
Windows Server 2008
Header
Wbemdisp.h
Type library
Wbemdisp.tlb
DLL
Wbemdisp.dll
CLSID
CLSID_SWbemServices
IID
IID_ISWbemServices

See also

SWbemServices

SWbemObjectSet