vbscript – 关于WMI Win32_WindowsProductActivation类和SetProductKey方法的问题

前端之家收集整理的这篇文章主要介绍了vbscript – 关于WMI Win32_WindowsProductActivation类和SetProductKey方法的问题前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个关于 Win32_WindowsProductActivation WMI类和SetProductKey方法的问题.

当我运行使用WMi Code创建者生成的此代码(vbscript)时,执行失败并显示错误Invalid参数

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

@R_301_323@

你必须调用并直接传递SetProductKey方法的参数而不使用SpawnInstance_,因为这种方法是非静态的.

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

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

Static methods apply only to WMI
classes and not to specific instances
of a class. For example,the Create
method of the Win32_Process class is a
static method because use it to create
a new process without an instance of
this class. Nonstatic methods apply
only to instances of a class. For
example,the Terminate method of the
Win32_Process class is a nonstatic
method because it only makes sense to
terminate a process if an instance of
that process exists. You can determine
if a method is static by checking if
the Static qualifier is associated
with the method.

另外,您可以查看这篇文章Calling a Provider Method

猜你在找的Windows相关文章