Take the 2-minute tour ×
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

10 Answers 10

up vote 76 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
3  
For PowerShell users this snippet may be of help: poshcode.org/2049 –  Anders Zommarin Oct 12 '11 at 6:32
4  
If using cmd, you need to restart it if change env variable –  Neil McGuigan Dec 13 '12 at 5:08
  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
2  
Out of all the answers on this page, this is the only one that actually worked for me. Thank you!! –  CoreDumpError Dec 6 '13 at 7:34
    
+1....................... –  IJas Jul 17 at 4:05
    
This worked for me. I think the problem is that if you run cmd through explorer (to save you having to type in long paths) then explorer is never closed, even if you close all explorer windows. Thanks for the solution :) –  Steve Mc Sep 18 at 15:48

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
1  
Are you sure it's not because of sharing a svchost process? –  Mark Sowul Nov 26 '13 at 22:57

Whilst I don't have enough of a reputation to comment on the highest voted answer to this question, I would like to state that it is not exactly correct. I know this because no matter which workaround I tried in this post, nothing actually worked.

The kb article linked to in that answer actually states that:

However, note that modifications to the environment variables do not result in immediate change. For example, if you start another Command Prompt after making the changes, the environment variables will reflect the previous (not the current) values. The changes do not take effect until you log off and then log back on.

The part about the environment variables resetting to the previous values after reloading the command prompt is exactly what I experienced in Windows Server 2008.

The article goes on to say:

To effect these changes without having to log off, broadcast a WM_SETTINGCHANGE message to all windows in the system, so that any interested applications (such as Windows Explorer, Program Manager, Task Manager, Control Panel, and so forth) can perform an update.

That does not imply that Explorer broadcasts a WM_SETTINGCHANGE message once you have changed the system environment variables, or that it actually works. I'm not sure how you would do what is suggested in the KB article (to propagate the changes immediately) from the command prompt.

share|improve this answer

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

I've just experienced the same need, under a Windows 7 Pro, and came up with a simple solution.

First of all, add the new path to the system environment variable by accessing:

"Control Panel" -> "System and Security" or "System" -> "Advanced System Settings" -> "Environment Variables" and under "System Variables" search for "Path". Edit this variable and at the end of the string, just add a semicolon followed by the new path for your app (just the path). Click Ok. This way, you will make sure the new path will be available next time you reboot your machine.

Now, to make the new path available straight away without rebooting the machine, try the following:

Open up a command line interface by typing "cmd" enter (without the quotes) in the start menu search box or Windows Key+R. Next, in the command line just type:

PATH=%PATH%;c:\path\to\your\app.exe [enter]

That's it. To confirm that your Path has been updated, just type:

echo %PATH% [enter]

and check if your new path is there. Next type the name of your app under any path and you should have it running.

share|improve this answer
1  
It's stupid for MS Windows make it a must to reboot the pc for the environment variable change. –  david.wan Nov 12 '13 at 19:59

You have to close the command prompt, and reopen it again, for your path variables to update. The variables are loaded when cmd starts.

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

Typically most of us will check the path via a cmd window by typing echo %PATH%, then we add/modify the path via the "Edit the system environment variables" by editing the "Path" variable.

Then we go back to the cmd window and we get confused because the %PATH% variable looks the same! All you have to do is open a new cmd window and test there. Why? The original cmd window was created with the old environment variables. No need to reboot the system.

share|improve this answer

protected by HopelessN00b Oct 20 at 13:44

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.