Archive: Path Evironment Variable code not working (sort of)


Path Evironment Variable code not working (sort of)
Hi, again.

I got the following code of NSIS site somewhere (can't recall if it was in the archive or someone's post). The purpose is to modify the environment path to add a couple of /bin directories to the beginning of the path.

;add to Registry PATH
Push $R0
Push $R1
StrCpy $R0 "PATH"
ReadEnvStr $R1 "$R0"
MessageBox MB_OK "Current PATH = $R1"
StrCpy $R1 "$INSTDIR\mars\cygwin\bin;C:\jdk1.3.1_08\bin;$R1"
System::Call 'Kernel32::SetEnvironmentVariableA(t, t) i("$R0", "$R1").r0'
ReadEnvStr $R1 "$R0"
MessageBox MB_OK "Updated PATH = $R1"
Pop $R1
Pop $R0

When running the install program, it seems like it is working really well. The two MessageBoxes show the path before and after, and it looks like it has worked. I.e., $R1 after the second ReadEnvStr does show the change. But when the install program has finished and I go to regedit to ensure that all the registry changes are accurate, the path variable is unchanged.

Can anyone figure out
1) why it looks like it is working? Is it only making a temporary change that is undone when the install program ends?

2) how to make it really work?

Dave


It's only a temporary change. To make them permanent, you have to change the registry (Windows NT). For Windows 9x/ME, you should write to Autoexec.bat

And searching the Archive is always a good idea: http://nsis.sourceforge.net/archive/....php?pageid=91


Thanks, Joost.

Usually I do search the archive before I post, but failed to this time. Sorry.

Dave