2008-11-29 250 views
0

全部, 我试图远程卸载软件,它在测试机器上正常工作,但我在生产服务器中遇到问题。 试验机我已经使用的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的,对象[]参数)

回答

2

Win2003的没有此类默认安装的 - 你必须从产品光盘手动安装。

+0

非常感谢Don,我做了很多诊断并最终找到了相同的东西,谢谢你的回答。 – 2008-12-01 18:16:19