Setting and getting Windows environment variables from the command prompt?

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


We can also use "setx var variable /M" to set the var to system environment variable level instead of user level.

Note: This command should be run as administrator.


setx program "C:\Program Files" /M

/M for set system environment variable level instead of user level like @Minh Chau answer

Test enter image description here

RESTART command line (if you don't restart command line, environment variable will not work)

enter image description here