Highlights

Friday, October 12, 2012

HOW TO - Set Permanent Environment Variables in Windows 7

Sometimes, certain programs may need to set and read user or system environment variables. However, the problem is if you just run a batch to set those values, they'll only be available in the command prompt session. We need a way to write permanently the environment variables.

Some may suggest using Power shell scripts, modifying registry, or writing VB codes. However, I found using the built-in command of Windows - the setx command - the easiest and cleanest in doing the job.

Here's what Microsoft said, "[setx] Creates or modifies environment variables in the user or system environment, without requiring programming or scripting. The Setx command also retrieves the values of registry keys and writes them to text files...

...

  • Setx provides the only command-line or programmatic way to directly and permanently set system environment values. System environment variables are manually configurable through Control Panel or through a registry editor. The set command, which is internal to the command interpreter (Cmd.exe), sets user environment variables for the current console window only."

Reference:
http://technet.microsoft.com/en-us/library/cc755104(v=ws.10).aspx


Setx command applies to Windows Server 2008, Windows Vista and Windows 7, these are platforms very widely used.

The exciting thing of setx is, especially for network administrators, that it supports setting environment variables remotely. Otherwise, you will have to go to each machine and adjust the Environment Variables in the Computer Properties. You may also put these setx commands in your login scripts for your Windows users to run when they logon Windows.

1 comment: