0

所有,我正在尝试远程卸载软件,它在测试机器上运行良好,但我在生产服务器中遇到问题。测试机器我用过windows xp,windows 2003 server,

生产机器: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.ManagementObject.Initialize(Boolean getObject) 的 System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) 的类无效 System.Management.ManagementObject.GetMethodParameters 的 System.Management.ManagementObject.get_ClassPath() (String methodName, ManagementBaseObject& inParameters, IWbemClassObjectFreeThreaded& inParametersClass, IWbemClassObjectFreeThreaded& outParametersClass) 在 System.Management.ManagementObject.InvokeMethod(String methodName, Object[] args)

4

1 回答 1

2

Win2003 默认没有安装这个类——你必须从产品光盘手动安装它。

于 2008-11-30T15:58:59.620 回答