Home » Questions » Computers [ Ask a new question ]

Setting and getting Windows environment variables from the command prompt?

Setting and getting Windows environment variables from the command prompt?

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).

Asked by: Guest | Views: 75
Total answers/comments: 3
Guest [Entry]

"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"
Guest [Entry]

"setx program ""C:\Program Files"" /M

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

Test

RESTART command line (if you don't restart command line, environment variable will not work)"
Guest [Entry]

"I want to add that if you are using the /s parameter with setx in order to set environment variables on a remote computer, the ""Remote Registry"" service needs to be running on the target machine or else you will receive a ""ERROR: The specified operation could not be completed.""

(I have asked Microsoft to update their TechNet article on setx to include this information.)"