2013-10-24 52 views
2

我一直在环顾网络,但我找不到它。使用C执行卸载#

有没有办法通过C#触发卸载程序(从程序和功能屏幕)?或者出于安全的目的,这被Windows阻止?

回答

4

您可以使用msiexec.exe。您可以简单地使用product code来卸载应用程序。使用命令你可以设置是否卸载过程中显示的UI或使其静默卸载,请

string UninstallCommandString = "/x {0} /qn";

  • /QN:设置用户界面级别:无
  • /QB:设置用户界面级别:基本UI
  • /qr:设置用户界面级别:缩小UI
  • /QF:设置用户界面级别:完全UI(默认)

C# code

string UninstallCommandString = "/x {0} /qn"; 

Process process = new Process(); 
ProcessStartInfo startInfo = new ProcessStartInfo(); 
process.StartInfo = startInfo; 

startInfo.UseShellExecute = false; 
startInfo.RedirectStandardError = true; 

startInfo.FileName = "msiexec.exe"; 
startInfo.Arguments = string.Format(UninstallCommandString, "Product Code"); 

process.Start(); 
+0

这看起来不错!我要试一下。谢谢! –

+1

@GuidoVisser确保提供安装的正确产品代码。 – Kurubaran

0

你可以调用使用System.Diagnostics程序卸载程序的可执行文件。

类似下面应该做的伎俩:

System.Diagnostics.Process.Start("/path/to/uninstall.exe", "arguments for uninstaller if needed, else don't bother with this arg"); 

它的快速和肮脏的和/宜/工作。希望有所帮助。

编辑 - 刚刚意识到你想从添加删除软件屏幕做到这一点。无论如何,我会离开这里,但我的错误。