How to change PERMANENTLY environment variables from batch script?

  • Thread starter Thread starter Cindy Parker
  • Start date Start date
C

Cindy Parker

Ok, I know. In a batch file I can change environment variables temporarily (=for the
current, remaining session) be entering e.g.

set CLASSPATH=D:\newpath;%CLASSPATH%

However these changes are not visible outside of the current session and furthermore they
are lost after a reboot.

Is there a(nother) way to change them PERMANENTLY from batch script?

I can imagine that there is a way by a regedit or VisualBasic script or 3rd party cmdline tool.

Again: I don't want to edit them manually e.g. in the "System" dialog in control panel.
The change should take place on cmdline from a script

Cindy
 
Cindy said:
Ok, I know. In a batch file I can change environment variables temporarily (=for the
current, remaining session) be entering e.g.

set CLASSPATH=D:\newpath;%CLASSPATH%

However these changes are not visible outside of the current session and furthermore they
are lost after a reboot.

Is there a(nother) way to change them PERMANENTLY from batch script?

I can imagine that there is a way by a regedit or VisualBasic script or 3rd party cmdline tool.

Again: I don't want to edit them manually e.g. in the "System" dialog in control panel.
The change should take place on cmdline from a script

Use SetX (a Resource Kit tool).

John
 
Cindy said:
Ok, I know. In a batch file I can change environment variables temporarily (=for the
current, remaining session) be entering e.g.

set CLASSPATH=D:\newpath;%CLASSPATH%

However these changes are not visible outside of the current session and furthermore they
are lost after a reboot.

Is there a(nother) way to change them PERMANENTLY from batch script?

I can imagine that there is a way by a regedit or VisualBasic script or 3rd party cmdline tool.

Again: I don't want to edit them manually e.g. in the "System" dialog in control panel.
The change should take place on cmdline from a script

You can use the Resource Kit's SetX for this.

John
 
REG ADD "HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
MyVar /t REG_SZ /d "Good Morning"

(Restart required.)

Lg
Marcello
 
Should be put in the CurrentControlSet, for all we know the
ControlSet001 could be a failed control set... Placing it in the
CurrentControlSet will ensure that it is written to the proper
corresponding nnn Control Set.

John
 
Cindy Parker said:
Ok, I know. In a batch file I can change environment variables temporarily
(=for the
current, remaining session) be entering e.g.

set CLASSPATH=D:\newpath;%CLASSPATH%

However these changes are not visible outside of the current session and
furthermore they
are lost after a reboot.

Is there a(nother) way to change them PERMANENTLY from batch script?

I can imagine that there is a way by a regedit or VisualBasic script or
3rd party cmdline tool.

Again: I don't want to edit them manually e.g. in the "System" dialog in
control panel.
The change should take place on cmdline from a script

Cindy

Here are a couple of options:
- setx.exe (Win2000 Resource Kit)
- setenv.exe (ftp://barnyard.syr.edu/pub/vefatica/setenv.exe)

Note that with either tool the change will only affect processes launched
*after* you issue this command. It has no effect on pre-existing processes.
 
In
Cindy Parker said:
Ok, I know. In a batch file I can change environment
variables temporarily (=for the
current, remaining session) be entering e.g.

set CLASSPATH=D:\newpath;%CLASSPATH%

However these changes are not visible outside of the
current session and furthermore they
are lost after a reboot.

Is there a(nother) way to change them PERMANENTLY from
batch script?

I can imagine that there is a way by a regedit or
VisualBasic script or 3rd party cmdline tool.

Again: I don't want to edit them manually e.g. in the
"System" dialog in control panel.
The change should take place on cmdline from a script

Cindy

Try Google or your favorite Seach Engine, whatever it might be. Maybe:
batch "permanent environment" +change
or similar.
 
Ok, I know. In a batch file I can change environment variables temporarily (=for the
current, remaining session) be entering e.g.

set CLASSPATH=D:\newpath;%CLASSPATH%

However these changes are not visible outside of the current session and furthermore they
are lost after a reboot.

Is there a(nother) way to change them PERMANENTLY from batch script?

I can imagine that there is a way by a regedit or VisualBasic script or 3rd party cmdline tool.

Again: I don't want to edit them manually e.g. in the "System" dialog in control panel.
The change should take place on cmdline from a script

Cindy

You can run a command line update to the registry from a script to
change the path that is stored there. You run it form the command line
or a batch file with a command like this:

C:\Windows\regedit.exe /s c:\myfile.reg

myfile has to contain a reg key in text format, something like this:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session
Manager\Environment]
"CLASSPATH"=".;C:\\Program Files\\Java\\jre6\\lib\\ext\\QTJava.zip"

Unfortunately that's not the key and value you want to set. It's
"PATH" and it's stored as a hex value, not text. So, creating the .reg
file to add would be a chore. If you want to set a fixed path for the
system, you could just set it manually, export the key to get the .reg
file you need, then use it in the future. But, if you need to add your
directory to the end of whatever is on the system currently, that
won't work.

I'd suggest you take a look towards the bottom of this page. There are
some other alternatives.

http://vlaurie.com/computers2/Articles/environment.htm#editing
 
Back
Top