bat批处理脚本实现proxy服务器设置
由于使用代理服务,需要较频繁地设置代理服务器。平常的做法是到Internet选项中手动选择,但是时间久了还是觉得麻烦。
于是想到了以下方法:
1.编写reg文件
在对话框中修改的参数最后还是对应到注册表的参数值,直接编写reg文件也能修改相应的值
1 REGEDIT4 2 [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings] 3 "ProxyEnable"=dword:00000001 4 "ProxyServer"="1.0.0.1:8080"
第1句表明是调用regedit工具。
第2句是注册表位置。
ProxyEnable意思即是是否启用代理服务器,dword:00000001表示开启,dword:00000000表示失效
ProxyServer是代理服务器的地址和端口
关闭代理的reg文件编写类似。
保存为.reg文件后运行有以下效果:
2.编写bat文件
每次设置都要点击确认窗口还是会觉得麻烦,于是使用bat批处理实现reg功能
1 @echo off 2 echo Proxy Enable 3 reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "ProxyEnable" /t REG_DWORD /d 00000001 /f 4 reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "ProxyServer" /t REG_SZ /d "1.0.0.1:8080" /f 5 echo Done 6 pause>nul
1 @echo off 2 echo Proxy Disable 3 reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "ProxyEnable" /t REG_DWORD /d 00000000 /f 4 echo Done 5 pause>nul
但是如果每次开始/关闭都要用到两个不同文件还是不够简便,现在还需要的是写到同一个bat文件中,使用set /p读取用户输入,判断语句if和跳转语句goto组合进行功能选择
1 @echo off 2 3 set /p switch=Enable/Disable(1/2): 4 if %switch% equ 1 goto enable 5 if %switch% equ 2 goto disable 6 echo Invalid Parameter! 7 goto done 8 9 :enable 10 echo Proxy Enable 11 reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "ProxyEnable" /t REG_DWORD /d 00000001 /f 12 reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "ProxyServer" /t REG_SZ /d "1.0.0.1:8080" /f 13 goto done 14 15 :disable 16 echo Proxy Disable 17 reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v "ProxyEnable" /t REG_DWORD /d 00000000 /f 18 19 :done 20 echo Done 21 pause>nul 22 exit
这样就可以很方便地使用代理服务设置啦。
注:
- “=”号左右不要留空格。
- 使用变量值时,要用“%%”把变量名包起来。
- reg add语句要写在同一行。
posted on 2013-01-26 10:33 JacobChen2012 阅读(3036) 评论(2) 编辑 收藏 举报