如何编程卸载应用程序 [英] How to uninstall application programatically
问题描述
我想这个,的这个以编程方式卸载应用程序。我没有得到任何错误或异常,但应用程序不会从我的machine.Please卸载看到试图code也
I tried this,this to uninstall the application programatically. I am not getting any error or exception but the application is not uninstalled from my machine.Please see tried code also
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#卸载应用程序。
Please help me to uninstall the application programatically using c#.
推荐答案
以上程序将返回一个字符串,假设它找到了匹配,可能是这样的:
The above routine will return a string, assuming it found a match that may look like:
在msiexec.exe / x {02DA0248-DB55-44A7-8DC6-DBA573AEEA94}
您需要采取并运行它作为一个过程:
You need to take that and run it as a process:
System.Diagnostics.Process.Start(uninstallString);
注意,它可能不总是MSIEXEC,也可以是程序选择指定任何东西。如果MSIEXEC的,可以追加 / Q
参数给你的 uninstallString
来使卸载提示(它赢得了 T显示这些修复/删除对话框)。
Note that it may not be always msiexec, it can be anything that the program chooses to specify. In case of msiexec, you can append /q
parameter to your uninstallString
to make it uninstall silently (and it won't show those Repair/Remove dialogs).
这篇关于如何编程卸载应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!