Export (0) Print
Expand All

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.

Aa389970.wedge(en-us,VS.85).gifTo delete an instance of a base class or derived class using C++

Note  Because the callback to the sink might not be returned at the same authentication level as the client requires, it is recommended that you use semisynchronous instead of asynchronous communication. For more information, see Calling a Method.

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.

Aa389970.wedge(en-us,VS.85).gifTo delete an instance of a base class or derived class using VBScript

  • Call either the SWbemObject.Delete_ or SWbemObject.DeleteAsync_ methods.

    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.

    Dim service
    
    Set service = GetObject("winmgmts:{impersonationLevel=impersonate}") 
    
    Set objwbemobject= service.get("")
    
    objwbemobject.Path_.Class = "MyNewClass" 
    objwbemobject.put_
    service.delete  "MyNewClass"
    

Note  Because the callback to the sink might not be returned at the same authentication level as the client requires, it is recommended that you use semisynchronous instead of asynchronous communication. For more information, see Calling a Method.

 

 

Show:
© 2014 Microsoft