Düzenle

Aracılığıyla paylaş


SWbemServices.Delete method

The Delete method of the SWbemServices object deletes the class or instance that is specified in the object path. You can only delete objects in the current namespace.

If a dynamic provider supplies the class or instance, you cannot delete this object unless the provider supports class or instance deletion.

This 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

SWbemServices.Delete( _
  ByVal strObjectPath, _
  [ ByVal iFlags ], _
  [ ByVal objWbemNamedValueSet ] _
)

Parameters

strObjectPath

Required. String that contains the object path to the object that you want to delete. For more information, see Describing the Location of a WMI Object.

iFlags [optional]

Reserved. This value must be zero.

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 services 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

This method does not return a value.

Error codes

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

wbemErrAccessDenied - 2147749891 (0x80041003)

Current context does not have adequate security rights to delete the object.

wbemErrFailed - 2147749889 (0x80041001)

Unspecified error.

wbemErrInvalidClass - 2147749904 (0x80041010)

Specified class does not exist.

wbemErrInvalidOperation - 2147749910 (0x80041016)

Object cannot be deleted.

wbemErrNotFound - 2147749890 (0x80041002)

Object does not exist.

wbemErrOutOfMemory - 2147749894 (0x80041006)

Not enough memory to complete the operation.

Remarks

The SWbemServices.Delete method can be used when the key property for the object is not given a value, because this method only requires an object path as input. This method can be used in situations where SWbemObject.Delete_ fails for lack of a key value. If the object is committed to WMI through SWbemObject.Put_, then an SWbemObjectPath object was obtained through the call.

Examples

The following example creates a new class, adds a property that is not a key, writes the new class to the repository, and displays the path of the new class object. The script then spawns an instance of the new class, writes the instance, and displays the path. Note that the script deletes both the class and its instances from the repository by deleting the class. For more information about WMI classes and instances, see Manipulating Class and Instance Information and Common Information Model.

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

' Add a property
' Integer property
objClass.Properties_.Add "iProperty", wbemCimtypeSint32  
objClass.Properties_("iProperty").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.iProperty = 1000

' Write the instance into the repository
Set objInstancePath = objNewInst.Put_
wscript.echo objInstancePath.Path

' Remove the new class and instance from the repository
objSWbemService.Delete("NewClass")
If Err <> 0 Then
    WScript.Echo Err.Number & "    " & Err.Description 
Else
    WScript.Echo "Delete succeeded"
End If

' Release SwbemServices object
Set objSWbemService = Nothing

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

SWbemObjectPath