Code : Tout sélectionner
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$aLabel = _GetNames(_GetObj())
Dim $aCheckBox[$aLabel[0] + 1][2]
Dim $aAdapter[2]
$hSelection = GUICreate("Selection", 300, $aLabel[0] * 45, -1, -1, -1, BitOR($WS_EX_TOOLWINDOW,$WS_EX_WINDOWEDGE))
If $aLabel[0] = 0 Then
MsgBox(0, "Error", "No Adapters Found", 0)
Exit
EndIf
For $i = 1 to $aLabel[0]
$aCheckBox[$i][0] = GUICtrlCreateCheckbox($aLabel[$i], 8, $i * 20, 290)
;~ GUICtrlSetState(-1, $GUI_CHECKED)
$aCheckBox[$i][1] = $aLabel[$i]
Next
$aCheckBox[0][0] = $aLabel[0]
$Button1 = GUICtrlCreateButton("Okay", 100, $aLabel[0] * 30, 75)
GUISetState(@SW_SHOW)
While 1
Sleep(50)
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $Button1
$i1 = 1
$bExit = 0
For $i = 1 to $aCheckBox[0][0]
If GUICtrlRead($aCheckBox[$i][0]) = 1 Then
$aAdapter[0] = $i1
ReDim $aAdapter[$i1 + 1]
$aAdapter[$i1] = $aCheckBox[$i][1]
$i1 += 1
$bExit = 1
EndIf
Next
If $bExit = 1 Then
GUIDelete($hSelection)
ExitLoop
Else
MsgBox(0, "Error", "No Adapter Selected", 0)
EndIf
EndSwitch
WEnd
$Tenth = 20
$hMonitor = GUICreate("Monitor", 212, 100, -1, -1)
GUISetFont(9)
$Menu = GUICtrlCreateMenu("&Options")
$bytesize = GUICtrlCreateMenu("Byte Size", $Menu)
$kbyte = GUICtrlCreateMenuItem("KB", $bytesize)
$mbyte = GUICtrlCreateMenuItem("MB", $bytesize)
GUICtrlSetState(-1, $GUI_CHECKED)
$gbyte = GUICtrlCreateMenuItem("GB", $bytesize)
$Label1 = GUICtrlCreateLabel("Bandwidth: Megabytes", 8, 8, 145, 24)
$Label3 = GUICtrlCreateLabel("", 8, 32, 210, 24)
$Label5 = GUICtrlCreateLabel("", 100, 32, 110, 20, $SS_RIGHT)
$progress = GUICtrlCreateProgress(8, 56, 160, 15)
$Label7 = GUICtrlCreateLabel("4 GB", 180, 55, 100, 24)
GUISetState(@SW_SHOW)
While 1
$Msg = GUIGetMsg()
If $Msg = $GUI_EVENT_CLOSE Then Exit
If $Msg = $kbyte Then
GUICtrlSetState($kbyte, $GUI_CHECKED)
GUICtrlSetState($mbyte, $GUI_UNCHECKED)
GUICtrlSetState($gbyte, $GUI_UNCHECKED)
$Tenth = 10
GUICtrlSetData($Label1, "Bandwidth: Kilobytes")
ElseIf $Msg = $mbyte Then
GUICtrlSetState($kbyte, $GUI_UNCHECKED)
GUICtrlSetState($mbyte, $GUI_CHECKED)
GUICtrlSetState($gbyte, $GUI_UNCHECKED)
$Tenth = 20
GUICtrlSetData($Label1, "Bandwidth: Megabytes")
ElseIf $Msg = $gbyte Then
GUICtrlSetState($kbyte, $GUI_UNCHECKED)
GUICtrlSetState($mbyte, $GUI_UNCHECKED)
GUICtrlSetState($gbyte, $GUI_CHECKED)
$Tenth = 30
GUICtrlSetData($Label1, "Bandwidth: Gigabytes")
EndIf
$aData = _GetData(_GetObj(), $aAdapter)
$BYTE = Round( ($aData[0]) / (2 ^ $Tenth),4)
GUICtrlSetData($Label3, $BYTE)
GUICtrlSetData($progress, ($aData[0] / (4 * (2^30))) * 100)
GUICtrlSetData($Label5, Round($aData[0] / (4 * (2^30)) * 100, 2) & "%")
WEnd
Func _GetNames($colItems)
Local $aName[2], $i = 1
If IsObj($colItems) then
For $objItem In $colItems
$aName[0] = $i
ReDim $aName[$i + 1]
$aName[$i] = $objItem.Name
$i += 1
Next
EndIf
Return $aName
EndFunc
Func _GetData($colItems, $aAdapter)
Local $aData[2]
If IsObj($colItems) then
For $objItem In $colItems
For $i = 1 to $aAdapter[0]
If $objItem.Name = $aAdapter[$i] Then
$aData[0] += $objItem.BytesReceivedPersec
$aData[1] += $objItem.BytesSentPersec
EndIf
Next
Next
EndIf
Return $aData
EndFunc
Func _GetObj()
Local $wbemFlagReturnImmediately = 0x10, $wbemFlagForwardOnly = 0x20, $colItems = "", $strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
$colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPersec,BytesSentPersec,Name FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
Return $colItems
EndFunc