找回密码
 加入
搜索
楼主: 令狐大虾

[网络通信] [已解决]请教如何判断存在无线网卡则执行?(感谢chzj58和raeast)

[复制链接]
 楼主| 发表于 2019-10-9 20:06:41 | 显示全部楼层
chzj589 发表于 2019-10-9 11:41
那是判断发现无线网卡,运行程序。
我测试用的,你可改或注消
测试环境:WIN764位,AutoIt3\autoit3_x6 ...

明白,但是我运行这个程序找到的是VM虚拟机的网卡而不是无线网卡呢
发表于 2019-10-9 22:10:43 | 显示全部楼层
令狐大虾 发表于 2019-10-9 20:06
明白,但是我运行这个程序找到的是VM虚拟机的网卡而不是无线网卡呢

明天再回复,要睡觉了
发表于 2019-10-10 09:45:50 | 显示全部楼层
本帖最后由 chzj589 于 2019-10-10 13:19 编辑
令狐大虾 发表于 2019-10-9 20:06
明白,但是我运行这个程序找到的是VM虚拟机的网卡而不是无线网卡呢

这样试试

#AutoIt3Wrapper_UseX64 = n ;32位=n,64位=y
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Global $wangka1, $lianjie1
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1 (" & @ScriptName & ")", 515, 138, 192, 124)
$GLabel1 = GUICtrlCreateLabel("网卡 :", 50, 23, 40, 22)
GUICtrlSetFont(-1, 11, 400, 0, "微软雅黑")
GUICtrlSetColor(-1, 0x990000)
$Combo1 = GUICtrlCreateCombo("", 95, 20, 375, 17);, $WS_VSCROLL)
GUICtrlSetFont(-1, 11, 400, 0, "微软雅黑")
$Input1 = GUICtrlCreateLabel("", 8, 50, 415, 22);, $WS_VSCROLL)
GUICtrlSetFont(-1, 11, 400, 0, "微软雅黑")
WMI()
GUICtrlSetData($Combo1, _ArrayToString($wangka1, "|"), $wangka1[0])
GUICtrlSetColor($Combo1, 0xFF0000)
ControlCommand($Form1, "", 'ComboBox1', "SetCurrentSelection", 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_wxwk()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Combo1
                        _wxwk()
        EndSwitch
WEnd

Func _wxwk();获取网卡信息
        $sComboRead = GUICtrlRead($Combo1)
        For $i = 0 To UBound($wangka1) - 1
                If $sComboRead == $wangka1[$i] Then
                        ;GUICtrlSetData($Input1, "" & $lianjie1[$i])
                        $wxwk = 'Broadcom 802.11ac Network Adapter'
                        If GUICtrlRead($Combo1) = $wxwk Then
                                GUICtrlSetColor($Combo1, 0x009900)
                                GUICtrlSetData($Input1, $lianjie1[$i] & " =  " & $wangka1[$i])
                                GUICtrlSetColor($Input1, 0x009900)
                                RunWait("notepad.exe")
                        Else
                                GUICtrlSetData($Input1,  $lianjie1[$i]&" =  " &$wangka1[$i])
                                GUICtrlSetColor($Input1, 0x990000)
                        EndIf
                EndIf
        Next
EndFunc   ;==>_wxwk
Func WMI()
        Local $dnsa1
        $sMesStr = ""
        $oLocator = ObjCreate("WbemScripting.SWbemLocator")
        $oService = $oLocator.ConnectServer
        $oClassSet = $oService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionID IS NOT NULL")
        For $oClass In $oClassSet
                If @error Then ExitLoop
                $sMesStr = $sMesStr & "连接名:“" & $oClass.NetConnectionID() & "”" & @CRLF & _
                                "网卡名: “" & $oClass.Name & "”" & @CRLF
        Next
        $wangka1 = 0
        $lianjie1 = 0
        $wangka1 = StringRegExp($sMesStr, "(?<=网卡名: “)[^”]+", 3)
        $lianjie1 = StringRegExp($sMesStr, "(?<=连接名:“)[^”]+", 3)
EndFunc   ;==>WMI
 楼主| 发表于 2019-10-10 15:26:24 | 显示全部楼层
chzj589 发表于 2019-10-10 09:45
这样试试
[au3]
#AutoIt3Wrapper_UseX64 = n ;32位=n,64位=y

谢谢,这个是识别机子里面所有的网卡。达不到我标题的要求
发表于 2019-10-10 17:04:47 | 显示全部楼层
令狐大虾 发表于 2019-10-10 15:26
谢谢,这个是识别机子里面所有的网卡。达不到我标题的要求

能识别无线网卡吗?在下拉组合框里第几行?
发表于 2019-10-10 17:38:41 | 显示全部楼层
令狐大虾 发表于 2019-10-10 15:26
谢谢,这个是识别机子里面所有的网卡。达不到我标题的要求

这样再试试

#AutoIt3Wrapper_UseX64 = n ;32位=n,64位=y
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
Global $wangka1, $lianjie1
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1 (" & @ScriptName & ")", 515, 138, 192, 124)
$GLabel1 = GUICtrlCreateLabel("网卡 :", 50, 23, 40, 22)
GUICtrlSetFont(-1, 11, 400, 0, "微软雅黑")
GUICtrlSetColor(-1, 0x990000)
$Combo1 = GUICtrlCreateCombo("", 95, 20, 375, 17);, $WS_VSCROLL)
GUICtrlSetFont(-1, 11, 400, 0, "微软雅黑")
$Input1 = GUICtrlCreateLabel("", 8, 50, 415, 22);, $WS_VSCROLL)
GUICtrlSetFont(-1, 11, 400, 0, "微软雅黑")
WMI()
GUICtrlSetData($Combo1, _ArrayToString($wangka1, "|"), $wangka1[0])
GUICtrlSetColor($Combo1, 0xFF0000)
ControlCommand($Form1, "", 'ComboBox1', "SetCurrentSelection", 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_wxwk()
While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Combo1
                        _wxwk()
        EndSwitch
WEnd

Func _wxwk();获取网卡信息
                        $wxwk = 'Broadcom 802.11ac Network Adapter'
                        $wxwka =$wangka1[1]
                        If $wxwka = $wxwk Then
                                GUICtrlSetColor($Combo1, 0x009900)
                                GUICtrlSetData($Input1, $lianjie1[1] & " =  " & $wangka1[1])
                                GUICtrlSetColor($Input1, 0x009900)
                                RunWait("notepad.exe")
                        Else
                                GUICtrlSetData($Input1, $lianjie1[2] & " =  " & $wangka1[2])
                                GUICtrlSetColor($Input1, 0x990000)
                        EndIf
EndFunc   ;==>_wxwk
Func WMI()
        Local $dnsa1
        $sMesStr = ""
        $oLocator = ObjCreate("WbemScripting.SWbemLocator")
        $oService = $oLocator.ConnectServer
        $oClassSet = $oService.ExecQuery("Select * From Win32_NetworkAdapter Where NetConnectionID IS NOT NULL")
        For $oClass In $oClassSet
                If @error Then ExitLoop
                $sMesStr = $sMesStr & "连接名:“" & $oClass.NetConnectionID() & "”" & @CRLF & _
                                "网卡名: “" & $oClass.Name & "”" & @CRLF
        Next
        $wangka1 = 0
        $lianjie1 = 0
        $wangka1 = StringRegExp($sMesStr, "(?<=网卡名: “)[^”]+", 3)
        $lianjie1 = StringRegExp($sMesStr, "(?<=连接名:“)[^”]+", 3)
EndFunc   ;==>WMI

发表于 2019-10-10 20:14:56 | 显示全部楼层
好像运行不了啊,我测试了一下,不管是xp的还是win7的,总是错误。
发表于 2019-10-10 20:21:26 | 显示全部楼层
syzeng 发表于 2019-10-10 20:14
好像运行不了啊,我测试了一下,不管是xp的还是win7的,总是错误。

执行文件试试看

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2019-10-10 20:46:34 | 显示全部楼层
chzj589 发表于 2019-10-10 17:38
这样再试试
[au3]
#AutoIt3Wrapper_UseX64 = n ;32位=n,64位=y

下拉最后一项才是我的无线网卡

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2019-10-10 20:57:13 | 显示全部楼层
令狐大虾 发表于 2019-10-10 20:46
下拉最后一项才是我的无线网卡

把这个改一下
Func _wxwk();获取网卡信息
        $wxwk = 'Realtek 8188GU Wireless LAN 802.11n USB NIC'
        $wxwka = $wangka1[3]
        If $wxwka = $wxwk Then
                GUICtrlSetColor($Combo1, 0x009900)
                GUICtrlSetData($Input1, $lianjie1[3] & " =  " & $wangka1[3])
                GUICtrlSetColor($Input1, 0x009900)
                RunWait("notepad.exe")
        Else
                GUICtrlSetData($Input1, $lianjie1[2] & " =  " & $wangka1[2]);"未发现无线网卡---  " &
                GUICtrlSetColor($Input1, 0x990000)
        EndIf
EndFunc   ;==>_wxwk
 楼主| 发表于 2019-10-10 21:20:07 | 显示全部楼层
chzj589 发表于 2019-10-10 20:57
把这个改一下
Func _wxwk();获取网卡信息
        $wxwk = 'Realtek 8188GU Wireless LAN 802.11n USB  ...

运行后跳出

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2019-10-11 01:12:13 | 显示全部楼层
Local $colItems = ""
Local $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter")
If IsObj($colItems) Then
        For $objItem In $colItems
                If StringInStr($objItem.netconnectionID, "无线") Then     ;如果连接中包含“无线”,认定有无线网卡,执行。。。。。。
                        MsgBox(0, 0, "找到无线网卡")
                EndIf
        Next
EndIf
发表于 2019-10-11 07:15:47 | 显示全部楼层

18楼就解决问题了,只是你没有点击下拉组合框里的内容。
把第20行改为:
ControlCommand($Form1, "", 'ComboBox1', "SetCurrentSelection", 3)
就能直接判断存在无线网卡
 楼主| 发表于 2019-10-11 20:12:46 | 显示全部楼层
本帖最后由 令狐大虾 于 2019-10-11 20:22 编辑
raeast 发表于 2019-10-11 01:12
Local $colItems = ""
Local $objWMIService = ObjGet("winmgmts:\\localhost\root\CIMV2")
$colItems =  ...

谢谢,简单易行!
我用的是win10,无线改为WLAN就可以了。不过for命令下好像不能用else就是检测不到则退出那样
 楼主| 发表于 2019-10-11 20:17:04 | 显示全部楼层
chzj589 发表于 2019-10-11 07:15
18楼就解决问题了,只是你没有点击下拉组合框里的内容。
把第20行改为:
ControlCommand($Form1, "", ' ...

嗯,换后很完美显示出来了。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-4-25 16:36 , Processed in 0.073733 second(s), 14 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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