【问题标题】:Using WMI to uninstall programs使用 WMI 卸载程序
【发布时间】:2011-01-24 07:39:35
【问题描述】:

我想使用 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());
        }
   }

谢谢!

【问题讨论】:

  • 在您尝试卸载时应用程序是否正在使用或文件是否被锁定?
  • 没有。手动卸载(从添加删除程序)没有任何问题
  • 任何带有示例代码的解决方案??

标签: c# wmi uninstallation


【解决方案1】:

您是在 XP 机器上执行此操作吗?我只是用谷歌搜索了你的错误号,并得到了几个链接:http://www.0x80070005.net/。关于这个问题的信息很多,这里复制粘贴一下:

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

此外,我们将WiX 用于我们的安装程序解决方案。不确定它是否可以使用,但我想我会把它扔在那里。

【讨论】:

  • 这个问题出现在 XP 上,是的。我不是想为我的软件构建一个工具包并安装它。我想使用 WMI 远程安装/卸载软件。我在尝试远程卸载时遇到此问题,而不是在安装时。所以这可能不是 Windows XP 的问题。
猜你喜欢
  • 1970-01-01
  • 2017-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-11-27
  • 2019-02-14
  • 2012-05-29
  • 1970-01-01
相关资源
最近更新 更多