cmd设置环境变量
- 方法,仅本次生效
set path=%path%;【新路径】 - 方法,永久生效
setx path "%path%;【新路径】" - 方法,永久生效
wmic ENVIRONMENT create name="【变量名】",username="<system>",VariableValue="【变量值】"
附一个系统代理切换脚本
@echo off
if "%1" == "yes" set judge=true & goto yes
if "%1" == "no" set judge=true & goto no
if "%judge%" NEQ "true" goto auto
exit /b
:no
echo no proxy
set http_proxy=
set https_proxy=
wmic ENVIRONMENT where "name='http_proxy'" delete
wmic ENVIRONMENT where "name='https_proxy'" delete
exit /b
:yes
echo yes proxy
set http_proxy=http://127.0.0.1:1080
set https_proxy=http://127.0.0.1:1080
wmic ENVIRONMENT create name="http_proxy",username=%username%,VariableValue="http://127.0.0.1:1080"
wmic ENVIRONMENT create name="https_proxy",username=%username%,VariableValue="http://127.0.0.1:1080"
exit /b
:auto
wmic ENVIRONMENT where "name='http_proxy'"|findstr http_proxy
if %errorlevel%==0 (
goto :no
) else (
goto :yes
)
exit /b
使用方式:
# 自动切换
proxy
# 使用代理
proxy yes
# 不使用代理
proxy no

浙公网安备 33010602011771号