I am working on a project that uses WIX to install an application. One of the requirements is to remove the old version before installing the current one. The old version is not MSI-based, it is created with SetupApi (which relies on inf files).
I figured this can be achieved with a custom action, the logic is as follows:
- look for the "ancient" version in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\%NAME% and extract the UninstallString value if possible
- If the value is set, run a custom action that will execute that command, usually it is a string like RunDll32 advpack.dll,LaunchINFSection C:\PROGRA~1\PROGRAM\file.inf, DefaultUninstall
- This action must be executed before installing the program, because they have shared files and registry keys. If the custom action is executed at the end of the MSI installation, it will break the program
My questions are:
- Is this the recommended way of removing old, INF-based programs?
Is there a way to uninstall INF-based programs silently? Otherwise the user experience will be pretty bad - a person is installing a program, and suddenly they see an "uninstalling program" window. This is counter intuitive.[resolved by adding ",3" to the uninstall command]
In case you're interested, here are the code snippets that do what I described above:
<Property Id="ANCIENTVERSION">
<RegistrySearch Id="RegistrySearchAncientVersion" Type="raw"
Root="HKLM" Key="SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Program"
Name="UninstallString" />
</Property>
<CustomAction Id="removeAncientVersion"
Directory="SystemFolder"
<!--ExeCommand="[ANCIENTVERSION]" regular uninstall-->
ExeCommand="[ANCIENTVERSION],3" <!--silent uninstall-->
Execute="immediate"
Return="check"/>
<InstallExecuteSequence>
<Custom Action='removeAncientVersion' After='InstallValidate'>ANCIENTVERSION</Custom>
</InstallExecuteSequence>
After some research I found that in order to run a silent uninstall, one needs to add ",3" to the end of the UninstallString command line. I tested it and it works:
Regular uninstall
Silent uninstall
As for the first question - since the uninstallation mechanism is the equivalent of clicking "Uninstall" in Add/Remove programs, I believe it can't get any cleaner/better than that.