1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| @echo off setlocal
rem 要添加到用户变量的路径 set "new_path1=%cd%\nodejs"
rem 获取当前用户的已有变量值 for /f "tokens=2*" %%A in ('reg query "HKCU\Environment" /v "Path" ^| find /i "Path"') do set "existing_path=%%B"
rem 检查用户变量中是否已经包含了新路径 echo %existing_path% | find /i "%new_path1%" > nul if %errorlevel% equ 1 ( rem 用户变量中不存在新路径,将其添加到用户变量 setx Path "%existing_path%;%new_path1%" > nul echo New path added to user environment variable. ) else ( echo Path already exists in user environment variable. )
rem 要添加到用户变量的路径 set "new_path2=%cd%\Git\cmd"
rem 获取当前用户的已有变量值 for /f "tokens=2*" %%A in ('reg query "HKCU\Environment" /v "Path" ^| find /i "Path"') do set "existing_path=%%B"
rem 检查用户变量中是否已经包含了新路径 echo %existing_path% | find /i "%new_path2%" > nul if %errorlevel% equ 1 ( rem 用户变量中不存在新路径,将其添加到用户变量 setx Path "%existing_path%;%new_path2%" > nul echo New path added to user environment variable. ) else ( echo Path already exists in user environment variable. )
pause
endlocal
|