Skip to content
⌘ NSIS Forum Archive

Setting Environment Variables

12 posts

vrunda#

Setting Environment Variables

hello,
I am new to the NSIS installer.During installation i need to set values for environment variables,like (classpath for java etc)
How do i do this,
thanks in advance
-vrunda
kichik#
This should do the trick:



Unless you want to temporarily set it for just the current process and sub-processes you will run from the installer and then you'll need:

Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.
vrunda#
hello,
could not make it work,i need to set the variable values for system variables,
with the following code
StrCpy $1 "value"
WriteRegStr HKU "Environment" "variable" $1
i am not able to set the values for the variable.but with same code i can set the value for current user variables.
how do i do this,
is any simple way out to this,other than .dll etc?
thanks
-Vrunda
kichik#
Oops, sorry... Wrong link.

Here is the right one:
Are you a developer who uses NSIS to distribute your application? Are you a Winamp plug-in developer who wants to use NSIS to distribute your plug-in? Have suggestions for other people like you? This is the place.
vrunda#
hello,
thanks for the reply,but could not open the code link 🙁 FYI i am working on windows 2000 platform.
Why i am not able to set the variable values for all users(like other system variables) with the code
StrCpy $1 "value"
WriteRegStr HKU "Environment" "variable" $1
How do i do this?
thanks in advance
-Vrunda
kichik#
HKU is not the right place to write it. I have created a new archive page that explains it all:


Have a look at the ALL_USERS define I have added, that's what you need.
vrunda#
hello
not working on NT platform.
The code in the .nsi file is

!verbose 3
!include functions.nsh
!verbose 4

Section
Push "JAVA_HOME"
Push "c:\jdk"
Call WriteEnvStr
SectionEnd

Section uninstall
# remove the variable
Call un.DeleteEnvStr
SectionEnd

and the
.nsh file has the functions in the code given by you.
no error is generated,and still the value is not set. 🙁
How do i do this.
thanks in advance
-Vrunda
kichik#
According to this code the environment variable will be written into HKCU\Environment. You didn't define ALL_USERS before including functions.nsh. Are you sure it's not in HKCU\Environment? If it's not, attach your script and I will create a testing script for you.
vrunda#
hello,
sorry for the delay in reply.Was a bit busy in some other issues. the .nsi file code goes like this

;The name of the installer
Name "TEMP"

;The file to write
OutFile "Temp.exe"

InstallDir $WINDIR\Temp2


;Texts on the dialogs

InstType Typical
!define ALL_USERS

!verbose 3
!include "functions.nsh" ;includes the script provided by you
!verbose 4

Section "Add to path"
PUSH "USERDIR"
PUSH "c:/temp1"
Call WriteEnvStr
SectionEnd
Waiting for your reply
thanks in advance
-Vrunda Divekar
kichik#
Please get the latest code too as there was a "Control\" missing in the registry path. Together with NSIS 2.0b2 it should really work this time 😉 I have tested it yet again and it worked.