myIP = InputBox("请输入IP地址:") If myIP<>"" Then myIP = Array(myIP) myDNS = Array("192.168.0.1", "192.168.0.2") mySubMask = Array("255.255.255.0") myGateWay = Array("192.168.0.1") Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!//" & "." & "/root/cimv2") Set colNetCards= objWMIService.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") For Each objNetCard in colNetCards setIP = objNetCard.EnableStatic(myIp, mySubMask) setGW = objNetCard.SetGateways(myGateWay) setDNS = objNetCard.SetDNSServerSearchOrder(myDNS) If setIP=0 and setGW=0 and setDNS=0 Then MsgBox "IP地址设置成功!" Exit For End If Next Else Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!//" & "." & "/root/cimv2") Set colNetCards= objWMIService.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True") For Each objNetCard in colNetCards setDHCP = objNetCard.EnableDHCP() setDNS = objNetCard.SetDNSServerSearchOrder() If setDHCP =0 and setDNS=0 Then MsgBox "自动获取ip地址!" Exit For End If Next End If