Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This is probably an easy answer, but I have never been able to find it by googling. I simply would like to add an Environment variable to a Windows machine (desktop or server) and be able to use it without rebooting that machine.

Say you have a production server which hosts a variety of apps and a new app needs a particular Environment variable to run. You do not want to reboot it while users are connected to your other apps. What choices do you have? I don't like the wait-until-a-good-time-to-reboot option. There must be a better way. What am I missing?

share|improve this question

6 Answers

up vote 48 down vote accepted

Changes to environment variables should take effect immediately, if you make the change via the main Properties dialog for the computer in question (go to My Computer | Properties | Advanced | Environment Variables). After the changes are saved, Explorer broadcasts a WM_SETTINGCHANGE message to all windows to inform them of the change. Any programs spawned via Explorer after this should get the updated environment, although already-running programs will not, unless they handle the setting change message.

I'm not able to tell from your problem description what specific problem you're having with this. Can you tell us more about the specific scenario that isn't working?

This KB article may also be of use: How to propagate environment variables to the system

share|improve this answer
1  
Ok, I guess I must have seen this behavior on a running service or something. I added a new environment variable using the method described above. Then, I was able to see the value after opening up a new command prompt and using the command "echo %<myvar>%. Thank you both for your answers. – Chad Braun-Duin May 21 '09 at 1:09
For PowerShell users this snippet may be of help: poshcode.org/2049 – Anders Zommarin Oct 12 '11 at 6:32
1  
If using cmd, you need to restart it if change env variable – Neil McGuigan Dec 13 '12 at 5:08

One thing to keep in mind is that many programs obtain the environmental variables when they're first started, so while windows may not need a restart, some programs might before they'll be able to use the new variables. Good example of this is having to open a new command prompt window after adding a PATH (yes, I've been tripped up by this).

share|improve this answer
This problems affects ALL SERVICES, even a restarted service will not see new environment variables. – gimel May 16 '09 at 10:39

I had this same issue. I read somewhere that killing the explorer.exe process would update the variables and it worked. Then I just had to run explorer from the task manager.

share|improve this answer
  1. In a command prompt type: runas /user:yourusername@yourdomain cmd
  2. It will open up a new cmd prompt and type: taskkill /f /im explorer.exe
  3. Then type: explorer.exe

Now after closing all command prompts, you will see that the PATH variable has been truly updated.

All command prompts must be closed. Then reopen a new command prompt, type path and you will see the new data.

share|improve this answer

A possible solution for services is to run them temporarily as another user (other than LocalSystem, LocalService, NetworkService). For example for Apache service this works without any problems. To change service account open services.msc console, select service, click service properties and on second tab enter logon credentials for a user. Restart the service and it's environment variables should be up to date.

If this is a user which has been logged of than this should work without problems. If you are using current user account, then restarting explorer.exe might be necessary too. Also note that running services as normal user account might create security risks.

share|improve this answer

The only way I got the PATH environment variable to update after ADDING a new path was the following:

1) In a command prompt type: runas /user:yourusername@yourdomain cmd 2) It will open up a new cmd prompt and type: taskkill /f /im explorer.exe 3) Then type: explorer.exe

Now after closing all command prompts, you will see that the PATH variable has been truly updated.

So, basically do you mean to restart the explorer ? That can be done in other ways as well

share|improve this answer

Your Answer

 
discard

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.