SWbemServices.Get method

The Get method of the SWbemServices object retrieves an object, that is either a class definition or an instance, based on the object path. This method retrieves only objects from the namespace that is associated with the current SWbemServices object.

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

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

Syntax


objWbemObject = .Get( _
  [ ByVal strObjectPath ], _
  [ ByVal iFlags ], _
  [ ByVal objWbemNamedValueSet ] _
)

Parameters

strObjectPath [optional]

String that contains the object path of the object to retrieve. If this value is empty, the empty object that is returned can become a new class. For more information, see Describing the Location of a WMI Object.

iFlags [optional]

Integer that determines the behavior of the query. This parameter can accept the following values.

wbemFlagUseAmendedQualifiers (131072 (0x20000))

Causes WMI to return class amendment data with the base class definition. For more information about amended qualifiers, 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, this method returns an SWbemObject object that represents the requested object.

Error codes

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

wbemErrAccessDenied - 2147749891 (0x80041003)

Current user does not have the permission to access the object.

wbemErrFailed - 2147749889 (0x80041001)

Unspecified error.

wbemErrInvalidParameter - 2147749896 (0x80041008)

A specified parameter is not valid.

wbemErrInvalidObjectPath - 2147749946 (0x8004103A)

Specified path was not valid.

wbemErrNotFound - 2147749890 (0x80041002)

Requested object could not be found.

wbemErrOutOfMemory - 2147749894 (0x80041006)

Not enough memory to complete the operation.

Remarks

Unlike the ExecQuery and InstancesOf methods, the Get method always returns an SWbemObject representing a specific instance of a WMI-managed resource. To obtain a specific instance of a WMI-managed resource using the Get method, you must tell Get the instance to retrieve by passing the method the object path, as shown in the following script.


strComputer = "."
Set objSWbemServices = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set objSWbemObject = objSWbemServices.Get("Win32_Service.Name='Messenger'")
Wscript.Echo "Name:         " & objSWbemObject.Name        & vbCrLf & _
             "Display Name: " & objSWbemObject.DisplayName & vbCrLf & _
             "Start Mode:   " & objSWbemObject.StartMode   & vbCrLf & _
             "State:        " & objSWbemObject.State


You can use this method to obtain singleton objects, such as __CIMOMIdentification, which contains version information about the WMI installation that is running.

You can examine the repository with a viewing tool such as CIM Studio to verify that the new class and instance appear. For an example of removing a class and instance from the repository, see SWbemServices.Delete or SWbemObject.Delete_.

Requirements

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
SWbemObject

 

 

Show: