|
发表于 2011-1-29 09:35:37
|
显示全部楼层
本帖最后由 smartzbs 于 2011-1-29 09:40 编辑
状态:0(未连接),2(连接),7(断线),11(地址非法)是你要的,也是常用的.
$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 |
|