PC Review


Reply
Thread Tools Rate Thread

How to change PERMANENTLY environment variables from batch script?

 
 
Cindy Parker
Guest
Posts: n/a
 
      20th May 2010
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

 
Reply With Quote
 
 
 
 
John John - MVP
Guest
Posts: n/a
 
      20th May 2010
Cindy Parker wrote:
> 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
 
Reply With Quote
 
John John - MVP
Guest
Posts: n/a
 
      20th May 2010

Cindy Parker wrote:
> 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
 
Reply With Quote
 
Marcello
Guest
Posts: n/a
 
      20th May 2010
REG ADD "HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
MyVar /t REG_SZ /d "Good Morning"

(Restart required.)

Lg
Marcello


 
Reply With Quote
 
John John - MVP
Guest
Posts: n/a
 
      20th May 2010
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



Marcello wrote:
> REG ADD "HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v
> MyVar /t REG_SZ /d "Good Morning"
>
> (Restart required.)
>
> Lg
> Marcello
>
>

 
Reply With Quote
 
Pegasus [MVP]
Guest
Posts: n/a
 
      20th May 2010



"Cindy Parker" <(E-Mail Removed)> wrote in message
news:4bf57064$0$6986$(E-Mail Removed)...
> 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.

 
Reply With Quote
 
Twayne
Guest
Posts: n/a
 
      20th May 2010
In news:4bf57064$0$6986$(E-Mail Removed),
Cindy Parker <(E-Mail Removed)> typed:
> 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.


 
Reply With Quote
 
+Bob+
Guest
Posts: n/a
 
      21st May 2010
On 20 May 2010 17:24:52 GMT, (E-Mail Removed) (Cindy Parker) wrote:

>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/Articl...nt.htm#editing


 
Reply With Quote
 
Charly
Guest
Posts: n/a
 
      21st May 2010

Hi Cindy,

Perhaps this can help you :
http://www.windowsnetworking.com/kba...Variables.html

(or http://tinyurl.com/2d4vul3 if the long URL is wrapped/damaged in the
message).

Charly
 
Reply With Quote
 
Charly
Guest
Posts: n/a
 
      21st May 2010
Charly a écrit :
>
> Hi Cindy,
>
> Perhaps this can help you :
> http://www.windowsnetworking.com/kba...Variables.html
>
>
> (or http://tinyurl.com/2d4vul3 if the long URL is wrapped/damaged in the
> message).
>
> Charly


Oops : Answer already given I see...

Charly
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to change PERMANENTLY environment variables from batch script? Cindy Parker Windows XP General 3 21st May 2010 07:11 PM
How to change/add environment variables from command line PERMANENTLY? Sebastian Kaist Windows XP General 1 1st Apr 2009 01:52 PM
How to change/add environment variables from command line PERMANENTLY? Sebastian Kaist Windows XP Help 3 1st Apr 2009 01:16 PM
Adding environment variables with script / batch =?Utf-8?B?dG9tcG8=?= Windows XP General 1 26th Jun 2006 11:18 AM
set environment variables through batch files =?Utf-8?B?ai1iaXJk?= Windows XP General 6 3rd Feb 2005 08:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:43 AM.