Set objWMIService=GetObject("winmgmts:\\.\root\cimv2")
Set colNetAdapters=objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
Set argsNamed = WScript.Arguments.Named
If argsNamed.Exists("IP") Then
arrIPAddress = Array(argsNamed.Item("IP"))
End If
If argsNamed.Exists("掩码") Then
arrSubnetMask = Array(argsNamed.Item("掩码"))
End If
If argsNamed.Exists("网关") Then
arrGateway = Array(argsNamed.Item("网关"))
End If
If argsNamed.Exists("DNS") Then
arrDNS = Split(argsNamed.Item("DNS"),",",-1,1)
End If
For Each objNetAdapter in colNetAdapters
If Isarray(arrIPAddress) And Isarray(arrSubnetMask) Then objNetAdapter.EnableStatic arrIPAddress,arrSubnetMask
If Isarray(arrGateway) Then objNetAdapter.SetGateways arrGateway
If Isarray(arrDNS) Then objNetAdapter.SetDNSServerSearchOrder arrDNS
Next
上面的代码保存为 VBS格式,比如:修改IP网关DNS.vbs
使用方法:
只修改IP:(修改IP时必须加入修改子网掩码参数,否则不能修改。)
修改IP网关DNS.vbs /IP:192.168.3.249 /掩码:255.255.252.0
只修改网关:
修改IP网关DNS.vbs /网关:192.168.0.1
只修改DNS:
修改IP网关DNS.vbs /DNS:192.168.0.1,202.96.168.86,202.96.168.166
同时修改IP、网关:
修改IP网关DNS.vbs /IP:192.168.3.249 /掩码:255.255.252.0 /网关:192.168.0.1
同时修改IP、DNS:
修改IP网关DNS.vbs /IP:192.168.3.249 /掩码:255.255.252.0 /DNS:192.168.0.1,202.96.168.86,202.96.168.166
同时修改网关、DNS:
修改IP网关DNS.vbs /网关:192.168.0.1 /DNS:192.168.0.1,202.96.168.86,202.96.168.166
同时修改IP、网关、DNS:
修改IP网关DNS.vbs /IP:192.168.3.249 /掩码:255.255.252.0 /网关:192.168.0.1 /DNS:192.168.0.1,202.96.168.86,202.96.168.166
批处理调用:
call \\server\bat$\修改IP网关DNS.vbs /各种参数 |