occamsTacKnife
occamsTacKnife

Reputation: 31

msiexec /qn Switch Prevents Uninstall

I'm trying to uninstall an application via C# using the following call:

msiexec.exe /x {my-product-code} /qn

Without the /qn switch, a dialog would appear asking if you want to uninstall. The /qn switch suppresses this dialog, but it appears to also cause an implicit "No" for the dialog result, because the application does not uninstall. If I leave off the /qn switch, I get the dialog as expected and if I choose "Yes", the application uninstalls.

How can I use the /qn switch without it causing an implicit "No" to the confirmation?

Upvotes: 1

Views: 1468

Answers (1)

occamsTacKnife
occamsTacKnife

Reputation: 31

As PhilDW noted in the comment above, the issue was one of needing to elevate privileges. Even though I'm an administrator, using the /qn switch suppresses the confirmation dialog (as expected), and the confirmation dialog is used as the administrative confirmation that it's OK to uninstall. The solution was as follows:

Process process = new Process();
process.StartInfo.FileName = "msiexec.exe";
process.StartInfo.Arguments = string.Format("/x {0} /qn /l*v uninstall.log", productCode);
process.StartInfo.UseShellExecute = true; // added to elevate privileges
process.StartInfo.Verb = "runas"; // added to elevate privileges
process.Start();
process.WaitForExit();

Upvotes: 1

Related Questions