如何利用 wmi 修改多网卡的 IP?
在论坛找了一段代码,$strComputer = "localhost"
$sDescription = "网卡名称"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\cimv2")
$colNetAdapters = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE Description = '" & $sDescription & "'", "WQL", 0x10 + 0x20)
If IsObj($colNetAdapters) Then
For $objNetAdapter In $colNetAdapters
If BitAND($Return, 1) = 0 And BitAND($Return, 2) = 0 Then $objNetAdapter.EnableStatic($LocalIPAddress, $strSubnetMask)
If BitAND($Return, 4) = 0 Then $objNetAdapter.SetGateways($strGateway, $strGatewayMetric)
Next
EndIf
但由于代码不完整,其中有些参数如 $Return 不知道是什么意思,也不知如何使用
请帮忙修改完整
[ 本帖最后由 新手上路 于 2008-12-13 21:21 编辑 ] 顶上去! . 论坛上的代码很多,我没有一个运行正确的。 代码不完整没有办法修改呀! 一会有时间我发上来。。。测试成功的。 三恨老大还没发上来啊? 三恨睡觉去了:face (6): :face (6): 顶到三恨醒来!
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE", "WQL", _
0x10+0x20)
For $objNetAdapter in $colItems
$objNetAdapter.EnableStatic($SetIPAddress,$SetSubnetmask)
$objNetAdapter.SetGateways($SetGateway)
$objNetAdapter.SetDNSServerSearchOrder($SetDns)
Next
感谢三恨!试过了再改为【已解决】
不过 DNS 一般有 首选DNS 和 备用DNS 两项,不知道 $SetDns 这个参数 是否支持 61.128.128.68,61.128.128.98
这样的值?(首选和备选之间用逗号 , 隔开)
[ 本帖最后由 新手上路 于 2008-11-13 22:25 编辑 ] E:\20081120\网卡名称.au3(10,46) : WARNING: $SetIPAddress: possibly used before declaration.
$objNetAdapter.EnableStatic($SetIPAddress,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\20081120\网卡名称.au3(10,61) : WARNING: $SetSubnetmask: possibly used before declaration.
$objNetAdapter.EnableStatic($SetIPAddress,$SetSubnetmask)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\20081120\网卡名称.au3(11,43) : WARNING: $SetGateway: possibly used before declaration.
$objNetAdapter.SetGateways($SetGateway)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\20081120\网卡名称.au3(12,51) : WARNING: $SetDns: possibly used before declaration.
$objNetAdapter.SetDNSServerSearchOrder($SetDns)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\20081120\网卡名称.au3(10,46) : ERROR: $SetIPAddress: undeclared global variable.
$objNetAdapter.EnableStatic($SetIPAddress,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
E:\20081120\网卡名称.au3 - 1 error(s), 4 warning(s)
代码不全呀? C:\Documents and Settings\Administrator\桌面\1.au3(2,11) : WARNING: $objWMIService: possibly used before declaration.
0x10+0x20)
~~~~~~~~~~^
C:\Documents and Settings\Administrator\桌面\1.au3(6,46) : WARNING: $SetIPAddress: possibly used before declaration.
$objNetAdapter.EnableStatic($SetIPAddress,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Administrator\桌面\1.au3(6,61) : WARNING: $SetSubnetmask: possibly used before declaration.
$objNetAdapter.EnableStatic($SetIPAddress,$SetSubnetmask)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Administrator\桌面\1.au3(7,43) : WARNING: $SetGateway: possibly used before declaration.
$objNetAdapter.SetGateways($SetGateway)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Administrator\桌面\1.au3(8,51) : WARNING: $SetDns: possibly used before declaration.
$objNetAdapter.SetDNSServerSearchOrder($SetDns)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Administrator\桌面\1.au3(2,11) : ERROR: $objWMIService: undeclared global variable.
0x10+0x20)
~~~~~~~~~~^
C:\Documents and Settings\Administrator\桌面\1.au3 - 1 error(s), 5 warning(s)
同样的错误 学习学习中,,, 学习一下。。
页:
[1]