# How do you add a Windows environment variable without rebooting?

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?

-

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

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

-
This problems affects ALL SERVICES, even a restarted service will not see new environment variables. –  gimel May 16 '09 at 10:39
Are you sure it's not because of sharing a svchost process? –  Mark Sowul Nov 26 '13 at 22:57
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.

-
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

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.

-

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.

-

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.

-
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

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.

-

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

-

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.

-