如何使用SetupApi获取活动的网卡?
如何使用SetupApi.au3来获取已连接的网卡信息?或者获取指定网卡的状态,如已连接,断开连接,禁用。谢谢! $sNetNmae = "本地连接";这里是你要监测的网卡名称$strComputer = "."
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter",Default,48)
While 1
For $objItem in $colItems
;ConsoleWrite($objItem.NetConnectionID & @CRLF)
If StringInStr($objItem.NetConnectionID, $sNetNmae, 1) Then
Switch $objItem.NetConnectionStatus
Case 0
$strStatus = "Disconnected"
Case 1
$strStatus = "Connecting"
Case 2
$strStatus = "Connected"
Case 3
$strStatus = "Disconnecting"
Case 4
$strStatus = "Hardware not present"
Case 5
$strStatus = "Hardware disabled"
Case 6
$strStatus = "Hardware malfunction"
Case 7
$strStatus = "Media disconnected"
Case 8
$strStatus = "Authenticating"
Case 9
$strStatus = "Authentication succeeded"
Case 10
$strStatus = "Authentication failed"
Case 11
$strStatus = "Invalid address"
Case 12
$strStatus = "Credentials required"
EndSwitch
TrayTip($objItem.NetConnectionID, $strStatus, 1)
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter",Default,48)
ExitLoop
EndIf
Next
;ExitLoop
WEnd 不好意思,WMI的我会,我是说使用P版的SetupApi来获取。还是谢谢你的答案。 SetupAPI.au3只是对硬件进行物理操作,比如获取网卡的状态,SetupAPI只能判断出它是否禁用、启用、或者有否安装驱动,对于“已连接”、“未连接”的情况,SetupAPI是判断不出来的。
楼主看下这个调用SetupAPI.au3实现的设备管理器,里面有获取网卡详细状态的实现代码,获取连接状态和连接时间等信息时,调用的是Iphlpapi函数,而不是SetupAPI函数。
页:
[1]