Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am preparing a set of instructions for automating an installation of some application on our team's computers and as part of that automation I need to add User Environment Variables and System Environment Variables. We are using both Windows XP and Windows 7

I wanted to do it using a *.reg file that will add these variables. So I have several questions:

Is the following correct for User Environment Variables:


Is the following correct for System Environment Variables:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]

What is the difference between:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]
and [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment]

I want to update the PATH environment variable, can I do something like:

[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment]


share|improve this question
up vote 2 down vote accepted

You're basically right re: the user and computer environment locations. If you create values of type REG_SZ Windows will refuse to "expand" other environment variables you might reference in them (i.e. "FOO"="%OTHER_VAR%\bar" as a REG_SZ will create an environment variable FOO with the literal string "%OTHER_VAR%\bar" as its value). Creating values as REG_EXPAND type will cause Windows to expand the variables. It's a quirky behavior because and REG_EXPAND types aren't actually "expanded" by the registry APIs.

"CurrentControlSet" is a symlink to the ControlSetXXX instance being used. If you boot with a different hardware profile you'll get a different "CurrentControlSet". This mechanism can be loosely thought of similiar to different runlevels in an inittab if you're familiar with SYSV *nix.

To demonstrate that "CurrentControlSet" is really a symlink just create a new key under "HKLM\System\CurrentControlSet" and go look for it under "...\ControlSet001". You'll find it there.

Finally, what you want to do w/ adding-on to the PATH variable won't work. You can't have multiple registry values in the same key with the same name. If you create a value named "PATH" then there will be no "%PATH%" for the new "PATH" to expand. Appending to the PATH is a real shortcoming of how the path is stored in the registry. You're going to have to append a string to the "PATH" value and, if you care about uninstallation, you'll need to parse the "PATH" variable to back it off when the user uninstalls.

share|improve this answer
Thanks Evan, your explanations are very helpful. Can you please elaborate on "Parsing" the PATH variable? Can I do this parsing with commands supported by a Registry script? (I am only familiar with the ability to define values and data) – RonK Nov 18 '10 at 13:54
When I say "parse" I'm talking generally about writing program code to examine the contents of the PATH variable and manipulating it (either to append your desired value or to remove it). If you want to "uninstall" something you've added to the PATH variable the right way to handle that is to read the current value, break it up into "chunks" (delimited by ";" characters) and put it back together w/o the "chunk" that you want to remove. That "breaking up" is parsing. – Evan Anderson Nov 21 '10 at 15:00

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.