全部, 我試圖遠程卸載軟件,它在測試機器上正常工作,但我在生產服務器中遇到問題。 試驗機我已經使用的Windows XP,Windows 2003服務器,WMI無效類錯誤(試圖卸載遠程PC上的軟件)
生產機:在Windows Server 2003
可能是什麼這個錯誤的原因,任何幫助,將更多的讚賞。 如果您有任何其他方式可以在遠程PC上卸載軟件,請分享。
public void Uninstallwithguid(string targetServer, string product,string guid, string version)
{
this.Project.Log(Level.Info, "Starting Uninstall ");
this.Project.Log(Level.Info, "targetServer :" + targetServer);
this.Project.Log(Level.Info, "product :" + product);
this.Project.Log(Level.Info, "guid :" + guid);
this.Project.Log(Level.Info, "version :" + version);
System.Management.ConnectionOptions connoptions = new System.Management.ConnectionOptions();
connoptions.Impersonation = System.Management.ImpersonationLevel.Impersonate;
connoptions.Timeout = new TimeSpan(0, 0, 10); // 10 seconds
System.Management.ManagementScope scope = new System.Management.ManagementScope(@"\\" + targetServer + @"\root\cimv2", connoptions);
scope.Connect();
System.Management.ObjectGetOptions objoptions = new System.Management.ObjectGetOptions();
string test = @"\\" + targetServer + @"\root\cimv2";
string objPath = string.Format("Win32_Product.IdentifyingNumber='{0}',Name='{1}',Version='{2}'",guid, product, version);
System.Management.ManagementPath path = new System.Management.ManagementPath(objPath);
System.Management.ManagementObject moobj = new System.Management.ManagementObject(scope, path, null);
UInt32 res1 = 0;
try
{
res1 = (UInt32)moobj.InvokeMethod("Uninstall", null);
}
catch(Exception ex)
{
this.Project.Log(Level.Error, ex.ToString());
throw ex;
}
if (res1 != 0)
{
this.Project.Log(Level.Error, "Uninstall error " + res1.ToString());
throw new Exception("Uninstall error " + res1.ToString());
}
}
錯誤描述:
System.Management.ManagementException:無效類 在System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus的errorCode) 在System.Management.ManagementObject.Initialize(布爾的getObject) 在System.Management.ManagementObject.get_ClassPath() 在System.Management.ManagementObject.GetMethodParameters(字符串方法名,ManagementBaseObject & inParameters,IWbemClassObjectFreeThreaded & inParametersClass,IWbemClassObjectFreeThreade d & outParametersClass) 在System.Management.ManagementObject.InvokeMethod(字符串methodName的,對象[]參數)
非常感謝Don,我做了很多診斷並最終找到了相同的東西,謝謝你的回答。 – 2008-12-01 18:16:19