PDA

View Full Version : Uninstall if Installed


stonkers
25th September 2003, 20:18
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...

deguix
25th September 2003, 20:50
See the archive function "Auto-uninstall old before installing new (http://nsis.sourceforge.net/archive/viewpage.php?pageid=326)". It will help you much.

stonkers
26th September 2003, 20:23
Thanks Deguix!

stonkers
26th September 2003, 22:09
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!

Joost Verburg
27th September 2003, 22:56
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/index.php?id=19&backPID=15&tx_faq_faq=14

ursus76
31st January 2004, 00:48
Use the code in the archive page and make sure your code is correct. You should also check http://nsis.sourceforge.net/site/index.php?id=19&backPID=15&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!

Vytautas
31st January 2004, 10:39
Why would it not clean up the install dir?

Vytautas

Joost Verburg
31st January 2004, 12:25
You should clean up the uninstaller and the application folder after running the uninstaller.

kichik
31st January 2004, 12:46
Or simply copy the uninstaller to the temporary directory yourself and execute it with the same command line arguments.