@echo off :: :: RefreshEnv.cmd :: :: Batch file to read environment variables from registry and :: set session variables to these values. :: :: With this batch file, there should be no need to reload command :: environment every time you want environment changes to propagate
::echo "RefreshEnv.cmd only works from cmd.exe, please install the Chocolatey Profile to take advantage of refreshenv from PowerShell" echo | set /p dummy="Refreshing environment variables from registry forcmd.exe. Please wait..."
goto main
:: Set one environment variable from registry key :SetFromReg "%WinDir%\System32\Reg" QUERY "%~1" /v "%~2" > "%TEMP%\_envset.tmp" 2>NUL for /f "usebackq skip=2 tokens=2,*" %%AIN ("%TEMP%\_envset.tmp") do ( echo/set "%~3=%%B" ) goto :EOF
:: Get a list of environment variables from registry :GetRegEnv "%WinDir%\System32\Reg" QUERY "%~1" > "%TEMP%\_envget.tmp" for /f "usebackq skip=2" %%AIN ("%TEMP%\_envget.tmp") do ( if /I not "%%~A"=="Path" ( call :SetFromReg "%~1" "%%~A" "%%~A" ) ) goto :EOF
:: Special handling forPATH - mix both User and System call :SetFromReg "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" Path Path_HKLM >> "%TEMP%\_env.cmd" call :SetFromReg "HKCU\Environment" Path Path_HKCU >> "%TEMP%\_env.cmd"