一、IE代理.bat
@echo off
title 自动设置代理服务器
echo 自动设置代理服务器
rem echo 正在清空代理服务器设置……
rem reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyEnable /t REG_DWORD /d 0 /f
rem reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyServer /d "" /f
rem reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d 0 /f
rem echo 代理服务器设置已经清空
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 "10.15.0.2:3128" /f
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Internet Settings" /v ProxyOverride /t REG_SZ /d "10.*.*.*;192.168.*.*;<local>" /f
或者用下面的方法:
cls
color 1f
@echo 清空代理设置
@echo Windows Registry Editor Version 5.00>>1.reg
@echo [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]>>1.reg
@echo "ProxyEnable"=dword:00000000>>1.reg
@echo "ProxyServer"="">>1.reg
@echo "ProxyOverride"="">>1.reg
regedit /s 1.reg
del 1.reg
@echo 设置代理
@echo Windows Registry Editor Version 5.00>>1.reg
@echo [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]>>1.reg
@echo "ProxyEnable"=dword:00000001>>1.reg
@echo "ProxyServer"="10.15.0.2:8080">>1.reg
@echo "ProxyOverride"="10.*.*.*;192.168.*.*;<local>">>1.reg
regedit /s 1.reg
del 1.reg
二、以上配合结合,放在一个文件里,可以这样写:
网络综合配置.bat
@echo off
color 1f
title "网卡&IE代理设置批处理"
echo 实现功能包括切换大连和沈阳网络配置,设置IE代理.
goto 51job
:51job
echo.
echo 请选择: 1:大连,2:沈阳,3:ADSL
set /p choice=请输入相应数字后回车:
if /i "%choice%" == "1" goto dlnet
if /i "%choice%" == "2" goto synet
if /i "%choice%" == "3" goto adsl
goto 51job
:adsl
cls
color 1f
netsh interface ip set address name="本地连接" source=dhcp
netsh interface ip set dns name="本地连接" source=dhcp
cls
goto noproxy
:noproxy
@echo Windows Registry Editor Version 5.00>>1.reg
@echo [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]>>1.reg
@echo "ProxyEnable"=dword:00000000>>1.reg
@echo "ProxyServer"="">>1.reg
@echo "ProxyOverride"="">>1.reg
regedit /s 1.reg
del 1.reg
goto exit
:dlnet
cls
color 1f
echo.
set /p choice=输入" N "后回车跳过网卡设置, 直接回车继续网卡设置:
if /i "%choice%" == "N" goto proxy
cls
echo 开始设置大连网络地址!
echo 正在设置大连IP ,请稍等……
netsh interface ip set address name="本地连接" source=static addr=10.15.100.86 mask=255.255.0.0
echo 正在设置大连网关,请稍等……
netsh interface ip set address name="本地连接" gateway=10.15.0.253 gwmetric=1
echo 正在设置大连主DNS ,请稍等……
netsh interface ip set dns name="本地连接" source=static addr=10.15.0.1 register=PRIMARY
echo 正在设置大连备用DNS ,请稍等……
netsh interface ip add dns name="本地连接" addr=10.100.1.2 index=2
echo 正在设置大连主WINS ,请稍等……
netsh interface ip set wins name="本地连接" source=static addr=10.15.0.1
echo 正在设置大连备用WINS ,请稍等……
netsh interface ip add wins name="本地连接" addr=10.100.1.2 index=2
echo 设置完成!
echo 正在刷新设置……
ipconfig /flushdns
echo 显示新的设置:
ipconfig /all
goto dlproxy
:dlproxy
cls
color 1f
@echo Windows Registry Editor Version 5.00>>1.reg
@echo [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]>>1.reg
@echo "ProxyEnable"=dword:00000001>>1.reg
@echo "ProxyServer"="10.15.0.2:8080">>1.reg
@echo "ProxyOverride"="10.*.*.*;192.168.*.*;<local>">>1.reg
regedit /s 1.reg
del 1.reg
echo 正在关闭浏览器:
taskkill /f /t /im IEXPLORE.exe
echo 正在开启浏览器
"C:\Program Files\Internet Explorer\IEXPLORE.EXE"
goto exit
:synet
cls
color 1f
echo.
set /p choice=输入" N "后回车跳过网卡设置, 直接回车继续网卡设置:
if /i "%choice%" == "N" goto proxy
cls
echo 开始设置沈阳网络地址!
echo 正在设置沈阳IP ,请稍等……
netsh interface ip set address name="本地连接" source=static addr=10.16.100.86 mask=255.255.0.0
echo 正在设置沈阳网关,请稍等……
netsh interface ip set address name="本地连接" gateway=10.16.0.253 gwmetric=1
echo 正在设置沈阳主DNS ,请稍等……
netsh interface ip set dns name="本地连接" source=static addr=10.16.0.1 register=PRIMARY
echo 正在设置沈阳备用DNS ,请稍等……
netsh interface ip add dns name="本地连接" addr=10.100.1.2 index=2
echo 正在设置沈阳主WINS ,请稍等……
netsh interface ip set wins name="本地连接" source=static addr=10.16.0.1
echo 正在设置沈阳备用WINS ,请稍等……
netsh interface ip add wins name="本地连接" addr=10.100.1.2 index=2
echo 设置完成!
goto syproxy
:syproxy
cls
color 1f
@echo Windows Registry Editor Version 5.00>>1.reg
@echo [HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings]>>1.reg
@echo "ProxyEnable"=dword:00000001>>1.reg
@echo "ProxyServer"="10.16.0.2:8080">>1.reg
@echo "ProxyOverride"="10.*.*.*;192.168.*.*;<local>">>1.reg
regedit /s 1.reg
del 1.reg
echo 正在关闭浏览器:
taskkill /f /t /im IEXPLORE.exe
echo 正在开启浏览器
"C:\Program Files\Internet Explorer\IEXPLORE.EXE"
goto exit
:exit
cls
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo 已完成所有设置.
echo.
echo
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
pause
exit
用这种方法就不用建立多个批处理文件,用一个文件做多件事,何乐而不为呢!
三、最后介绍一下如何使用VBS脚本来实现
大连网络配置.vbs
on error resume next
strIPAddress = array("10.15.100.86")
strSubnetMask = array("255.255.0.0")
strGateway = array("10.15.0.253")
strGatewayMetric = array("1")
strwinsOne = "10.15.0.1"
strwinsTwo = "10.100.1.2"
strdnsOne = "10.15.0.1"
strdnsTwo = "10.100.1.2"
strComputer = "."
Set objShell = CreateObject("Wscript.shell")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colNetCards = objWMIService.ExecQuery _
("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
wscript.echo "正在进行大连网络配置"
For Each objNetCard in colNetCards
errEnable = objNetCard.EnableStatic(strIPAddress,strSubnetMask)
errGateways = objNetCard.SetGateways(strGateway,strGatewayMetric)
arrDNSServers = Array(strdnsone, strdnstwo)
objNetCard.SetDNSServerSearchOrder(arrDNSServers)
SetWins = objNetCard.SetWINSServer(strwinsOne,strwinsTwo)
Next
wscript.echo "大连网络配置完成!"
IE代理配置.vbs
strMachines = "10.15.0.2:3128;10.16.0.2:3128"
aMachines = split(strMachines, ";")
For Each machine2 in aMachines
machinearr = split(machine2, ":")
machine = machinearr(0)
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("select * from Win32_PingStatus where address = '"_
& machine & "'")
For Each objStatus in objPing
If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
WScript.Echo(machine2 & " is not reachable")
else
WScript.Echo(machine2 & " is OK")
if confirm("设置代理为"& machine2 &"?") then
msgbox SetIEProxy(1,machine2)
end if
End If
Next
Next
function confirm(s)
confirm = (msgbox(s,vbYesNo,s) = 6)
end function
Function SetIEProxy(ProxyEnable,ProxyIP)
On Error Resume Next
Const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set objReg = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}\\" & strComputer & _
"\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\"
strEntryName = "ProxyEnable"
dwvalue = ProxyEnable
objReg.SetDWORDValue HKEY_CURRENT_USER, strKeyPath, strEntryName,dwValue
strEntryName = "ProxyServer"
dwvalue = ProxyIP
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strEntryName,dwValue
strEntryName = "ProxyOverride"
dwvalue = "10.*.*.*;10.10.*.*;<local>"
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strEntryName,dwValue
If Err = 0 Then
SetIEProxy = True
Else
SetIEProxy = False
End If
End Function
msgbox "ok"
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。