Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 trying to set a custom environment variable in Windows 7, which needs to be done programmatically as it must be set on multiple computers.

I have been testing one a single machine, but When I create it programmatically, it exists for that session (i.e. in DOS when the command window is open, or in Powershell when the ISE is open) - however, when I close the session the variable disappears?

How do I make it permanent?



share|improve this question

for users
wmic environment create name='test', variablevalue='air',username='domain\username'

for computer
wmic environment create name='test', variablevalue='air',username='system'

can work remotely by using the /node: paramter

maybe overkill but

share|improve this answer
As tony has suggested, add it to the user or system environment variables in the advanced system properties. – joeqwerty Jul 16 '10 at 17:38
Sorry - didn't make it clear in the question: This needs to be done programatically as I need to roll out the variable to multiple laptops. – Ben Jul 16 '10 at 19:58
@ben see the updated answer for more details – tony roth Jul 16 '10 at 21:24
use @shay's method! – tony roth Jul 19 '10 at 20:09

The basic syntax is:


This will create a new permanant env variable for the logged on user:


And this one for the system:

share|improve this answer
This needs a reboot to become "visible", right? Is there a way for it to become available instantly? – Ben Jul 20 '10 at 11:33
Basically yes, if you want it to be visible to a certain application then just restart that app. – Shay Levy Jul 21 '10 at 14:57

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.