Windows – Setting and getting Windows environment variables from the command prompt

command lineenvironment-variableswindows

I want to set an environment variable from the command prompt and then be able to access it globally (for instance, I should see it by going to System -> Environment Variables).

When I use the set command, it isn't accessible in a new cmd session.

set NEWVAR=SOMETHING
echo %NEWVAR%

Related questions:

Best Answer

To make the environment variable accessible globally you need to set it in the registry. As you've realised by just using:

set NEWVAR=SOMETHING

you are just setting it in the current process space.

According to this page you can use the setx command:

setx NEWVAR SOMETHING

setx is built into Windows 7, but for older versions may only be available if you install the Windows Resource Kit