Another approach is to make a UninstallPrevious
hidden section and make it run before all other sections in the installer. I also suggest making the uninstaller run silently.
; The "" makes the section hidden.
Section "" SecUninstallPrevious
Call UninstallPrevious
SectionEnd
Function UninstallPrevious
; Check for uninstaller.
ReadRegStr $R0 HKLM "${HKLM_REG_KEY}" "InstallDir"
${If} $R0 == ""
Goto Done
${EndIf}
DetailPrint "Removing previous installation."
; Run the uninstaller silently.
ExecWait '"$INSTDIR\Uninstall.exe /S"'
Done:
FunctionEnd
The advantage of this approach is that the user won't uninstall the old version until they're ready to install the new version. Furthermore, they don't even have to make a decision about uninstalling the old version, it just magically disappears.
Of course, depending on your needs, you may want the user to confirm uninstalling, in which case use the spinner_den's approach.