Question

I've been looking around the internet for this, but I couldn't find it.

Is there a way to trigger an uninstaller (from the Programs and Features screen) via C#? Or is this blocked by Windows for security purposes?

Was it helpful?

Solution

You can use msiexec.exe. You can simply uninstall an application with its product code. Using command you can set whether to show UI during the uninstallation or make it a silent uninstallation,

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

  • /qn: Set user interface level: None
  • /qb: Set user interface level: Basic UI
  • /qr: Set user interface level: Reduced UI
  • /qf: Set user interface level: Full UI (default)

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

OTHER TIPS

You could invoke the executable file for the uninstaller using system.diagnostics.

Something like the following should do the trick:

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

It's quick and dirty and /should/ work. Hope that helps.

edit- Just realised you want to do this from the add remove software screen. I'll leave this here anyway but my mistake.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top