Обновление PATH пользователя из командной строки

Добавление в переменную PATH строки c:\Tools\Git64\bin

setlocal ENABLEEXTENSIONS
set KEY_NAME="HKEY_CURRENT_USER\Environment"
set VALUE_NAME="PATH"

FOR /F "usebackq skip=2 tokens=1,2*" %%A IN (`REG QUERY %KEY_NAME% /v %VALUE_NAME% 2^>nul`) DO (
    set ValueName=%%A
    set ValueType=%%B
    set User_Path=%%C
)

if defined ValueName (
    @echo User_Path = %User_Path%
) else (
    @echo %KEY_NAME%\%VALUE_NAME% not found.
)

If NOT "%User_Path%"=="%User_Path:Git=%" (
    echo Already added
) else (
    echo Adding
    setx PATH "%User_Path%;c:\Tools\Git64\bin"
)

echo %PATH%

Posted in Git on Sep 03, 2015