From a87f3c076487e9dc47b3633f1996be817649827b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20H=C3=B6glinger-Stelzer?= Date: Tue, 6 Jun 2023 15:18:33 +0200 Subject: [PATCH] More fixes --- add_to_path.cmd | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/add_to_path.cmd b/add_to_path.cmd index d905f01..e976360 100644 --- a/add_to_path.cmd +++ b/add_to_path.cmd @@ -5,18 +5,20 @@ 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 ( - 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 + set newValue=%MYDIR%%%d rem concat previous and new value - set value=%currentValue%;%MYDIR%%%d + 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 "%value%" /f 2>nul - echo Added !value! to system PATH + 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