[[migrate]] makes the first Bach install remove the old one first. This page walks through finding the key Windows keeps for the old install and adding it.
1
Find the old install's entry
Install the old version on a test computer and open
regedit. Look below HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall (or HKEY_LOCAL_MACHINE\... for a machine-wide old install). The name of the entry is what you need:2
Add it to bach.toml
bach.toml
QuietUninstallString, tell setup how to run the old uninstaller without a window: arguments = "/VERYSILENT /NORESTART" for Inno Setup, arguments = "/S" for NSIS. An MSI needs nothing: it is removed with msiexec /x {code} /qn /norestart.3
Keep the user's data
The old uninstaller decides what it removes, and most keep the user’s settings. Point
uninstall.data and the app’s own paths at the folders the old app used, so the new version finds them. See The uninstaller and your users’ data.4
Test it on a copy
On a test computer with the old version installed, run the new setup file. It should remove the old install first and then install the new one, and Settings › Apps should list the app once. The log,
%TEMP%\<app id>-setup.log, says what happened to each entry.What to expect
- Migration runs on a first install with Bach, before any file is placed. Updates of a Bach install skip it.
- It never stops the install. If the old install is not there, cannot be removed quietly or fails to go, the log says so and the new version installs anyway. Test with the old version once, so you know it goes.
- A machine-wide old install (under
HKLM) is removed only when you addelevated = true, which makes Windows ask for administrator rights, and only if its uninstaller sits in Program Files or the Windows folder. A per-user old install is never run by a setup that already has administrator rights. - If the old install and the new one use the same folder, nothing the old uninstaller deletes can be a file Bach just installed, because the old one goes first.
[[migrate]] reference for every setting and the safety limits, and machine-wide installs if the old install was for every user.