Reputation: 387
I have an installer that makes it mandatory to uninstall the previous version before the new version can be installed.
However, when the initial question gets asked it does so. But the uninstall dialogue doesn't.
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
"${PRODUCT_NAME} is already installed. $\n$\nIf you have software older than 3.0, please manually uninstall it with Windows before procedeing. $\n$\nClick `OK` to remove the \
previous version or `Cancel` to cancel this upgrade." \
IDOK uninst IDCANCEL giveup
; I am giving up
giveup:
Abort
; Run the uninstaller
uninst:
ClearErrors
ExecWait '$R0 _?=$INSTDIR' ;Do not copy the uninstaller to a temp file
IfErrors no_remove_uninstaller
no_remove_uninstaller:
install:
; ..... snip
Then here
Function un.onInit
MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "Are you sure you want to completely remove $(^Name) and all of its components?" IDYES NoAbort
Abort
NoAbort:
FunctionEnd
So, when it is a standalone uninstall it seems to be fine, but when it is uninstalling at the beginning, if a user says No/Cancel, the installer will still go on when they say no. I can't think of a reason as to why. As an ill side-effect, the program files icon on start menu is orphaned and the uninst.exe is orphaned. But if you run the uninstaller "manually" it seems to be fine. I had no changed any of that logic other than trying to get this thing to work.
Thanks.
Upvotes: 1
Views: 1747
Reputation: 101666
It is important to quote the path in ExecWait and then check the exit code:
Function .onInit
StrCpy $R0 "c:\old install" ; TODO: Somehow find the old install (in the registry? InstallDirRegKey?) and put its path in $R0
IfFileExists "$R0\*.*" 0 noOldInstall
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "${PRODUCT_NAME} is already installed. blahblah..." IDOK uninstOld
Abort
uninstOld:
ExecWait '"$R0\uninstaller.exe" _?=$R0' $R1
; Exit codes are documented in Appendix D in the help file.
StrCmp $R1 0 noOldInstall ; Success? If so we are done...
Abort ; Uninstaller was canceled or failed, we cannot continue
noOldInstall:
FunctionEnd
Upvotes: 2