问题
I'm trying to automate an install process in which I uninstall a previous version and install a newer version over the top. How should I test (in my bootstrapper, coded in C#) if the uninstall was a success?
This is currently how I'm launching the uninstall.
Process p = Process.Start("msiexec", /*various switches*/);
p.WaitForExit();
I'm also currently tangling with dynamic multiple instances, which really bend my mind, so handling this problem within WiX itself is difficult if not impossible.
回答1:
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.
回答2:
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:
- Major Upgrade — UpgradeCode property is the same; ProductCode is different
- Minor Upgrade — UpgradeCode and ProductCode properties are the same; ProductVersion is higher
- Related product removal — Removal by any UpgradeCodes you specify
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.
来源:https://stackoverflow.com/questions/17149811/checking-for-successful-uninstall