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 Windows user environment variable and then launch an application via either batch file or a script. However, the environment variable is not set to the appropriate value until after the user logs off and logs back on. (I think a more accurate description would be that the new value is not available to the app until after the next logon.)

Is there any way to set a variable in the user's environment so that it's immediately available?

I'm doing this because this program's functionality can be controlled by environment variables, and users will need different functionality at different times. Because of license constraints I need to set this dynamically, if possible.



share|improve this question
up vote 1 down vote accepted

The simplest way to to not set the environment variable at all and run the application from a batch file that sets the environment variable for that session. Only if the variable exists should it not take effect until the next logon

share|improve this answer
That's not the behavior I'm seeing. When I try launching from a batch file, even if the variable does not exist it isn't available until the next logon. – Graham Powell Apr 26 '10 at 21:34
Whoops, looks like I lose this game of "Who's the dumbass?" I was relying on info from a co-worker. Long story short, this worked fine. – Graham Powell Apr 26 '10 at 21:53

Where are you actually setting the variable? If you are setting it in the system properties, it will only affect new shell sessions and not existing ones... but a logoff/logon shouldn't be required, really.

Your best option would be to set your variable in te same batch file that launches the application.

share|improve this answer

If you're user is administrator to the machine, then you can merge the value you need in to registry. Then run the batch file.

This will add the environment variable MYENVIRON with the value MYVALUE

reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v MYENVIRON /t REG_SZ /d MYVALUE /f

share|improve this answer

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.