【发布时间】: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