批处理、VBS实现自动设置IP、默认网关、DNS、WINS、IE代理(全)
作者 佚名
来源 批处理
浏览
发布时间 2013-07-09
用这种方法就不用建立多个批处理文件,用一个文件做多件事,何乐而不为呢! 六、最后介绍一下如何使用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.*.*.*;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,都可以实现我们想要的功能。总的来说,还是根据自己的特定要求来选择!再执行命令时,要注意权限的问题! |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于批处理、VBS实现自动设置IP、默认网关、DNS、WINS、IE代理(全)的所有评论