Reputation: 1075
I can't figure out how to get to the PATH variable in an NSIS script. Here's what I tried, but it returns 'error' in $0:
nsExec::ExecToStack 'echo %PATH%'
Pop $0
MessageBox MB_OK "$0"
Also tried escaping the % signs with $s, to no avail. Putting just some string instead of %PATH% also does not work. I saw a suggested example just like this one using Exec instead of ExecToStack, but that did not work either. What am I missing?
Upvotes: 1
Views: 1389
Reputation: 101764
NSIS already has a built-in instruction for this: ReadEnvStr $0 PATH
.
ExecToStack
did not work because echo
is a internal command in cmd.exe, not a .exe. You would have to execute it as cmd.exe /c echo %path%
.
Remember that %path% can be longer than the NSIS string limit so you should not write it back to the registry after storing it in a NSIS variable. Use the EnVar plug-in to safely modify %path%.
Upvotes: 5