How to change/add environment variables from command line PERMANENTLY?

  • Thread starter Sebastian Kaist
  • Start date
S

Sebastian Kaist

When I open a command prompt in WinXP and type

set FOOBAR=D:\test\project

then the env variable FOOBAR is set for this command prompt session (only !!) to the (new) value.
It is however NOT changed for the "global" environment of the whole machine.
To change it for the "global" machine I have always to go to

Control Panel->System->Advanced Tab->Environment Variable Button

and change it manually there.
This is very unconvenient.

Is there a way to change the "global" env variable values PERMANENTLY from command line/from batch script?

Maybe I have to change the Registry (where exactly) ?

Assume I want to change ONE path pattern in the PATH variable (not only add it).
Can I do this with a command similar to

CHANGEENVvalue.exe var=PATH "D:\myoldpath\" "D:\mynewpath\"

....and afterwards all path patterns are replaced permanently ?

Sebastian
 
P

Pegasus [MVP]

Sebastian Kaist said:
When I open a command prompt in WinXP and type

set FOOBAR=D:\test\project

then the env variable FOOBAR is set for this command prompt session (only
!!) to the (new) value.
It is however NOT changed for the "global" environment of the whole
machine.
To change it for the "global" machine I have always to go to

Control Panel->System->Advanced Tab->Environment Variable Button

and change it manually there.
This is very unconvenient.

Is there a way to change the "global" env variable values PERMANENTLY from
command line/from batch script?

Maybe I have to change the Registry (where exactly) ?

Assume I want to change ONE path pattern in the PATH variable (not only
add it).
Can I do this with a command similar to

CHANGEENVvalue.exe var=PATH "D:\myoldpath\" "D:\mynewpath\"

...and afterwards all path patterns are replaced permanently ?

Sebastian

After running the set command, run one of the following commands as well:
setx.exe (Win2000 Resource Kit)
setenv.exe (ftp://barnyard.syr.edu/pub/vefatica/setenv.exe)
 
A

Alister

Sebastian Kaist said:
When I open a command prompt in WinXP and type

set FOOBAR=D:\test\project

then the env variable FOOBAR is set for this command prompt session (only
!!) to the (new) value.
It is however NOT changed for the "global" environment of the whole
machine.
To change it for the "global" machine I have always to go to

Control Panel->System->Advanced Tab->Environment Variable Button
Is there a way to change the "global" env variable values PERMANENTLY from
command line/from batch script?

There is a tool in the Windows XP Service Pack 2 Support Tools named
setx.exe that allows you to change global Environment variables from the
command line.

Alister
 
J

Jose

When I open a command prompt in WinXP and type

set FOOBAR=D:\test\project

then the env variable FOOBAR is set for this command prompt session (only!!) to the (new) value.
It is however NOT changed for the "global" environment of the whole machine.
To change it for the "global" machine I have always to go to

Control Panel->System->Advanced Tab->Environment Variable Button

and change it manually there.
This is very unconvenient.

Is there a way to change the "global" env variable values PERMANENTLY from command line/from batch script?

Maybe I have to change the Registry (where exactly) ?

Assume I want to change ONE path pattern in the PATH variable (not only add it).
Can I do this with a command similar to

CHANGEENVvalue.exe var=PATH "D:\myoldpath\" "D:\mynewpath\"

...and afterwards all path patterns are replaced permanently ?

Sebastian

That is unconvenient.

I created a new FOOBAR variable for my user account through
CP...Advanced... and saved it.
I opened a new CMD window, ran "set" and the FOOBAR variable was
there, it was not before.
The change is permanent unless removed through CP.
I deleted the FOOBAR variable later from CP and it was then gone in a
new CMD window.

You can create/change variables by user or system wide.

I frequently make a system wide adjustment to add stuff to the end of
the PATH variable to make things easier for me later to keep me from
having to CD when in a DOS window. If you don't like the PATH, change
it. They don't call me DOS Boy for nothing.

Here is a link to some discussion that may help:
http://vlaurie.com/computers2/Articles/environment.htm

For more, use google for: dos window environment variable
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top