1
0
HID-Tools-Collection/add_to_path.cmd

30 lines
801 B
Batchfile

@echo off
@setlocal
rem cobbled together by https://github.com/nefarius
set MYDIR=%~dp0
pushd "%MYDIR%"
rem grab current value
for /f "tokens=1,2*" %a in ('reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v path') do set currentValue=%c
SETLOCAL EnableDelayedExpansion
NET SESSION >nul 2>&1
IF %ERRORLEVEL% EQU 0 (
for /d %%d in (*.*) do (
set newValue=%MYDIR%%%d
rem concat previous and new value
set currentValue=%currentValue%;%newValue%
rem write back new value
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d "%currentValue%" /f 2>nul
echo Added !currentValue! to system PATH
)
) ELSE (
ECHO You need to run this script as Administrator
)
popd
endlocal
pause