新手上路 发表于 2008-11-11 23:14:22

如何利用 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 编辑 ]

新手上路 发表于 2008-11-12 11:00:10

顶上去!                           .

redapple2008 发表于 2008-11-12 11:17:42

论坛上的代码很多,我没有一个运行正确的。

redapple2008 发表于 2008-11-12 11:22:18

代码不完整没有办法修改呀!

sanhen 发表于 2008-11-12 11:50:16

一会有时间我发上来。。。测试成功的。

新手上路 发表于 2008-11-12 18:03:55

三恨老大还没发上来啊?

redapple2008 发表于 2008-11-13 09:14:18

三恨睡觉去了:face (6): :face (6):

新手上路 发表于 2008-11-13 21:28:17

顶到三恨醒来!

sanhen 发表于 2008-11-13 22:04:51



$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

新手上路 发表于 2008-11-13 22:21:23

感谢三恨!试过了再改为【已解决】

不过 DNS 一般有 首选DNS 和 备用DNS 两项,不知道 $SetDns 这个参数 是否支持 61.128.128.68,61.128.128.98
这样的值?(首选和备选之间用逗号 , 隔开)

[ 本帖最后由 新手上路 于 2008-11-13 22:25 编辑 ]

redapple2008 发表于 2008-11-14 09:07:06

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)


代码不全呀?

zhao08681 发表于 2009-4-25 16:41:46

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)


同样的错误

songtao 发表于 2009-8-6 00:44:52

学习学习中,,,

menfan1 发表于 2009-8-6 12:40:37

学习一下。。
页: [1]
查看完整版本: 如何利用 wmi 修改多网卡的 IP?