diff --git a/add_to_path.cmd b/add_to_path.cmd index 61f15bf..d905f01 100644 --- a/add_to_path.cmd +++ b/add_to_path.cmd @@ -10,9 +10,13 @@ SETLOCAL EnableDelayedExpansion NET SESSION >nul 2>&1 IF %ERRORLEVEL% EQU 0 ( for /d %%d in (*.*) do ( - set value=%MYDIR%%%d - echo Adding !value! to system PATH - reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d "%value%" /f + 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 + rem concat previous and new value + set value=%currentValue%;%MYDIR%%%d + rem write back new value + reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v Path /t REG_EXPAND_SZ /d "%value%" /f 2>nul + echo Added !value! to system PATH ) ) ELSE ( ECHO You need to run this script as Administrator