Win32_NetworkAdapterConfiguration
1 strComputer = "."
2 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
3
4 ' Set colNetAdapters = objWMIService.ExecQuery (_
5 ' "Select * from Win32_NetworkAdapterConfiguration Where Index=8")
6 ' Index=8,导致硬件更换后网卡序列号不对。
7 Set colNetAdapters = objWMIService.ExecQuery (_
8 "Select * from Win32_NetworkAdapterConfiguration where IPEnabled=True")
9
10 strIPAddress = Array("192.168.188.109")
11 strSubnetMask = Array("255.255.255.0")
12 strGateway = Array("192.168.188.100")
13 strGatewayMetric = Array(1)
14 ' If colNetAdapters Is Nothing Then
15 ' MsgBox "不能创建colNetAdapters对象。"
16 ' End If
17
18 For Each objNetAdapter in colNetAdapters
19 ' WScript.Echo objNetAdapter.Caption 'Atheros AR8131 PCI-E Gigabit Ethernet Controller
20 '修改指定网卡的IP
21 If Left(objNetAdapter.Description,Len("Atheros AR8131"))="Atheros AR8131" Then
22 errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
23 errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
24 End If
25 Next
26
27 ' 参考资料:
28 ' http://social.msdn.microsoft.com/Forums/zh-CN/windowssdk/thread/466fa3b8-9179-4244-9b83-5f8ffc6825bc
29 ' http://topic.csdn.net/u/20100720/17/08148f61-926a-4a94-8ebd-3edcde9a5c0a.html
2 Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
3
4 ' Set colNetAdapters = objWMIService.ExecQuery (_
5 ' "Select * from Win32_NetworkAdapterConfiguration Where Index=8")
6 ' Index=8,导致硬件更换后网卡序列号不对。
7 Set colNetAdapters = objWMIService.ExecQuery (_
8 "Select * from Win32_NetworkAdapterConfiguration where IPEnabled=True")
9
10 strIPAddress = Array("192.168.188.109")
11 strSubnetMask = Array("255.255.255.0")
12 strGateway = Array("192.168.188.100")
13 strGatewayMetric = Array(1)
14 ' If colNetAdapters Is Nothing Then
15 ' MsgBox "不能创建colNetAdapters对象。"
16 ' End If
17
18 For Each objNetAdapter in colNetAdapters
19 ' WScript.Echo objNetAdapter.Caption 'Atheros AR8131 PCI-E Gigabit Ethernet Controller
20 '修改指定网卡的IP
21 If Left(objNetAdapter.Description,Len("Atheros AR8131"))="Atheros AR8131" Then
22 errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
23 errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
24 End If
25 Next
26
27 ' 参考资料:
28 ' http://social.msdn.microsoft.com/Forums/zh-CN/windowssdk/thread/466fa3b8-9179-4244-9b83-5f8ffc6825bc
29 ' http://topic.csdn.net/u/20100720/17/08148f61-926a-4a94-8ebd-3edcde9a5c0a.html