您的位置:首页 > 编程语言 > VB

批处理、VBS实现自动设置IP、默认网关、DNS、WINS、IE代理!(二)

2010-04-14 14:47 661 查看
四、自动设置IE代理
美国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 "192.168.0.2:8888" /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"="192.168.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=192.168.100.86 mask=255.255.255.0
echo 正在设置美国网关,请稍等……
netsh interface ip set address name="本地连接" gateway=192.168.0.253 gwmetric=1
echo 正在设置美国主DNS ,请稍等……
netsh interface ip set dns name="本地连接" source=static addr=192.168.0.1 register=PRIMARY
echo 正在设置美国备用DNS ,请稍等……
netsh interface ip add dns name="本地连接" addr=192.168.1.2 index=2
echo 正在设置美国主WINS ,请稍等……
netsh interface ip set wins name="本地连接" source=static addr=192.168.0.1
echo 正在设置美国备用WINS ,请稍等……
netsh interface ip add wins name="本地连接" addr=192.168.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"="192.168.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=192.168.100.86 mask=255.255.255.0
echo 正在设置日本网关,请稍等……
netsh interface ip set address name="本地连接" gateway=192.168.0.253 gwmetric=1
echo 正在设置日本主DNS ,请稍等……
netsh interface ip set dns name="本地连接" source=static addr=192.168.0.1 register=PRIMARY
echo 正在设置日本备用DNS ,请稍等……
netsh interface ip add dns name="本地连接" addr=192.168.1.2 index=2
echo 正在设置日本主WINS ,请稍等……
netsh interface ip set wins name="本地连接" source=static addr=192.168.0.1
echo 正在设置日本备用WINS ,请稍等……
netsh interface ip add wins name="本地连接" addr=192.168.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"="192.168.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("192.168.100.86")
strSubnetMask = array("255.255.255.0")
strGateway = array("192.168.0.253")
strGatewayMetric = array("1")
strwinsOne = "192.168.0.1"
strwinsTwo = "192.168.1.2"
strdnsOne = "192.168.0.1"
strdnsTwo = "192.168.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 = "192.168.0.2:8888;192.168.0.2:8888"
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.*.*.*;192.168.*.*;<local>"
objReg.SetStringValue HKEY_CURRENT_USER, strKeyPath, strEntryName,dwValue
If Err = 0 Then
SetIEProxy = True
Else
SetIEProxy = False
End If
End Function
msgbox "ok"
至此所有的方法已经向大家介绍了一遍,不管是BAT还是VBS,都可以实现我们想要的功能。总的来说,还是根据自己的特定要求来选择!再执行命令时,要注意权限的问题!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: