Checking for successful uninstall

牧云@^-^@ 提交于 2019-11-29 12:50:18

Rather than invoke Windows Installer through msiexec, you can use the Windows Installer API. You can do that through P/Invoke, activating the COM interface or via WiX's DTF wrapper library. The specific function to use to remove a product is MsiConfigureProductEx.

With DTF, you can do it like this:

Installer.SetInternalUI(InstallUIOptions.Silent);
Installer.SetExternalUI(UiHandler, InstallLogModes.Verbose);
Installer.EnableLog(InstallLogModes.None, null);
Installer.ConfigureProduct(productCode, 0, InstallState.Removed, "");
Console.WriteLine("RebootRequired: {0}   RebootInitiated: {1}", Installer.RebootRequired, Installer.RebootInitiated);

The UiHandler delegate allows the app to monitor progress. If there is an error, DTF throws an exception.

As an alternative to handling this in your bootstrapper, and assuming that the installer for the newer version is a Windows Installer package (.msi) under development, you can use Windows Installer functionality to uninstall the older version, where required. When you do that an upgrade can be one of the following:

A major upgrade is basically the removal of the older version and installation of the newer version. WiX allows you to author any of these in a setup project quite easily.

So, your bootstrapper would just need to install the newer version and let Windows Installer do the rest.


BTW—You might want to look at using a WiX Bootstrapper instead of writing your own logic. If you wish, you can write a custom UI in .NET for a WiX Bootstrapper, if that's the reason you're writing your own bootstrapper.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!