【发布时间】:2012-01-21 11:36:14
【问题描述】:
我正在使用一些 PowerShell functions 来配置 Windows 产品密钥和激活。我得到一个SoftwareLicensingService 的实例并调用InstallProductKey,就像这样。带有超级格式的trap 块有助于调试。
trap [Exception]
{
"=================================================="
"Trapped: $($Error[0])"
"=================================================="
"Exception: $($_.Exception)"
"--------------------------------------------------"
""
break
}
$service = Get-WmiObject -Query "SELECT * FROM SoftwareLicensingService"
$service.InstallProductKey("12345-12345-12345-12345-12345")
$service.RefreshLicenseStatus() | Out-Null
错误条件是无效的产品密钥。我知道这一点是因为我从 System 面板手动将其输入到 Activate Windows 对话框中。但是,脚本只显示WMIMethodException 或COMException。
==================================================
Trapped: Exception calling "InstallProductKey" : ""
==================================================
Exception: System.Runtime.InteropServices.COMException (0xC004F025)
at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
at System.Management.ManagementObject.InvokeMethod(String methodName, ManagementBaseObject inParameters, InvokeMethodOptions options)
at System.Management.Automation.ManagementObjectAdapter.InvokeManagementMethod(ManagementObject obj, String methodName, ManagementBaseObject inParams)
--------------------------------------------------
Exception calling "InstallProductKey" : ""
At line:14 char:31
+ $service.InstallProductKey <<<< ("12345-12345-12345-12345-12345")
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : WMIMethodException
我没有从该方法获得返回码(尽管文档说明我这样做了,但无论如何都找不到错误代码列表)。 您知道如何获取激活(或产品密钥安装)错误原因吗?
【问题讨论】:
标签: windows-7 com powershell wmi