Archive: Uninstall if Installed


Uninstall if Installed
I'm guessing this is a typical question, but I was unable to find it posted. I want to make my installer uninstall the previous installation if, indeed, it does exist. Is this an automatic thing, or do I need to manually add this to the script? If manual, what do I use to check it's existance. It seems to uninstall, I would just:

Delete "$INSTDIR\Uninst.exe"
DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\AppName"
DeleteRegKey HKEY_LOCAL_MACHINE "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\AppName"
RMDir "$INSTDIR"

thanks again...


See the archive function "Auto-uninstall old before installing new". It will help you much.


Thanks Deguix!


OK, well I tried that and got some sort of uninstall initiation error (or somthing of the sort). So I found the following code and tried it:

Function .onInit
check:
ReadRegStr $1 HKLM \
"Software\Microsoft\Windows\CurrentVersion\Uninstall\${PROGRAM_NAME}" \
"UninstallString"
StrCmp $1 "" done cont

cont:
HideWindow
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "${PROGRAM_NAME} \
is already installed.$\n$\r$\n$\r \
Click 'OK' to remove the previous version or 'Cancel' to abandon \
this upgrade." IDOK uninst
Abort
uninst:
ClearErrors
Exec '$1'
; IfErrors cont
uninst_wait:
Sleep 500
FindWindow $0 "" "${PROGRAM_NAME} Uninstall "
IsWindow $0 uninst_wait ""
uninst_finish:
Sleep 500
FindWindow $0 "" "${PROGRAM_NAME} Uninstall: Completed"
; StrCmp $0 "" show_error
IsWindow $0 uninst_finish ""
done:
BringToFront
FunctionEnd

This "kind of" worked, but not really. The first window comes up asking if I want to uninstall, and I click OK. After clicking OK, the second window comes up, but doesn't wait for me to say uninstall, but rather the install window comes up. I can pull the uninstall window from the task bar, but that's not too intuitive. Anything I can do to make this better? Thanks!


I do not recommend you to use that code, it isn't really a good method.

Use the code in the archive page and make sure your code is correct. You should also check http://nsis.sourceforge.net/site/ind...&tx_faq_faq=14


Use the code in the archive page and make sure your code is correct. You should also check http://nsis.sourceforge.net/site/ind...&tx_faq_faq=14
If I use the faq's script(ExecWait '"$INSTDIR\uninstall.exe" _?=$INSTDIR') , then my application's folder can't be totally cleaned up.

If I use this (ExecWait ExecWait '"$INSTDIR\uninst.exe"'), then the uninstaller won't wait for the installer as faq says.

Also, if the user deletes the uninstaller.exe, then none of above will happen.

Any suggestion for this?

Thanks a lot!

Why would it not clean up the install dir?

Vytautas


You should clean up the uninstaller and the application folder after running the uninstaller.


Or simply copy the uninstaller to the temporary directory yourself and execute it with the same command line arguments.