The
Delete_ method of the
SWbemObject object deletes either the current class or the current instance. If a dynamic provider supplies the class or instance, it is sometimes not possible to delete this object unless the provider supports class or instance deletion. The following syntax is language-neutral. For an explanation of this syntax, see
Document Conventions for the Scripting API.
Syntax
Delete_(
[ iFlags = 0 ],
[ objwbemNamedValueSet = null ]
)
Parameters
- iFlags [in, optional]
-
Reserved and must be 0 (zero) if specified.
- objwbemNamedValueSet [in, optional]
-
This parameter is typically 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
This method has no return values.
Remarks
The
Delete_ method fails if a new instance of SWbemObject is created, but no value is supplied for the key property. Windows Management Instrumentation (WMI) generates a globally unique identifier (GUID) value automatically, but a GUID value is not accepted by SWbemObject.Delete_. In this case,
SWbemServices.Delete, which uses the object path works. Note that an
SWbemObjectPath object is returned by the
SWbemObject.Put_ method after an object is committed to WMI.
Examples
For script code examples, see WMI Tasks for Scripts and Applications and the TechNet ScriptCenter Script Repository.
The following example creates a new class; adds a key property; 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 it; and displays the path. Note that the script deletes both the class and its instances from the repository by simply deleting the class.
On Error Resume Next
wbemCimtypeString = 8 ' String datatype
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
' Remove the new class and instance from the repository
objClass.Delete_()
If Err <> 0 Then
WScript.Echo Err.Number & " " & Err.Description
Else
WScript.Echo "Delete succeeded"
End If
' Release SwbemServices object
Set objSWbemService = Nothing
Requirements
| Minimum supported client | Windows 2000 Professional |
| Minimum supported server | Windows 2000 Server |
| Type Library | Wbemdisp.tlb |
| DLL | Wbemdisp.dll |
Send comments about this topic to Microsoft
Build date: 11/3/2009