Archive: ExecWait in Uninstall Section


ExecWait in Uninstall Section
I had problems when I used the ExecWait procedure in Uninstall Section!

Example:
ExecWait "$WINDIR\notepad.exe"

The application does not execute! (Only in Uninstall Section, but in all others instalation sections it works.)


Maragato,

I tested it, no problems at my machine! It just works fine. Maybe there are other problems in the installer...

-Hn3.


Thanks for help!
Please, send me a .nsi file with this case.


The test file:

if executed it runs and waits for notepad
then it creates $DESKTOP\unprob.exe

when run this exe it starts notepad.exe again.

Why wouldn't this not work? Maybe you did something wrong in the rest of the script. Maybe you delete notepad.exe???

Just a guess... :)

Good luck,
Hendri.


ExecWait: Solution
There is a "feature" (bug?) in NSI scripts.
ExecWait does not work when used after RmDir /r $INSTDIR (this is where I have uninstall executable).
However it may not work in other situations, too, but I have not tested it.

Solution: Remove $INSTDIR as the last line in your uninstall script.

These are the fragments of the NSI file:

; Won't work
Section "Uninstall"
RMDir /r $INSTDIR
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\C+Shop v 6.0"
Call un.RmDLL ; This is where ExecWait is called
SectionEnd

; Will work
Section "Uninstall"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\C+Shop v 6.0"
Call un.RmDLL
RMDir /r $INSTDIR
SectionEnd

Piotr.


Piotr,

please tell me what this un.RmDll does. If it tries to display some text (readme.txt or something) that is supposed to be in $INSTDIR of course this will not work because you just deleted the file in the original script. So the correction is obvious then. Just do not delete files if you still have to display/execute them.

But that's my guess for I don't know what this un.RmDll is doing. Just post this script or take a look at it yourself. I expect that this might be the solution to the problem. But I can only tell if there is really a bug or just a mistake in the script when you post the un.RMDLL script.

Or take a look at the uninstall details (in the uninstall window) If you don't find the ExecWait command there, the uninstall could not find or execute the file.

Good luck,
-Hendri.


Hendri,

I've just removed unnecessary code to make it clear. It does not matter what function un.RmDLL does. There is FULL nsi script at the bottom that does not work.
It should probably run write.exe (it's in system directory, not in \TEMP that is removed).
Please make sure the script removes the \TEMP dir. Actually if it's not removed (eg you have it open in Command Prompt or Explorer) the script runs well.
If you move RMDIR just before SectionEnd - works fine !

Probably (I did not look at the code) when installer get's removed (and its dir, too) it looses environment (with PATH variable)

Piotr.

;
OutFile "Test.exe"
InstallDir "C:\TEMP"

Section "Install"
SetOutPath $INSTDIR
File "C:\WINNT\Notepad.exe"
WriteUninstaller "$INSTDIR\uninst.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Test" \
"DisplayName" "Test"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Test" \
"UninstallString" '"$INSTDIR\uninst.exe"'
SectionEnd

Section "Uninstall"
RMDir /r $INSTDIR
ExecWait "write.exe"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Test"
SectionEnd


Piotr,

take a look at this script:

OutFile "Test.exe" 
InstallDir "C:\TEMP"
name test

Section "Install"
SetOutPath $INSTDIR
WriteUnInstaller "$INSTDIR\uninst.exe"
SectionEnd

Section uninstall
RMDir /r $INSTDIR
SetOutPath $WINDIR
ExecWait "write.exe"
sectionend

It works. Apparently, the problem is that once the dir has been removed, the uninstaller cannot find the path anymore. So we have to set it manually to an existing dir, eg "WinDir". BTW, the same is true for an installer like this:
OutFile "Test.exe" 
InstallDir "C:\TEMP"
name test

Section "Install"
SetOutPath $INSTDIR
RMDir /r $INSTDIR
SetOutPath $WINDIR
ExecWait "write.exe"
SectionEnd

I don't know if this is a bug. It seems a bit logical to me since $INSTDIR does not exists anymore. It has to do with the way Windows manages the path and how it can find it, I guess.

But it's nice we know of the problem right now and of the solution. So there are no limitations to the script (in terms of deleting dirs ONLY at the end of the uninstall) but just take care that the program can find the files to be run by including the proper path or resetting the current dir to an existing one.

Good luck, greetz,
-Hendri.