How can I refresh my PATH variable from the registry, without a reboot, logoff, or restarting explorer?
Solution 1:
- 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
Solution 2:
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?