setlocal EnableExtensions DisableDelayedExpansion
set mypath="%cd%"
setx JAVA_HOME "D:\a_soft\a_green\java\jdk\17"
setx MAVEN_HOME "D:\a_soft\a_green\java\maven"
setx ORACLE_HOME "D:\a_soft\a_green\a_lib\oracle\instantclient_19_8"
setx NLS_LANG "AMERICAN_AMERICA.AL32UTF8"
setx BOOST_INCLUDEDIR %mypath%\cmake\boost_1_55_0_vc80\boost_1_55_0_vc140
setx BOOST_LIBRARYDIR %mypath%\cmake\boost_1_55_0_vc80\boost_1_55_0_vc140\stage\lib
REM setx vs2019_v140_HOME "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.16.27023\bin\HostX64\x64\cl.exe"
rem setx vs2019_v140_HOME "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin"
setx vs2019_v142_HOME "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64"
@echo %path% >> log.txt
@echo off
REM set pathStr=%path%
REM set "vs2019_v142=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64"
REM :Loop
REM for /f "delims=; tokens=1,*" %%a in ("%pathStr%") do (
REM if "%%a"=="%vs2019_v142%" (
REM echo %mingw%已经存在于环境变量中
REM goto :eof
REM )
REM set pathStr=%%b
REM goto Loop
REM )
REM set newPath="%path%;%vs2019_v142%"
REM echo %newPath%
REM setx Path %newPath% /m
REM echo %mingw%添加到环境变量中
REM pause>NUL
set "new_path=%%JAVA_HOME%%\bin"
set "already_added=0"
for /f "tokens=2,*" %%a in ('reg query HKCU\Environment /v PATH ^| find /i "PATH"') do (
set "user_path_var=%%b"
)
if "%user_path_var:~-1%"==";" set "user_path_var=%user_path_var:~0,-1%"
echo User PATH variable: %user_path_var%
for %%i in ("%user_path_var:;=" "%") do (
if /i "%%~i"=="%new_path%" (
set "already_added=1"
)
)
if %already_added%==0 (
setx PATH "%user_path_var%;%new_path%"
echo %new_path% add ok.
) else (
echo %new_path% already exists in user PATH variable.
)
set "new_path=%%MAVEN_HOME%%\bin"
set "already_added=0"
for /f "tokens=2,*" %%a in ('reg query HKCU\Environment /v PATH ^| find /i "PATH"') do (
set "user_path_var=%%b"
)
if "%user_path_var:~-1%"==";" set "user_path_var=%user_path_var:~0,-1%"
echo User PATH variable: %user_path_var%
for %%i in ("%user_path_var:;=" "%") do (
if /i "%%~i"=="%new_path%" (
set "already_added=1"
)
)
if %already_added%==0 (
setx PATH "%user_path_var%;%new_path%"
echo %new_path% add ok.
) else (
echo %new_path% already exists in user PATH variable.
)
set "new_path=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30133\bin\Hostx64\x64"
set "already_added=0"
rem HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment
for /f "tokens=2,*" %%a in ('reg query "HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment" /v PATH ^| find /i "PATH"') do (
set "user_path_var=%%b"
echo %%b>> loga.txt
)
if "%user_path_var:~-1%"==";" set "user_path_var=%user_path_var:~0,-1%"
echo User PATH variable: %user_path_var%
for %%i in ("%user_path_var:;=" "%") do (
if /i "%%~i"=="%new_path%" (
set "already_added=1"
)
echo %%~i>> loga.txt
)
echo %already_added%
echo %user_path_var%
echo %new_path%
if %already_added%==0 (
rem setx PATH "%user_path_var%;%new_path%"
rem reg add HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment /v PATH /t REG_EXPAND_SZ /d %user_path_var%;%new_path% /f
rem reg add HKLM\System\CurrentControlSet\Control\Session Manager\Environment /v "PATH" /t REG_EXPAND_SZ /d "%new_path%" /f
reg add "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v "Path" /d "%user_path_var%;%new_path%" /t REG_EXPAND_SZ /f
rem echo %new_path% add ok.
echo add ok.
) else (
rem echo %new_path% already exists in user PATH variable.
echo already exists.
)
pause>NUL
endlocal
pause
bat添加注册表
最新推荐文章于 2024-08-28 13:52:02 发布