How to execute an NSIS uninstaller from within an another NSIS installer and wait for it to finish?
Asked Answered
B

2

13

I have an installer, a compiled NSIS script and it first checks if another version of my application is running on the system. If another instance exists, then it first triggers the silent uninstallation and then proceeds with installation of the new instance.

I use ExecWait to trigger the uninstaller in the silent mode but my main installer process does not wait and goes ahead with the installation process.

How do I force the main installer to wait for the silent uninstallation to complete first?

Baritone answered 13/1, 2011 at 4:53 Comment(1)
G
12

There is a special uninstaller parameter you need to use (The reason for this is that normally the uninstaller needs to be able to delete itself)

ExecWait '"$INSTDIR\uninstaller.exe" /S _?=$INSTDIR'
Gabion answered 13/1, 2011 at 6:31 Comment(7)
+1: I think, this doesn't answer the question, works anyway for small apps. So, +1 for workaround :-). Actually, ExecWait still doesn't wait for the end of uninstaller, but uninstaller is now executed silently (/S) in background. If uninstaller takes long time, it would uninstall also currently installed data. Thus, uninstaller and installer would work in parallell. So pay attention!Fez
@Valentin: What makes you think ExecWait does not wait? It does WaitForSingleObject(hChildProcess,INFINITE);Gabion
+1 See here for how to implement this on a .onInit function.Preheat
@ValentinHeinitz this problem actually hit me recently. Took my a while to figure out what's going on, thought it was the anti-virus software at firstPelican
I've tested this, and in my case it doesn't wait for the uinstaller, but returns immediately.Lykins
@Lykins Something wrong with the way you pass the parameters perhaps?Gabion
I don't know what was wrong. The line was exactly as written here, and I tried multiple variations, but still the second uninstall process was spawned. In the end I simply used RMDir on the directories at risk of clashing with older versions.Lykins
E
7

It is not just about "ExecWait". It is also about "_?", a special uninstaller instruction. Actually, during uninstall the uninstaller.exe is copied to a temp directory and then executed from there.

This step of copying and invoking a new uninstaller from temp directory might be fast and the call would come back immediately without actually waiting for the uninstaller to complete.

By using "_?" instruction you tell NSIS to run the uninstaller from the same place and not from the temp directory.

By using "ExecWait" in addition to the "_?" you tell NSIS to wait for the "uninstaller" process to complete and then return. This way you achieve what you need.

refer http://nsis.sourceforge.net/Docs/Chapter3.html#3.2.2 for more information.

Examine answered 7/12, 2011 at 10:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.