I tried this,this以编程方式卸载应用程序。我没有收到任何错误或异常,但该应用程序未从我的计算机上卸载。另请参阅尝试过的代码
public static string GetUninstallCommandFor(string productDisplayName)
{
RegistryKey localMachine = Registry.LocalMachine;
string productsRoot = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products";
RegistryKey products = localMachine.OpenSubKey(productsRoot);
string[] productFolders = products.GetSubKeyNames();
foreach (string p in productFolders)
{
RegistryKey installProperties = products.OpenSubKey(p + @"\InstallProperties");
if (installProperties != null)
{
string displayName = (string)installProperties.GetValue("DisplayName");
if ((displayName != null) && (displayName.Contains(productDisplayName)))
{
string uninstallCommand =(string)installProperties.GetValue("UninstallString");
return uninstallCommand;
}
}
}
return "";
}
请帮助我使用 C# 以编程方式卸载应用程序。
上面的例程将返回一个字符串,假设它找到了一个可能如下所示的匹配:
MsiExec.exe /X{02DA0248-DB55-44A7-8DC6-DBA573AEEA94}
您需要将其作为一个进程运行:
System.Diagnostics.Process.Start(uninstallString);
Note它可能并不总是 msiexec,它可以是程序选择指定的任何内容。如果是 msiexec,您可以附加/q
参数给你的uninstallString
使其以静默方式卸载(并且不会显示那些修复/删除对话框)。
Update:如果您使用的是 Windows installer 3.0 或更高版本,您还可以使用/quiet
用于静默安装/卸载。基本上是一样的/qn
(如果您使用的是旧版本)。Source。感谢@JRO 提出来!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)