Archive: Automatic uninstall


Automatic uninstall
I'm trying to construct the following:

My setup detects whether or not it has been installed already
and gives a message about this observation. If the user chooses
not to overwrite (so make a backup) then my setup copies everything
it can discover in $INSTDIR to $TEMP and calls the uninstall of the
previous (installed) version. If this uninstall was succesful, the
setup continues installing the new version.

2 problems:

1) is there a way to execute the uninstall "silently"? Normally the
uninstall contains things like "You're uninstalling!!! Continue???".
Can the new setup shut these things down at runtime and run the
uninstall silently?

2) the setup executes the uninstall using ExecWait, but it actually
doesn't wait for the uninstall to be closed. The setup just continues
and (obviously) observes that uninstall was not succesfull. How can I
get the install to wait for the uninstall?


thx, greetz,

- :D Hendri :D -


please help me out....
does nobody have an answer to my questions above???

Please help me out...

Thx,

- :D Hendri :D -


If the uninstaller was generated with 1.7b2 or later, you can do this:


ExecWait '"$INSTDIR\uninst.exe" /S _=$INSTDIR'
Delete $INSTDIR\uninst.exe ; the uninstaller won't be able to delete itself when run above.


And that will silently uninstall and wait. The /S switch will be ignored on earlier uninstallers, but the uninstaller will be executed and waited for though.

-Justin

thx...
Thx Justin!

I'll try your solution.

Greetz,

- :D Hendri :D -


Detection of silent uninstall
Still a question about this silent uninstall:

How to detect at runtime that my uninstall is run silently?
The problem: the /S parameter disappears from the commandline
at run time, so I cannot check this...

My Uninstall has to know this to be able block usermessages like
MessageBox MB_YESNO "You are uninstalling! Continue?"

Thx,

- :D Hendri :D -


When the uninstaller has _=$INSTDIR passed to it you should find that the problem of other parameters going missing will stop. The uninstaller normally copies to and relaunches itself from the $TEMP directory, but the presence of the _= parameter fools it into thinking this has already happened.

Btw, here's a general purpose function I use for getting parameters from the command-line that hopefully might be useful.

; GetNextParm
; Processes the next parameter, which may be quoted, from the string on the
; top of the stack.
; Usage:
; Push <parameters>
; Call GetNextParm
; Pop <next parameter>
; Pop <remaining parameters>
Function GetNextParm
Exch $0
Push $1
Push $9
Push $8
StrCpy $1 ""

; Trim leading space
TrimLeading:
StrCpy $9 $0 1
StrCmp $9 "" Done
StrCmp $9 '"' DelimitQuote
StrCmp $9 " " "" DelimitSpace
StrCpy $0 $0 "" 1
Goto TrimLeading

; Begin a quote-delimited parameter
DelimitQuote:
StrCpy $0 $0 "" 1
Goto CopyParm

; Begin a space-delimited parameter
DelimitSpace:
StrCpy $9 " "

; Extract the parameter
CopyParm:
StrCpy $8 $0 1
StrCmp $8 "" Done
StrCpy $0 $0 "" 1
StrCmp $8 $9 Done
StrCpy $1 $1$8
Goto CopyParm

Done:
Pop $8
Pop $9
Exch $1
Exch
Exch $0
Exch
FunctionEnd
e.g.
  Push $CMDLINE
Call GetNextParm
Pop $0 ; exe name
StrCpy $9 "" ; /S flag

ParmsLoop:
Call GetNextParm
Pop $0
StrCmp $0 "" ParmsDone ; No more parms
StrCpy $1 $0 2
StrCmp $1 "_=" ParmsDone ; No more /useful/ parms
StrCmp $0 "/S" ParmSlashS
Goto ParmsLoop

ParmSlashS:
StrCpy $9 "Y"
Goto ParmsLoop

ParmsDone:
Pop $0 ; Tidy the stack
StrCmp $9 "Y" Silent NotSilent
etc...

Good luck :)

Dave.

thx...
Thx Dave,

your solution (GetNextParm) work great!

Besides that I would like to inform you about the fact that the
solution by Justin (with /S parameter and deleting uninstall after
the actual uninstall) doesn't work on slow machines (like mine).

After ExecWait returns, Windows hasn't really shut down the program,
so we cannot delete it. Use something like:

code:-----------------------------------------------------------------
ExecWait '"$INSTDIR\uninst.exe" /S _=$INSTDIR'
Sleep 500 ; wait for the uninstall to close
Delete $INSTDIR\uninst.exe ; the uninstaller won't be able to delete itself when run above.
----------------------------------------------------------------------

This works fine on my machine!

Good luck, thx again Dave, greetz,

- :D Hendri :D -