检索实例后,可以修改本地副本并更新对服务器的更改。
修改或更新实例
使用对 GetObject 的调用检索对象的本地副本。
如有必要,请使用对 Properties_ 方法的调用查看对象的属性。
虽然不需要,但在更改属性之前,可能需要知道该属性的值。
通过调用 SWbemProperty.Value 方法对对象属性进行任何更改。
Value 方法仅更改本地副本。 若要将更改保存到 WMI,必须将完整副本放回 WMI 存储库中。
使用调用 SWbemObject.Put_ 或 SWbemObject.PutAsync_ 方法将对象放回 WMI 存储库中。
正如名称所暗示的那样, Put_ 同步更新,同时 PutAsync_ 异步更新。 无论哪种方法都会用修改后的实例替换原始实例。 但是,若要利用异步处理,必须创建 SWbemSink 对象。
以下示例演示如何更新实例:
Set ObjClass = Namespace.Get("MsSna_LinkService_IpDlc") ' Create new link service instance Set NewInst = ObjClass.SpawnInstance_ ' Set instance properties NewInst.NetworkName = Left(strComputerName, 8) NewInst.CPName = "IPDLCLS" NewInst.NodeID = "05D.FFFFF" NewInst.AddressType = 2 NewInst.LocalAddress = Trim(strLocalAddress) NewInst.LENNode = strLenNode NewInst.PrimaryNNS = strPrimaryNNS if (strBackupNNS <> Empty) then NewInst.BackupNNS = strBackupNNS end if ' Commit the instance NewInst.Put_