已解决:问题是分割的行与_转到下一行。决定使用Set colNetAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
全部修复!
任何想法为什么?它看起来很好!
Set objShell = WScript.CreateObject("Wscript.Shell")
Set objWMIService = GetObject("winmgmts:\\localhost\root\cimv2")
Set colNetAdapters = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=TRUE")
strIPAddress = Array("192.168.5.2")
strSubnetMask = Array("255.255.255.0")
strGateway = Array("192.168.5.1")
strGatewayMetric = Array(1)
objShell.Run "netsh interface ip add dns * 209.11.240.36"
objShell.Run "netsh interface ip add dns * 8.8.8.8 index=2"
For Each objNetAdapter in colNetAdapters
errEnable = objNetAdapter.EnableStatic(strIPAddress, strSubnetMask)
errGateways = objNetAdapter.SetGateways(strGateway, strGatewaymetric)
Next