nul(goto PATH_EXI。配置环境变量|配置环境变量 wmic。" />
- 首页 > it技术 > >
配置环境变量|配置环境变量 wmic
- @echo off
- ::设定环境变量
- set "add_path1=D:\Oracle\product\10.2.0\db_1\bin"
- set "env_path1=ORACLE_HOME"
- ::检查PATH中是否已添加
- wmic ENVIRONMENT where "name='PATH'" get VariableValue|findstr /i /c:"%add_path1%">nul&&(goto PATH_EXIST)
- echo PATH环境变量中未添加: %add_path1%
- echo.
- echo 添加环境变量
- echo.
- set "set_val=%add_path1%;
%PATH%"
- wmic ENVIRONMENT where "name='PATH' and username=''" set VariableValue="https://www.it610.com/article/%set_val%"
- :PATH_EXIST
- echo PATH环境变量中已添加: %add_path1%
- echo.
- ::检查是否已创建环境变量
- wmic ENVIRONMENT where "name='%env_path1%'" get VariableValue|findstr /i /c:"VariableValue">nul&&(goto ENV_CREATE)
- echo %env_path1%环境变量未创建
- echo.
- echo 创建环境变量
- echo.
- wmic ENVIRONMENT create name="%env_path1%",username="",VariableValue="https://www.it610.com/article/%add_path1%"
- :ENV_CREATE
- echo %env_path1%环境变量已创建
- echo.
- echo 配置完成,按任意键还原环境变量
- echo.
- pause>nul
- echo 还原环境变量
- echo.
- set set_val=
- :loop_findpath
- set /a n+=1
- for /f "tokens=%n% delims=;
" %%a in ('wmic ENVIRONMENT where "name='PATH'" get VariableValue^|findstr /i /c:"%add_path1%"') do (
- if "%%a" neq "" (
- if "%%a" neq "%add_path1%" (
- if "%set_val%" == "" (
- set "set_val=%%a"
- ) else (
- set "set_val=%set_val%;
%%a"
- )
- )
- goto loop_findpath
- )
- )
- wmic ENVIRONMENT where "name='PATH' and username=''" set VariableValue="https://www.it610.com/article/%set_val%"
- echo 删除环境变量
- echo.
- wmic ENVIRONMENT where "name='%env_path1%'" delete
- echo 环境变量已还原
- echo.
- pause>nul
推荐阅读