7

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 4

7
  • 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
  • When I run for /f "tokens=3*" %%A in ... do set syspath=%%A%%B the output does not include the first space in my Path, e.g. C:\Program Files becomes C:\ProgramFiles. Instead it would work better to use for /f "tokens=2*" %%A in ... do set syspath=%%B Jan 18, 2017 at 4:24
  • Dave, may you say step-by-step, what you do, that new ConEmu console run with this batch file? Where did you put in this code? Thanks. Feb 26, 2017 at 6:55
  • Changing set PATH=%userpath%;%syspath% to call set "PATH=%userpath%;%syspath%" also enables expansion of environment variables that are in the path string.
    – Karlsson
    Oct 3, 2019 at 11:38
0

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
  • I'll have to test this. I'd tried opening a new command shell, but hadn't closed the first yet I think.
    – Iszi
    Feb 17, 2012 at 0:48
  • Also, which variable are you changing - the system path or the user path? I am nearly certain that the behavior will be different for each (they get refreshed based on different triggers). Feb 17, 2012 at 11:12
  • 1
    The variable is in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
    – Iszi
    Feb 17, 2012 at 17:10
  • 3
    Tested. No luck here. CMD shell was closed when Registry key was changed, opened a new one after and the PATH change doesn't seem to have taken effect.
    – Iszi
    Nov 3, 2014 at 15:52
  • 2
    This doesn't actually work. It will load the old value of the path variable.
    – iopq
    Mar 31, 2015 at 23:28
-2

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
  • I think that he means to ask how to make the changes to PATH be reflected in the CMD without rebooting. Jul 15, 2018 at 13:37
-2
  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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .