How can I refresh my PATH variable from the registry, without a reboot, logoff, or restarting explorer?

I've made some changes to the %PATH% variable in the registry. Now, I'd like to see those changes applied without having to go so far as a logoff, reboot, or reload of Explorer. Is there a way this can be done?

I'd rather do this via some sort of command that can be put at the end of a .BAT file, and don't want to use any tools other than those that come with the OS in a fresh install. This needs to be minimally compatible with Windows XP SP3, and should work all the way up to Windows 7 x64 and Server 2008 R2.

5

4 Answers

  • Change either User or System PATH in System Properties.
  • Running this batch file pulls the new PATH variables with a REG query.
  • The FOR commands parse the PATH variables from the REG results.
  • The current PATH is updated to the registry values.
  • I use ConEmu for my consoles and it runs this batch file on each new console to refresh the PATH so a reboot isn't necessary.

@echo off
echo.
echo Refreshing PATH from registry
:: Get System PATH
for /f "tokens=2*" %%A in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path') do set syspath=%%B
:: Get User Path
for /f "tokens=2*" %%A in ('reg query "HKCU\Environment" /v Path') do set userpath=%%B
:: Set Refreshed Path
set PATH=%userpath%;%syspath%
echo Refreshed PATH
echo %PATH%

The task Commands parameter in ConEmu launches C:\Windows\System32\cmd.exe with the /k switch to run the refreshpath.cmd above and then remain. That updates the path and leaves the console open.

C:\Windows\System32\cmd.exe /k refreshpath.cmd

ConEmu Task settings

3

If you are trying to use the new value of the path variable from within a Windows command shell, all you should need to do is close your command shell window and open a new one. The new command shell will load the updated path variable.

So I think the answer to your original question sort of depends on where exactly you are trying to see the change take effect... Is there something specific that is not working for you?

6

The easiest way to add a variable to the path without rebooting is to open the command prompt and type: PATH=(VARIABLE);%path% and press enter. To check if your variable loaded, type PATH and press enter.

1
  1. Change the PATH variable from the UI in environment variables.
  2. Add a new environment variable, call it something random. Maybe something like CHANGE_TO_UPDATE and put a random value like x in it.
  3. Remember to restart cmd.exe or whatever program that needs to see the new path variable.

This will actually trigger the settings to update when you launch a new application.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like