找回密码
 加入
搜索
查看: 2604|回复: 8

请教获取本地连接的名字成为变量的方法

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

通常AU3中修改IP、子网掩码、网关、主DNS、备DNS我们都会。但是在这样的语句中,如何获取本地连接网卡的名称成为一个难题,希望高手能指点,在下列语句中,“本地连接”使用变量,将应该如何获名这个网卡名称?
RunWait(@ComSpec&" /c "&'netsh interface ip set address name="本地连接" source=static addr='&$IP&' mask='&$Mask,"",@SW_HIDE)
RunWait(@ComSpec&" /c "&'netsh interface ip set address name="本地连接" gateway='&$Gateway&' gwmetric=0',"",@SW_HIDE)
RunWait(@ComSpec&" /c "&'netsh interface ip set dns name="本地连接" source=static addr='&$pDNS&' register=PRIMARY',"",@SW_HIDE)
RunWait(@ComSpec&" /c "&'netsh interface ip add dns name="本地连接" addr='&$sDNS,"",@SW_HIDE)
RunWait(@ComSpec&" /c "&'netsh interface ip set wins name="本地连接" source=static addr=none',"",@SW_HIDE)复制代码$IP(IP地址)
$Mask(子网掩码)
$Gateway(默认网关)
$pDNS(主DNS)
$sDNS(副DNS)
请教获取本地连接的名字成为变量的方法

评分

参与人数 1金钱 +20 贡献 +10 收起 理由
kn007 + 20 + 10 问题解决,及时更改标题为《已解决》,下次 ...

查看全部评分

发表于 2009-9-7 10:12:29 | 显示全部楼层
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
                        MsgBox(0, '本地连接名:', $netn)
                EndIf
        Next
EndIf
发表于 2009-9-7 10:50:19 | 显示全部楼层
经过3个系统测试,楼上源码切实可行!
 楼主| 发表于 2009-9-7 11:12:38 | 显示全部楼层
非常感激各位的帮忙已经成功解决了。。谢谢,谢谢。。。
;获取网卡名称
        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 12:07:16 | 显示全部楼层
呵呵,学习一下。。
发表于 2009-9-7 21:49:08 | 显示全部楼层
多网卡怎么搞呀?
发表于 2009-9-8 09:32:23 | 显示全部楼层
学习了,这有点难!!!
发表于 2009-9-16 10:55:41 | 显示全部楼层
学习了,呵呵,
发表于 2012-5-16 14:16:18 | 显示全部楼层
运行出错:
Variable must be of type "Object".:
$colitems = $objWMIService.ExecQuery ('SELECT * FROM Win32_NetworkAdapter', 'WQL', 0x10 + 0x20)
$colitems = $objWMIService^ ERROR
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-30 11:28 , Processed in 0.106640 second(s), 20 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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