msiexec / qn Switch防止卸载

时间:2015-05-14 16:01:40

标签: c# windows-installer msiexec silent-installer

我正在尝试使用以下调用通过C#卸载应用程序:

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

如果没有/qn开关,则会出现一个对话框,询问您是否要卸载。 /qn开关禁止显示此对话框,但它似乎也会导致对话框结果隐式“ No ”,因为应用程序不会卸载。如果我不使用/qn开关,我会按预期获得对话框,如果我选择“”,则应用程序将卸载。

如何使用/qn开关而不会导致确认隐含“”?

1 个答案:

答案 0 :(得分:1)

正如PhilDW在上述评论中指出的那样,问题是需要提升特权。即使我是管理员,使用/ qn开关也会禁止确认对话框(如预期的那样),并且确认对话框将用作管理确认,即可以卸载。解决方案如下:

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