找回密码
 加入
搜索
查看: 1701|回复: 1

求助au3获取网卡名称,并给出变量

  [复制链接]
发表于 2009-9-7 08:44:14 | 显示全部楼层 |阅读模式
本帖最后由 fjvip 于 2009-9-7 11:14 编辑

下面一段代码是修改IP地址的,可是很遗憾的是,不够人性化,经常有时候因为摄像头驱动的影响,本地连接,经常名称是“本地连接 2”这样的名称,而下面,是针对“本地连接”修改IP的。所以不够灵活。希望高手能使用AU3获取网卡名称,传给一个变量值。

;修改IP
        GUICtrlSetData($Edit4_1, "2、修改IP地址为: " & $sdip & @CRLF, "1")
        Sleep(500)
        GUICtrlSetData($Edit4_1, "3、修改子网掩码为: " & $mask & @CRLF, "1")
        Sleep(500)
        GUICtrlSetData($Edit4_1, "4、修改网关为: " & $gateway & @CRLF, "1")
        RunWait('netsh interface ip set address name = "本地连接"  source = static addr = ' & $sdip & ' mask = ' & $mask & ' gateway = ' & $gateway & ' gwmetric = 0', "c:\windows\system32", @SW_HIDE)
        GUICtrlSetData($Edit4_1, "5、修改DNS1为: " & $Dns[1] & @CRLF, "1")
        RunWait('netsh interface ip set dns name = "本地连接"  source = static addr = ' & $Dns[1] & ' register = PRIMARY', "c:\windows\system32", @SW_HIDE)
        GUICtrlSetData($Edit4_1, "6、修改DNS2为: " & $Dns[2] & @CRLF, "1")
        RunWait('netsh interface ip add dns name = "本地连接"  addr = ' & $Dns[2] & ' index=2', "c:\windows\system32", @SW_HIDE)

解决方法如下:(在这里感谢提供方法的朋友。谢谢。)

;获取网卡名称
        Dim $objwmiservice = ObjGet('winmgmts:\\localhost\root\CIMV2'), $netn
        $colitems = $objwmiservice.ExecQuery('SELECT * FROM Win32_NetworkAdapter', 'WQL', 0x10 + 0x20)
        If IsObj($colitems) Then
                For $objitem In $colitems
                        If $objitem.netconnectionid <> '' Then
                                $netn = $objitem.netconnectionid
                        EndIf
                Next
        EndIf
        ;修改IP
        GUICtrlSetData($Edit4_1, "2、修改IP地址为: " & $sdip & @CRLF, "1")
        Sleep(500)
        GUICtrlSetData($Edit4_1, "3、修改子网掩码为: " & $mask & @CRLF, "1")
        Sleep(500)
        GUICtrlSetData($Edit4_1, "4、修改网关为: " & $gateway & @CRLF, "1")
        RunWait('netsh interface ip set address name = ' & $netn & '   source = static addr = ' & $sdip & ' mask = ' & $mask & ' gateway = ' & $gateway & ' gwmetric = 0', "c:\windows\system32", @SW_HIDE)
        GUICtrlSetData($Edit4_1, "5、修改DNS1为: " & $Dns[1] & @CRLF, "1")
        RunWait('netsh interface ip set dns name = ' & $netn & '  source = static addr = ' & $Dns[1] & ' register = PRIMARY', "c:\windows\system32", @SW_HIDE)
        GUICtrlSetData($Edit4_1, "6、修改DNS2为: " & $Dns[2] & @CRLF, "1")
        RunWait('netsh interface ip add dns name = ' & $netn & '  addr = ' & $Dns[2] & ' index=2', "c:\windows\system32", @SW_HIDE)
 楼主| 发表于 2009-9-7 08:46:41 | 显示全部楼层
以下是我使用批处理的解决方案
@echo off
FOR /F "tokens=2*" %%i IN ('ipconfig/all^|find /i "Ethernet adapter "') DO set name=%%j
FOR /F "tokens=1* delims=:" %%i in ("%name%") do set 网卡名称=%%i
netsh -c interface ip set address name="%网卡名称%" source=static addr=172.31.153.201 mask=255.255.0.0
netsh -c interface ip set address name="%网卡名称%" gateway=172.31.153.1 gwmetric=0
netsh -c interface ip add dns name="%网卡名称%" addr=218.85.157.99 index=1
netsh -c interface ip add dns name="%网卡名称%" addr=218.85.152.99 index=2

请高手帮忙使用AU3获取网卡名称变量。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-5-5 05:28 , Processed in 0.067280 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表