最近给一个中学装我们公司的软件,但是发现他的电脑一重启IP地址就自动改回来了,真是郁闷,找了半天也没有发现什么还原的软件,而我又不想给他重装电脑(我这个人比较懒的,呵呵),所以我就想有没有什么小程序能在电脑重启的时候自动的改下IP,到网上小搜了下,果然有,还是VBS的,下来看了下,代码也很简单,主要是用了WMI,这里和大家共享下:
| strIPAddress = Array("10.55.152.131") | | strSubnetMask = Array("255.255.255.0") | | strGateway = Array("10.55.152.1") | | arrDNSServers = Array("10.55.0.13", "221.12.1.228") | | strComputer = "." | | Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") | | Set colNetAdapters = objWMIService.ExecQuery _ | | ("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE") | | For Each objNetAdapter in colNetAdapters | | sip=objNetAdapter.IPAddress | | | | strGatewayMetric = Array(1) | | 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 | | exit for | | NextCOPY |
http://hangzhou492.blog.51cto.com/67690/38698 |