Archive: Path and environment variable


Path and environment variable
Hi to all,

I would like to register some environment variables once the installer completed successfully.

Add something to the PATH environment variable
Add something to the CLASSPATH environment variable
Define a new environment variable WEBCONF_HOME

I have seen that for Win2000/NT this information is located on the registry so It would be possible to manipulate the content. However I do not know if NSIS is able to edit the autoexec.bat file ...

I would like also put this for all users on Win2000, as well as shortcuts. There is a thread here but it's for not only (WINDIR\Profiles\All Users is for not, now it's Document And Settings\...)

Thanks for any help


Hi!

Please see this thread.

The last reply contains all the functions you need.

KiCHiK


Hi DarkLord23,

NSIS comes with file appending capabilities. All you need to do is append these lines to the AUTOEXEC.BAT file:


Originally posted by petersa
Hi DarkLord23,

NSIS comes with file appending capabilities. All you need to do is append these lines to the AUTOEXEC.BAT file:
  • SET PATH=%PATH%;[what to add to the path]
  • SET CLASSPATH=%CLASSPATH%;[what to add]
  • SET WEBCONF_HOME=[what to add]
Thanks !!!
Could u please give me more details about the append function? :)

Thanks thanks thanks ;-)

I have given you a link to the entire source code ready for you in functions...


In the same problem, how can I append the path and the classpath in the registry (in case of NT/2000/XP) ???

Thanks

PS : for all users!


Originally posted by kichik
I have given you a link to the entire source code ready for you in functions...
I've had a look at it but i can't find out how i Can append line to the files ... And how I can create new line :( :( :(

What I want is :

If OS is Win9x:

Edit autoexec.bat
add
rem --- Added for webconf ---
set PATH=$INSTDIR\bin\;%PATH%
set CLASSPATH=$INSTDIR\lib\webconf.jar;$INSTDIR\lib\WebcanalApplet.class;%CLASSPATH%
set WEBCONF_HOME=$INSTDIR

If os is win NT/2000/XP

APPEND these information in the registry for all users ...

Thaks for ur help:( :(

My AddToPath function does exactly that but only for PATH. It also changes the registry only for current user so you should change that one.

Have a deeper look, if you still don't understand say so and I will be happy to help you understand.

KiCHiK


Originally posted by kichik
My AddToPath function does exactly that but only for PATH. It also changes the registry only for current user so you should change that one.

Have a deeper look, if you still don't understand say so and I will be happy to help you understand.

KiCHiK
Thanks. In fact I don't figure out how to invoke your function. Something like

AddToPath "$INSTDIR\bin"

???

;)


Push "C:\AddThisDirToPath\"
Call AddToPath


I have also found remains to the times before version 1.80~
Please change every
GetShortPathName $0 $0
;GetFullPathName /SHORT $0 $0

to

GetFullPathName /SHORT $0 $0

[/code]

KiCHiK

Originally posted by kichik

Push "C:\AddThisDirToPath\"
Call AddToPath


I have also found remains to the times before version 1.80~
Please change every
GetShortPathName $0 $0
;GetFullPathName /SHORT $0 $0

to

GetFullPathName /SHORT $0 $0

[/code]

KiCHiK
In your code where are u declaring the KEY to Append. I want to make a new Function to add The classpath and the path to all users. Curently, there is


ReadRegStr $1 HKCU "Environment" "PATH"
StrCmp $1 "" AddToPath_NTwasEmpty
StrCpy $0 "$1;$0"
Goto AddToPath_NTdoIt
AddToClassPath_NTwasEmpty:
StrCpy $1 $0
AddToClassPath_NTdoIt:
WriteRegStr HKCU "Environment" "PATH" $0
Push $OUTDIR
SetOutPath $TEMP
File "RefreshEnv\Release\RefreshEnv.exe"
Exec "$TEMP\RefreshEnv.exe"
Delete "$TEMP\RefreshEnv.exe"
Pop $OUTDIR


The key where I have to write my classpath is:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment\classpath

How can I do this?

Thanks!

Ok sorry It works. But I'm not sure whether

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment

Is the good place to update the variables ....

Anyway, I have antoher question. In your fonction, you only need one param. I need two param for my fonction (add a new environment variable wich takes the name of the variable and its value

Something like


Push "WEBCONF_HOME" $INSTDIR"
Call createEnvVar


Any idea?

It will be easier for you to make it accept two pushes.

Push "WEBCONF_HOME"
Push $INSTDIR
Call createEnvStr

If you don't know how have a look in my StrStr function in the same path.nsi file.

About the registry, personally I prefer this kind of enviorment variable in the current user key because I want every user to have an option and not to force him this PATH from the local machine key.
However, you can do whatever you want, and if you need every user to have this env var then go ahead and put it in the local machine key.

KiCHiK