bat添加注册表

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

lst0426

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值