使用 C# 执行卸载

Gui*_*ser 3 c# uninstallation

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

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

Kur*_*ran 5

您可以使用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();
Run Code Online (Sandbox Code Playgroud)