Erreur de classe WMI invalide (tentative de désinstallation d'un logiciel sur un ordinateur distant)

StackOverflow https://stackoverflow.com/questions/327650

  •  11-07-2019
  •  | 
  •  

Question

Tous,       J'essaie de désinstaller un logiciel à distance, cela fonctionne très bien sur les machines de test, mais j'ai un problème avec les serveurs de production. machines de test, j'ai utilisé Windows XP, serveur Windows 2003,

machine de production: Windows Server 2003.

quelle pourrait être la cause de cette erreur, toute aide serait plus appréciée. si vous avez un autre moyen de désinstaller un logiciel sur le PC distant, partagez-le.

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

Description de l'erreur:

System.Management.ManagementException: classe non valide    à System.Management.ManagementException.ThrowWithExtendedInfo (ManagementStatus errorCode)    sur System.Management.ManagementObject.Initialize (Boolean getObject)    à System.Management.ManagementObject.get_ClassPath ()    at System.Management.ManagementObject.GetMethodParameters (String methodName, ManagementBaseObject & inParameters, IWbemClassObjectFreeThreaded & ampParametersClass, IWbemClassObjectFreeThreaded & amp; outParameters).    sur System.Management.ManagementObject.InvokeMethod (String methodName, Object [] args)

Était-ce utile?

La solution

Win2003 n’a pas cette classe installée par défaut. Vous devez l’installer manuellement à partir du disque du produit.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top