thivnor
14th May 2008 02:30 UTC
Set working directory for program called via exec
I would like to have my NSIS script invoke an executable, and have the working directory for the invoked executable be the same as its own current directory. What is happening now is that the working directory for the invoked program is the same as the folder where my NSIS executable is running from.
I have used SetOutPath, but that does not appear to be setting the working directory for the invoked .exe.
I've created a simple test setup to demonstrate this.
debug.nsi has:
System::Call "kernel32::GetCurrentDirectory(i ${NSIS_MAX_STRLEN}, t .r0)"
StrCpy $workingDir $0
MessageBox MB_OK|MB_ICONEXCLAMATION "workingDir: $workingDir"
In other works, it just reports out its working directory.
invoke.nsi has:
StrCpy $OUTDIR "C:\"
SetOutPath "C:\"
Exec "$EXEDIR\subfolder\debug.exe"
No matter what I do, debug.exe reports that the working directory is the same: the directory where invoke.exe lives.
I'm looking for the equivalent to "cd" in a batch file. Or, in Windows Shortcut terms, I want to set the "Start In" property.
Anyway to accomplish this?
I'm using MakeNSIS v2.31
kichik
15th May 2008 22:27 UTC
Does it work with something other than "C:\"?
thivnor
15th May 2008 23:03 UTC
Wow.
I've re-tested this, and determine that, in fact using C:\ doesn't work, but every other folder I've tried does work. I had originally just popped C:\ in, as a quick test. I didn't figure the actual directory mattered.
BAD:
SetOutPath "C:\"
Exec "$EXEDIR\subfolder\debug.exe"
GOOD:
SetOutPath "E:\"
Exec "$EXEDIR\subfolder\debug.exe"
GOOD:
SetOutPath "C:\Foo"
Exec "$EXEDIR\subfolder\debug.exe"
Now ... I'm super-curious! What is so special about C:\ ?
Animaether
16th May 2008 00:31 UTC
C:\, or more accurately - your boot drive's root folder is, well, your boot drive's root folder. Installing into it (which SetOutPath is usually for) is considered 'bad'.
See also "AllowRootDirInstall".
Note that under Vista, unless you mucked with write permissions left and right, writing to root will fail regardless.
thivnor
16th May 2008 00:57 UTC
Hmm... C:\ ... your boot drive's root folder ... now that you put it THAT way, this all makes total sense.
As an aside, I've found NSIS so useful that I now use it as a general purpose programming language, for small Windows utilities. I will need to keep in mind the original point of functions like SetOutPath!
Thanks for the clues !!!