使用C#执行卸载

时间:2013-10-24 07:44:56

标签: c# uninstall

我一直在寻找互联网,但我找不到它。

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

3 个答案:

答案 0 :(得分:4)

您可以使用msiexec.exe。您只需使用product code卸载应用程序即可。使用命令可以设置是在卸载过程中显示UI还是将其设置为静默卸载,

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

  • / qn :设置用户界面级别:无
  • / qb :设置用户界面级别:基本用户界面
  • / qr :设置用户界面级别:缩减UI
  • / qf :设置用户界面级别:完整用户界面(默认)

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();

答案 1 :(得分:1)

答案 2 :(得分:0)

您可以使用system.diagnostics调用卸载程序的可执行文件。

以下内容应该可以解决问题:

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

它快速而且肮脏和/应该/工作。希望有所帮助。

编辑 - 刚刚意识到你想从添加删除软件屏幕中执行此操作。无论如何,我会留在这里,但我的错误。