Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Refresh `cmd` environment from registry

This script refreshes environment variables for its parent cmd.exe process according to the values from Registry.

Written for my SuperUser post.

@echo off
:: <grawity@gmail.com>, WTFPL v2 <http://sam.zoy.org/wtfpl>
:main
set __append_path=n
:: NOTE: There should be exactly one tab after 'delims=' -- NOT spaces.
for /f "usebackq tokens=1,2,* delims= " %%a in (`reg query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment"`) do call :process "%%~a" "%%~b" "%%~c"
set __append_path=y
for /f "usebackq tokens=1,2,* delims= " %%a in (`reg query HKCU\Environment`) do call :process "%%~a" "%%~b" "%%~c"
set __append_path=
goto :eof
:process
set "__var_name=%~1"
if not "%__var_name:~0,4%"==" " goto :eof
set "__var_name=%__var_name:~4%"
if /i "%__var_name%"=="PATH" (
if "%__append_path%"=="y" (
set "%__var_name%=%PATH%;%~3"
goto :process_next
)
)
set "%__var_name%=%~3"
:process_next
set __var_name=
goto :eof
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.