【发布时间】:2010-11-05 02:28:10
【问题描述】:
我对@987654321@ WMI 类和SetProductKey 方法有疑问。
当我运行使用 WMi 代码创建器生成的此代码 (vbscript) 时,执行失败并出现错误 Invalid parameter
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
' Obtain an instance of the the class
' using a key property value.
Set objShare = objWMIService.Get("Win32_WindowsProductActivation")
' Obtain an InParameters object specific
' to the method.
Set objInParam = objShare.Methods_("SetProductKey"). _
inParameters.SpawnInstance_()
' Add the input parameters.
objInParam.Properties_.Item("ProductKey") = "QW4HDDQCRGHM64M6GJRK8K83T"
' Execute the method and obtain the return status.
' The OutParameters object in objOutParams
' is created by the provider.
Set objOutParams = objWMIService.ExecMethod("Win32_WindowsProductActivation", "SetProductKey", objInParam)
' List OutParams
Wscript.Echo "Out Parameters: "
Wscript.echo "ReturnValue: " & objOutParams.ReturnValue
但如果我使用此代码可以正常工作,请使用 InstancesOf 方法。
Dim VOL_PROD_KEY
VOL_PROD_KEY = "QW4HDDQCRGHM64M6GJRK8K83T"
for each Obj in GetObject("winmgmts:{impersonationLevel=impersonate}").InstancesOf ("win32_WindowsProductActivation")
result = Obj.SetProductKey (VOL_PROD_KEY)
if err <> 0 then
WScript.Echo Err.Description, "0x" & Hex(Err.Number)
Err.Clear
end if
Next
问题是
为什么第一个代码失败了?或者为什么这个 wmi 类需要使用 InstancesOf 执行这个方法?
【问题讨论】: