Archive: change PATH using variables


change PATH using variables
I am trying to set a variable and then use that variable in the path. My problem is that the when I open another command window the PATH look right but it is treating the %VAR% as "%VAR%" and not whatever %VAR% resolves into.

To put it another way - why don't this work as expected:

WriteRegStr \
HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" \
"BOB" "C:\bob"

# Tell Windows to re-read its config
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000


ReadRegStr $0 \
HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" \
"Path"
MessageBox MB_OK "ReadRegStr:Reg=$0"

StrCpy $0 "$0;%BOB%"


WriteRegStr \
HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" \
"Path" "$0"

MessageBox MB_OK "ReadRegStr:Reg=$0"

# Tell Windows to re-read its config
SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000


Thanks in advance.


You'll have to resolve %BOB% yourself using ExpandEnvStrings or ReadEnvStr. The PATH environment variable isn't recursively expanded.


Under Win2000 the registry entry for PATH is set to:

%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem

Is it the 'cmd' program that is doing the mangling behind the scences?
When you change the PATH using MyComputer->Properties->Advanced->Environment then it 'appears' to work.


Hi davidnewcomb!

The path value is of type REG_EXPAND_SZ. If you write it with WriteRegStr the entry becomes a type REG_SZ and it will never expand to the full path (eg. %windir% -- c:\windows) in the future again. (You'll see that if you go into cmd and execute path, %windir% is shown and is not in expanded state.)

Have a look into this wiki article:

http://nsis.sourceforge.net/Path_Manipulation

Cheers

Bruno


Thanks very much - that hit the spot.