使用WMI卸载程序

时间:2010-03-05 22:05:19

标签: c# wmi uninstall

我想使用WMI卸载程序,但是我收到此错误:“访问被拒绝。(HRESULT异常:0x80070005(E_ACCESSDENIED))”。使用相同的ConnectionOptions安装它没有任何问题。 管理员用户是否有可能安装软件但不能卸载?如果是这样,我该如何编辑它们?

Main()
{
        ConnectionOptions oConn = new ConnectionOptions();
        oConn.Impersonation = ImpersonationLevel.Impersonate;
        oConn.EnablePrivileges = true;
        oConn.Username = "Administrator";
        oConn.Password = "password";

        System.Management.ManagementScope oMs = 
            new System.Management.ManagementScope("\\\\192.168.14.128\\root\\cimv2", oConn);

        Uninstall(oMs, "\\\\192.168.14.128\\root\\cimv2:Win32_Product.IdentifyingNumber=    \"{926C96FB-9D0A-4504-8000-C6D3A4A3118E}\",Name=\"Java DB 10.4.2.1\",Version=\"10.4.2.1\"");

}

    static void Uninstall(ManagementScope oMs, string path)
    {
        if (!oMs.IsConnected) oMs.Connect();
        ManagementObject product = new ManagementObject(path);

        if ((product != null) && (product.Path.ClassName ==
        "Win32_Product"))
        {
            object result = product.InvokeMethod("Uninstall", null); //here is where I get the error
            Console.WriteLine("The Uninstall method result is {0}",
            result.ToString());
        }
   }

谢谢!

1 个答案:

答案 0 :(得分:0)

你是在XP机上做这个吗?我只是谷歌你的错误号码,并得到了一些链接:http://www.0x80070005.net/。有很多关于这个问题的信息,这里有一个复制和粘贴:

  

错误0x80070005经常发生在   任务计划程序中的计划任务   Windows变得腐败,你需要   安装一个安全更新   收到错误消息。错误   消息通常显示“拒绝访问”。   这需要一个漏洞任务   调度程序,它将允许代码   执行。这些是安全更新   这是早先发布的   公告。这需要一个微软   知识库。所以很明显   此错误与安全问题有关   并且它在访问中发现错误。

此外,我们正在使用WiX作为我们的安装程序解决方案。不确定它是否可以使用,但我想我会把它扔出去。