WMI invalid Class error (trying to uninstall a sof

2019-06-09 13:23发布

问题:

All, I am trying to uninstall a software remotely, it is working fine in the test machines, but i got problem in production servers. test machines i have used windows xp, windows 2003 server,

production machine : windows server 2003.

what could be the cause of this error, any help would be more appreciated. if you have any other way to unistall a software on the remote PC, please share.

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());
        }
}

Error Description :

System.Management.ManagementException: Invalid class at System.Management.ManagementException.ThrowWithExtendedInfo(ManagementStatus errorCode) at System.Management.ManagementObject.Initialize(Boolean getObject) at System.Management.ManagementObject.get_ClassPath() at System.Management.ManagementObject.GetMethodParameters(String methodName, ManagementBaseObject& inParameters, IWbemClassObjectFreeThreaded& inParametersClass, IWbemClassObjectFreeThreaded& outParametersClass) at System.Management.ManagementObject.InvokeMethod(String methodName, Object[] args)

回答1:

Win2003 doesn't have this class installed by default - you have to install it manually from the product disc.



标签: c# .net wmi