Uninstall a Previous Version
The Uninstall a previous version custom action runs the uninstaller of a previously installed version of your product, waits for it to finish, and stores the outcome in a variable so your script can react.
Add it in an install event. Before File Extraction is the recommended placement: by that point the user has gone through the wizard and committed to installing, the destination folder and install scope are resolved, and the previous version is removed only when the new files are about to be written, and never if the user cancels at an earlier screen. You can also use Initialization, but it runs before the welcome and confirmation screens, so the previous version would be removed even if the user then backs out, and any elevation (UAC) prompt would appear before the first screen.
Properties
Section titled “Properties”| Property | Data Type | Description |
|---|---|---|
| RegistryKey | String | The Uninstall registry subkey of the previous version (the Uninstall registry key you set in Uninstaller Settings). The action reads its UninstallString. Leave empty if you do not register an Add/Remove Programs entry. |
| RegistryRoot | Enum | Where to read the key: Auto (HKLM then HKCU), HKLM (all-users), or HKCU (per-user). |
| FallbackPath | String | Full path to the previous uninstaller EXE (variables allowed, e.g. %PROGRAMFILES%\MyApp\uninstall.exe). Used when no registry key is set or found. Often the only option, since the Add/Remove Programs entry is optional in Paquet Builder. |
| UIMode | Enum | Silent panel (run silently, show a “please wait” panel), Native window (let the uninstaller show its own window/progress bar), or Silent (no extra UI). |
| WaitMessage | String | Text shown in the wait panel (Silent panel mode). |
| ResultVariable | VarName | Variable receiving the outcome (default %PBPREVUNINSTRESULT%). |
Result values
Section titled “Result values”| Value | Meaning |
|---|---|
0 | Success |
1 | No previous version found |
2 | Could not launch the uninstaller (e.g. UAC declined) |
3 | The uninstaller reported an error (or was cancelled) |
4 | Cancelled by the user (reserved; see note) |
3010 | Success, a reboot is required (previous version built with 2026.2+) |
Elevation
Section titled “Elevation”If the previous version was installed all-users (per-machine), removing it requires administrator rights. When your installer is not already elevated, the action requests elevation (UAC) before launching the uninstaller; if it is already elevated, no extra prompt appears. A previous per-user version is removed in the current token, without any prompt.
To decide whether elevation is needed, the action determines the previous version’s install scope as follows:
- Versions built with 2026.2+ record their scope in the uninstall log, which is read directly, which is the most reliable signal.
- Older versions do not record a scope. In that case the scope is inferred from where the uninstaller was found: an entry resolved from the all-users registry (HKLM) is treated as per-machine and triggers elevation, while one resolved from the per-user registry (HKCU) does not. When the uninstaller is located only through FallbackPath (no registry entry), no scope can be inferred and the action does not elevate on its own; set RegistryRoot to HKLM, or run your installer elevated, if the old version was per-machine.
Recommended pattern (deferring reboot)
Section titled “Recommended pattern (deferring reboot)”Uninstall a previous version → %PBPREVUNINSTRESULT%If %PBPREVUNINSTRESULT% == 3010 → remember "reboot needed"; offer reboot at the END of installationIf %PBPREVUNINSTRESULT% == 3 → warn the user; optionally ExitElse → continue