Επεξεργασία

Κοινή χρήση μέσω


SWbemObject object

You can use the methods and properties of the SWbemObject object to represent one Windows Management Instrumentation (WMI) class definition or object instance. This object cannot be created by the VBScript CreateObject call.

This object supports two types of properties and methods. Those defined in this section are generic properties and methods that apply to all WMI objects. In addition, this object exposes the properties and methods of the underlying object as dynamic automation properties and methods of SWbemObject. The names and types of these properties and methods depend on the underlying WMI object. For more information about how these dynamic properties and methods are exposed, see Manipulating Class and Instance Information.

From the WMI client perspective, this object is always in-process. Write operations only affect the local copy of the object, and read operations always retrieve values from the local copy. Updates to WMI are performed only when entire objects are written using a call to the SWbemObject.Put_ method. If you modify the properties or methods in an SWbemObject object, your changes are not written to WMI until you call SWbemObject.Put_.

The generic method and property names defined in this section always end with a trailing underscore ("_") to differentiate them from the dynamic WMI methods and properties of the underlying object.

Note that SWbemObject cannot be created using the VBScript GetObject.method. If you want to create a new, empty class use SWbemServices.Get with an empty path parameter. This call returns an empty SWbemObject object that can become a class. You can then supply a class name for the Class property of the SWbemObjectPath object returned by the Path_ call. Add properties to the new class by the Properties_ method. To create an instance, call GetObject on the new class.

The following code example shows how to obtain a new class and add a property to it. The SWbemObject object that represents the class must be written back to the WMI repository by a call to Put_.

wbemCimtypeString = 8
Set objSWbemService = GetObject("Winmgmts:root\default")
Set objClass = objSWbemService.Get()
objClass.Path_.Class = "NewClass"

' Add a property
' String property
objClass.Properties_.add "PropertyName", wbemCimtypeString  
' Make the property a key property 
objClass.Properties_("PropertyName").Qualifiers_.add "key", true

' Write the new class to the root\default namespace in the repository
Set objClassPath = objClass.Put_
WScript.Echo objClassPath.Path

'Create an instance of the new class using SWbemObject.SpawnInstance
Set objNewInst = GetObject( _
    "Winmgmts:root\default:NewClass").Spawninstance_

objNewInst.PropertyName = "My Instance"

' Write the instance into the repository
Set objInstancePath = objNewInst.Put_
WScript.Echo objInstancePath.Path

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_.

Members

The SWbemObject object has these types of members:

Methods

The SWbemObject object has these methods.

Method Description
Associators_ Retrieves the associators of the object.
AssociatorsAsync_ Asynchronously retrieves the associators of the object.
Clone_ Makes a copy of the current object.
CompareTo_ Tests two objects for equality.
Delete_ Deletes the object from WMI.
DeleteAsync_ Asynchronously deletes the object from WMI.
ExecMethod_ Executes a method exported by a method provider.
ExecMethodAsync_ Asynchronously executes a method exported by a method provider.
GetObjectText_ Retrieves the textual representation of the object (MOF syntax).
Instances_ Returns a collection of instances of the object (which must be a WMI class).
InstancesAsync_ Asynchronously returns a collection of instances of the object (which must be a WMI class).
Put_ Creates or updates the object in WMI.
PutAsync_ Asynchronously creates or updates the object in WMI.
References_ Returns references to the object.
ReferencesAsync_ Asynchronously returns references to the object.
SpawnDerivedClass_ Creates a new derived class from the current object (which must be a WMI class).
SpawnInstance_ Creates a new instance from the current object.
Subclasses_ Returns a collection of subclasses of the object (which must be a WMI class).
SubclassesAsync_ Asynchronously returns a collection of subclasses of the object (which must be a WMI class).

Properties

The SWbemObject object has these properties.

Property Access type Description
Derivation_
Read-only
Contains an array of strings that describes the derivation hierarchy for the class.
Methods_
Read-only
An SWbemMethodSet object that is the collection of methods for this object.
Path_
Read-only
Contains an SWbemObjectPath object that represents the object path of the current class or instance.
Properties_
Read-only
An SWbemPropertySet object that is the collection of properties for this object.
Qualifiers_
Read-only
An SWbemQualifierSet object that is the collection of qualifiers for this object.
Security_
Read-only
Contains an SWbemSecurity object used to read or change the security settings.

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_SWbemObject
IID
IID_ISWbemObject

See also

SWbemObjectEx

Scripting API Objects