Alex Rivera | Logout

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

Asked 2011-01-13T04:53:03.547
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?

Edit
Report

2 Answers

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'
answered 2011-01-13T06:31:18.567
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.

answered 2011-12-07T10:41:19.417

Your Answer