Export (0) Print
Expand All

Updating an Entire Instance

The most common means of updating a WMI class instance is to update the entire instance at once. By updating an entire instance, WMI does not have to parse the instance into individual properties and send them to your application. Instead, WMI can simply send you the entire instance. When you finish, WMI can then copy your entire changed instance over the original instance.

The following procedure describes how to modify or update an instance using VBScript.

Aa393946.wedge(en-us,VS.85).gifTo modify or update an instance using VBScript

  1. Retrieve a local copy of the object with a call to GetObject.
  2. If necessary, view the properties of the object with a call to the Properties_ method.

    Although not required, you may wish to know the value of the property before you change it.

  3. Make any changes to the object properties with a call to the SWbemProperty.Value method.

    The Value method changes only the local copy. To save your changes to WMI, you must place the entire copy back into the WMI repository.

  4. Place the object back into the WMI repository with a call the SWbemObject.Put_ or SWbemObject.PutAsync_ methods.

As the names imply, Put_ updates synchronously while PutAsync_ updates asynchronously. Either method copies over the original instance with your modified instance. However, to take advantage of asynchronous processing, you must create an SWbemSink object. For more information, see Calling a method.

The following procedure describes how to modify or update an instance using C++.

Aa393946.wedge(en-us,VS.85).gifTo modify or update an instance using C++

  1. Retrieve a local copy of the instance with a call to IWbemServices::GetObject or IWbemServices::GetObjectAsync.
  2. If necessary, view the properties of the object with a call to IWbemClassObject::Get.

    Although not required, you may wish to know the value of the property before you change it.

  3. Make any necessary changes to the copy with a call to IWbemClassObject::Put.

    The Put method changes only the local copy. To save your changes to WMI, you must place the entire copy back into the WMI repository.

  4. Place your copy back into the WMI repository with a call the IWbemServices::PutInstance or IWbemServices::PutInstanceAsync methods.

    As the names imply, PutInstance updates synchronously while PutInstanceAsync updates asynchronously. Either method copies over the original instance with your modified instance. However, to take advantage of asynchronous processing, you must implement the IWbemObjectSink interface.

    You should be aware that an update operation on an instance belonging to a class hierarchy might not succeed due to an error involving another class in the hierarchy. WMI calls the PutInstanceAsync method of each of the providers responsible for the classes from which the class owning the original instance derives. If any of these providers fail, the original update request fails. For more information, see the Remarks section of PutInstanceAsync.

For more information, see Calling a Provider Method.

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