脚本宝典收集整理的这篇文章主要介绍了用VBS设置静态IP和DNS服务器地址的代码,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
核心代码一:
strIPAddress = Array("192.168.0.148") strSubnetmask = Array("255.255.255.0") strGateway = Array("192.168.0.1") strGatewayMetric = Array(1) arrDNSServers = Array("192.168.0.1","192.168.0.2") strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{imPErsonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colNetAdapters = objWMIService.ExecQuery _ ("Select * From Win32_NetworkAdapterconfiguration where IPEnabled=TRUE") For each objNetAdapter in colNetAdapters errEnable = objNetAdapter.Enablestatic(strIPAddress, strSubnetMask) errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) errDNS = objNetAdapter.SetDNSServerSeArchOrder(arrDNSServers) If errEnable = 0 Then WScript.Echo "The IP address has been changed." Else WScript.Echo "The IP address could not be changed." End If Next
记得把参数改成自己想要的。
代码二:
将计算机的 IP 地址设置为 192.168.1.111,并将 IP 网关设置为 192.168.1.1。
strComputer = "." Set objWMIService = GetObject("winmgmts:\" & strComputer & " ootcimv2") Set colNetAdapters = objWMIService.ExecQuery _ ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") strIPAddress = Array("192.168.1.111") strSubnetMask = Array("255.255.255.0") strGateway = Array("192.168.1.1") strGatewayMetric = Array(1) For Each objNetAdapter in colNetAdapters errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask) errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric) If errEnable = 0 Then WScript.Echo "The IP address has been changed." Else WScript.Echo "The IP address could not be changed." End If Next
原文:http://demon.tw/programming/vbs-modify-ip-dns-setting.html
以上是脚本宝典为你收集整理的用VBS设置静态IP和DNS服务器地址的代码全部内容,希望文章能够帮你解决用VBS设置静态IP和DNS服务器地址的代码所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。