示例代码:
strComputer = "."
Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where MACAddress='00:24:8c:xx:xx:xx'")
strIPAddress = Array("192.168.17.14")
strSubnetMask = Array("255.255.255.192")
strGateway = Array("192.168.17.254")
strGatewayMetric = Array(1)
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
If errEnable = 0 Then
IPChan=1
Else
IPChan=0
End If
Exit For
Next
If IPChan = 1 Then
WScript.Echo "The IP address has been changed