Windows – How to add a Windows environment variable without rebooting

environment-variableswindows

I 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?

Best Answer

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