工作心得体会

使用批量指令cmd创建bat修改windows的http代理

2020-09-22  本文已影响0人  魔王大柚子

如标题,直接上代码:

@echo off
echo 参数说明:q 是离开; o (欧) 是使用上一次的代理数据,输入处没有显示:即没有历史数据; c 是清空代理; ip:port 按照此格式可以设置代理


if not exist %temp%\myproxy (
md %temp%\myproxy
)
if not exist %temp%\myproxy\r.txt (
set /p flag="please enter c/ip:port/q->"
)^
else (
set /p flag="please enter c/ip:port/q/o->"
)

if /i %flag% == c (
echo 正在清空代理服务器设置……
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "" /f
echo 代理服务器设置已经清空
)^
else (
if /i %flag% == q (
echo 关闭
)^
else (
if /i %flag% == o (
if not exist %temp%\myproxy\r.txt (
echo 没有历史记录
pause
)^
else (
set /p firstRow=<"%temp%\myproxy\r.txt"
echo 正在设置代理服务器……
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "%firstRow%" /f
echo 设置完毕
)
)^
else (
echo %flag% > %temp%\myproxy\r.txt
echo 正在设置代理服务器……
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 1 /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "%flag%" /f
echo 设置完毕
)

)

)

更新:
发现设置后,没有实时更新,还是需要打开系统的配置页面才能刷新,研究发现还需要考虑:
HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections
正在理解中。。。

上一篇下一篇

猜你喜欢

热点阅读