众所周知,工作中需要设置一些代理才能访问特定的网络环境,每次打开windows系统的设置页面,非常麻烦,所以如果有一个脚本可以自动设置常用的代理,岂不美哉?
假设我有一个代理服务器IP+端口为:192.168.4.6:8888
注意:SET my_proxy=192.168.4.6:8888
这个代码的等号两端不能有空格。
下面介绍一段脚本保存到电脑中 文件名暂且叫openProxy.bat吧
@echo off
cls
color 0A
Echo The program is running...
Echo Setting the proxy
SET my_proxy=192.168.4.6:8888
Echo you proxy is %my_proxy%
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 "%my_proxy%" /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /d "noproxyaddress1;noproxyaddress2;<local>" /f
Echo Done.
Echo Press any key to leave...
exit
双击运行openProxy.bat ,查看效果如下

那么关闭的时候是不是还是要打开这个页面进行配置呢?其实也是可以用脚本关闭代理的,
建一个closeProxy.bat的文件,然后把代码复制粘贴到文件里保存即可
@echo off
cls
Echo The program is running...
Echo Setting the proxy...
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
Echo Done.
exit
双击closeProxy.bat运行,再来代理页面看,代理已经被关闭了。
