Skip to content
⌘ NSIS Forum Archive

Exe wont call second exe

5 posts

napy2#

Exe wont call second exe

Hi guys

I'm hoping someone can help me with the following.

I have a NSIS script that silently copies a load of files to a temp folder (C:\Users\username\AppData\Local\Temp) then runs one of the files (an executable) from this location. A button within this exe is then supposed to launch another exe from the same folder however for some reason this doesn't work and instead exits the program and all the files from the temp folder get removed.

The script reads as follows:

Name "Myapp"
Outfile "Myapp.exe"
InstallDir "$pluginsdir"

Function .onInit
SetSilent silent
FunctionEnd

Section ""

InitPluginsDir
SetOutPath "$pluginsdir"
File /r "C:\tocopy\*"
ExecWait '"$pluginsdir\start.exe"'
SetOutPath $exedir
SectionEnd
Strangely, if I manually run the same exe from the temp folder NSIS writes to so that there are two copies of it running consecutively then click the button that;s supposed to call the other exe it opens as expected!?

Clicking the cancel button on the first exe closes it and deletes all the files from the temp directory which I believe is normal behaviour when using the $pluginsdir. Ideally I don't want it deleting all the files until the second exe has run, the user closes out of this then both exes and all other related files can be removed.

What obvious thing am I missing here? 🙂

Thank you
Anders#
InstallDir "$pluginsdir" is not a good idea but you don't really use $instdir here so it should not matter.

This is not a NSIS issue.

If you are the author of start.exe you can just debug it.

If you are not the author then you can try Process Monitor to see which file it actually tries to execute. I'm guessing there is a current directory issue.
napy2#
Thank you for replying.

The program is a quick run type of thing (nothing to install) so doesn't really matter where it extracts to. I figured the temp directory would suffice and although it does write everything there as expected it does as you say seem to have a current directory issue as looking at process monitor start.exe is trying to launch the next exe from:

C:\Users\username\AppData\Local\Temp\nsr23A2.tmp\main.exe

Although the actual location of these two files are:

C:\Users\username\AppData\Local\Temp\nsr23A2.tmp\bin\start.exe
C:\Users\username\AppData\Local\Temp\nsr23A2.tmp\bin\main.exe

I've no idea why though as they all copy to the correct place when NSIS runs and start.exe launches fine from the \bin\start.exe location it just decides to look at the folder above for no reason that I can determine. As I said, if I run start.exe from the location above it calls the other exe just fine.



Have also just noticed the line

ExecWait '"$pluginsdir\start.exe"'

in my original post which is wrong. That should actually read

ExecWait '"$pluginsdir\bin\start.exe"'

which is my mistake. It still doesn't call the other exe though... 🙁
Anders#
SetOutPath "$pluginsdir" sets the current directory to "C:\Users\username\AppData\Local\Temp\nsr23A2.tmp".

You could try this:

Section
InitPluginsDir
SetOutPath "$pluginsdir"
File /r "C:\tocopy\*"

SetOutPath "$pluginsdir\bin" ; Set current directory for buggy app
ExecWait '"$pluginsdir\bin\start.exe"'

SetOutPath $exedir
SectionEnd