Updating System Environment Variable

TitaniumZX

Limp Gawd
Joined
Jul 15, 2004
Messages
328
Anyone know of an easy way to update the system environment variable for a computer running Windows 2003 (VBScript or batch)? I have to update the variable on 20+ servers and don’t want to do them manually via remote desktop. Thanks.
 
Here is a possible method:
1. Change the appropriate variables on one machine.

2. use regedit and export them to a reg file. ( [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Control\Session Manager\Environment] )

3. Clean up the file with notepad

4. Open the file on the other machines with a batch file ( regedit /s filename.reg )
/s is only necessary if you want it to be silent without prompting to confirm.
 
Langford, thanks for the quick response. I do have a few questions.

1) I'm looking at the registry and under \HKEY_LOCAL_MACHINE\SYSTEM\ there are three items that has "ControlSet" and they are: ControlSet001, ControlSet002 & CurrentControlSet. Do I have to do this for all three because I noticed the environment variable keys are present.

2) What do you mean by "clean" it up with notepad? I exported it and see that it has all the environment variable keys within the "Environment" folder. Do you mean delete all the other keys except for the one I'm updating? Like the example below, I updated "TestVariable", so I should remove the key for "windir"?

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Control\Session Manager\Environment]
"windir"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
00,25,00,00,00
"TestVariable"="C:\TestVariable\"

3) Can I schedule the batch file to run from one machine and update all 25? Again, thanks.
 
TitaniumZX said:
Langford, thanks for the quick response. I do have a few questions.

1) I'm looking at the registry and under \HKEY_LOCAL_MACHINE\SYSTEM\ there are three items that has "ControlSet" and they are: ControlSet001, ControlSet002 & CurrentControlSet. Do I have to do this for all three because I noticed the environment variable keys are present.

2) What do you mean by "clean" it up with notepad? I exported it and see that it has all the environment variable keys within the "Environment" folder. Do you mean delete all the other keys except for the one I'm updating? Like the example below, I updated "TestVariable", so I should remove the key for "windir"?

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet002\Control\Session Manager\Environment]
"windir"=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,\
00,25,00,00,00
"TestVariable"="C:\TestVariable\"

3) Can I schedule the batch file to run from one machine and update all 25? Again, thanks.

1. It should probably be CurentControlSet. Changing them all to match should be a safe approach.

2. By clean it up, I mean remove non-relivant entries, just like you said.

3. This will be unique to your network configuration. if you have a regular scipt that passes by these machines you probably can use it, but to be honest you should probably schedule a reboot after any changes of this nature. Scheduling downtime would probably be prudent, even if you end up not needing much of it. There are tools available that can let you remotly run processes, provided you have the administrative permissions to the machines. http://www.sysinternals.com/Utilities/PsExec.html

In any case, you will want to do a test run on a simgle machine, after backing up it's registry.
 
You might check the built in reg command, it allows you to add entries into the registry of remote machines that you have admin rights to.

> reg add /?
 
Back
Top