Archive: Problem with Auto-Uninstall


Problem with Auto-Uninstall
I want to use the auto-unstall script from the archive, but when I try I find two problems (both of which stem from the call to ExecWait).

#1 So far as I can see, ExecWait always sets the error flag, this creates an infinite loop in the onInit function

#2 If I comment out the call to IfErrors (so as to avoid the loop), it appears to me that ExecWait does not actually wait.


The relevant sections of my script are below:

;--------------------------------
;Installer Functions

Function .onInit
check:
ReadRegStr $1 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" "UninstallString"
StrCmp $1 "" done cont
cont:
HideWindow
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "${PRODUCT} 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
ExecWait '$1'
IfErrors cont
uninst_wait:
Sleep 500
FindWindow $0 "" "${PRODUCT} Uninstall"
IsWindow $0 uninst_wait ""
done:
BringToFront
FunctionEnd

;--------------------------------
;Uninstaller Section

Section "Uninstall"

;ADD YOUR OWN STUFF HERE!

Delete "$INSTDIR\MyApp.exe"
Delete "$INSTDIR\Uninstall.exe"

RMDir "$INSTDIR"

DeleteRegKey /ifempty HKCU "Software\MyFirm\${PRODUCT}"
DeleteRegKey /ifempty HKCU "Software\MyFirm"

SectionEnd


So what's the content of $1?


Check the first line of the onInit function:

ReadRegStr $1 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" "UninstallString"


You'll have to add ClearErrors above the registry reading to clear any previous errors.

And you should check the FAQ: http://nsis.sourceforge.net/site/FAQ.15.0.html

It contains this item:

When I use ExecWait uninstaller.exe it doesn't wait for the uninstaller

http://nsis.sourceforge.net/site/ind...&tx_faq_faq=14


Well...

The onInit function I used was taken from the archive (see: http://nsis.sourceforge.net/archive/...instances=0,11), and the changes suggested by the document you cite (which, by the way, I did not find when I searched the archive) seems to me to compromise the uninstall process (because the uninstaller won't be able to delete itself).

Does that mean that it is effectively impossible to write a script that does a complete uninstall before installing a new version?

JAS


A solution:

Looking more closely at the onInit function I (finally) understood the purpose of the uninst_wait section. It does the job that ExecWait cannot do in this case (because of the way uninstall works).

Except, it doesn't work. It will work, however, if you append a space to the window title paramater of the FindWindow call.

Or, rather, it half-way works. What is needed is yet another version of that section because the uninstaller changes its caption on its finish page. So this is what I have now, and it works:

;--------------------------------
;Installer Functions

Function .onInit
check:
ReadRegStr $1 HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT}" "UninstallString"
StrCmp $1 "" done cont
cont:
HideWindow
MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION "${PRODUCT} 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 "" "${PRODUCT} Uninstall "
; StrCmp $0 "" show_error
IsWindow $0 uninst_wait ""
uninst_finish:
Sleep 500
FindWindow $0 "" "${PRODUCT} Uninstall: Completed"
; StrCmp $0 "" show_error
IsWindow $0 uninst_finish ""
done:
BringToFront
FunctionEnd

JAS

P.S. The additional call to ClearErrors you suggested can't really help since the error occurs after ExecWait (or in my revised version, after Exec) and that call is prefaced by a call to ClearErrors.


Use http://nsis.sourceforge.net/site/in...5&tx_faq_faq=14 and delete the uninstaller after using ExecWait (you can check a registry key to see whether the user has chosen to uninstall).


Sorry Joost the link doesnt work....thanks


This one should work:

http://nsis.sourceforge.net/site/ind...&tx_faq_faq=14