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
静悄悄是
@R_301_323@
规则是,如果执行的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