Vbscript 有关WMI Win32_WindowsProductActivation类和SetProductKey方法的问题

Vbscript 有关WMI Win32_WindowsProductActivation类和SetProductKey方法的问题,vbscript,wmi,Vbscript,Wmi,我有一个关于WMI类和SetProductKey方法的问题 当我运行使用WMi代码创建者生成的此代码(vbscript)时,执行失败,出现错误无效参数 strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2") ' Obtain an instance of the the class ' using a key property value. Se

我有一个关于WMI类和
SetProductKey
方法的问题

当我运行使用WMi代码创建者生成的此代码(vbscript)时,执行失败,出现错误
无效参数

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
执行此方法?

您必须调用并直接传递
SetProductKey
方法的参数,而无需使用
SpawnInstance\uuuu
,因为此方法是非静态的

规则是,如果要执行的wmi方法是静态的,则可以使用
spawnConstance\uu
否则直接调用传递参数的方法

这里有静态和非静态方法的描述

静态方法仅适用于WMI 类,而不是特定实例 一流的。例如,创建 Win32_进程类的方法是 静态方法,因为使用它来创建 没有实例的新进程 这个班。非静态方法适用 仅适用于类的实例。对于 例如 Win32_进程类是一个非静态类 方法,因为它只对 如果出现以下情况,请终止进程: 这一进程是存在的。你可以决定 如果方法是静态的,请检查 静态限定符是关联的 用这种方法

此外,你可以查看这篇文章