我想使用WMI卸载程序,但出现此错误:“Access is denied。(Exception from HRESULT:0x80070005(E_ACCESSDENIED))”。安装它没有任何问题,使用相同的ConnectionOptions。 管理员用户是否有任何可能需要安装软件,但不能卸载?如果是这样,我该如何编辑它们?使用WMI卸载程序
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());
}
}
谢谢!
当您尝试卸载时,应用程序正在使用还是锁定文件? – slugster
手动卸载(从添加删除程序)工作没有任何问题 –
带有示例代码的任何解决方案? – Kiquenet