Deleting an Instance
Deleting an instance is the most common delete command you are likely to perform in WMI. Like deleting a class, the actual command is fairly simple. However, WMI performs quite differently depending on the type of instance you are deleting. If the instance is static, WMI simply deletes the instance from the WMI repository.
If the instance is dynamic, WMI must call IWbemServices::DeleteInstanceAsync on the providers that are responsible for the following classes:
- The class that owns the instance.
- Every parent class of the class that owns the instance.
- Every subclass of the class that owns the instance.
The success of the deletion depends on the topmost nonabstract class for the original instance. If the provider for any topmost nonabstract class succeeds in completing the deletion, the operation succeeds. For more information, see the Remarks section of IWbemServices::DeleteInstance.
The COM API for WMI has different methods for deleting an instance and deleting an object.
The following procedure describes how to use C++ to delete an instance of a base class or derived class.
To delete an instance of a base class or derived class using C++
- Call either the
As the name suggests, DeleteInstanceAsync deletes an instance asynchronously while DeleteInstance deletes an instance synchronously. To use DeleteInstanceAsync, you must also implement an IWbemObjectSink object.
The Scripting API for WMI uses the same methods to delete either a class object or an instance.
The following procedure describes how to use VBScript to delete an instance of a base class or derived class.
To delete an instance of a base class or derived class using VBScript
- Call either the
As the name suggests, Delete_ deletes an instance synchronously while DeleteAsync_ deletes an instance asynchronously. For more information about deleting an instance asynchronously, see Calling a Method.
The following example describes how to delete an instance using VBScript.