Page 1 sur 1
[Ex] Popup informations système
Posté : jeu. 19 mai 2016 15:48
par juju3301
Hello,
C'est avec plaisir que je vous partage mon premier script avec GUI.
Voici l'utilité de celui-ci :
Le script permet d'afficher (en permanence) des informations du système sous forme de popup dans le but :
- D'avoir un œil sur l'utilisation de la mémoire et du processeur
- D'afficher les informations permettant au support technique de l'entreprise de prendre la main à distance
En effet, le script sera déployé sur un parc d'environ 200 postes de travail, et les informations affichées permettront aux utilisateurs appelant le support, de communiquer facilement les informations système de base.
Le script affiche :
- L'adresse IP locale
- Le nom de l'ordinateur
- Le nom de l'utilisateur connecté
- Le système d'exploitation, la version du service pack et l'architecture du processeur
- La taille de l'écran
- L'utilisation de la mémoire et du processeur
Voici une capture d'écran :
Et voici le code source :
#NoTrayIcon#include <GUIConstantsEx.au3>#include <FontConstants.au3>#include <WindowsConstants.au3>#include <ColorConstantS.au3>#include <MsgBoxConstants.au3>Opt("GUICloseOnESC", 0) ; Désactive la fermeture du programme via la touche ESCAPEDisplaySystemInfo
()Func DisplaySystemInfo
() $FenPosSizeX = @DesktopWidth - 300 $FenPosSizeY = @DesktopHeight - 153 $aMem = MemGetStats() $Form1 = GUICreate("",300,110,$FenPosSizeX,$FenPosSizeY,$WS_POPUP,$WS_EX_TOOLWINDOW) GUISetBkColor("0xfff7b2") GUISetFont(9, $FW_NORMAL, $GUI_FONTNORMAL, "Courier New") WinSetTrans($Form1, "", 170) Local $iOldOpt = Opt("GUICoordMode", 2) GUICtrlCreateLabel("Adresse IP : " & @IPAddress1, 5, 5, 300) GUICtrlCreateLabel("Nom de l'ordinateur : " & @ComputerName, -1, -5) GUICtrlCreateLabel("Utilisateur : " & @UserName, -1, -5) GUICtrlCreateLabel("Système : " & @OSVersion & " - " & @OSServicePack & " - " & @OSArch, -1, -5) GUICtrlCreateLabel("Taille écran : " & @DeskTopWidth & "x" & @DesktopHeight, -1, -5) GUICtrlCreateLabel("Mémoire : " & $aMem[0] & "% " & "Processeur : ", -1, -5) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;Exit EndSwitch ; Récupère l'utilisation de la mémoire $aMem = MemGetStats() GUICtrlSetData(-1,"Mémoire : " & $aMem[0] & "% " & "Processeur : "&_Processor_Usage
()) Sleep(1000) WEnd $iOldOpt = Opt("GUICoordMode", $iOldOpt) Opt("GUICloseOnESC", 0) EndFunc Func _Processor_Usage
() Local $s_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor') Local $Obj_Item For $Obj_Item In $Col_Items Local $s_Text = $Obj_Item.PercentProcessorTime & '%' Next Return String($s_Text) Else Return 0 EndIf EndFunc
Si vous avez des commentaires ou des suggestions, je suis preneur !
Re: [Ex] Popup informations système
Posté : jeu. 19 mai 2016 20:56
par blacksoul305
Salut salut,
merci pour le script. C'est bien de pouvoir ce dont les utilisateurs du forum sont capables de faire !
Moi je me contenterai d'une suggestion : perso je pense que chacun a ses préférences, d'autres vont vouloir avoir des infos type consommation processeur, mémoire, disque, d'autres des infos plus axées réseau comme l'adresse IP, le débit etc... Ma suggestion serait de donner à l'utilisateur la possibilité (via un fichier à éditer, ou une GUI formulaire) de concevoir sa propre notification en activant ou non l'affichage de certaines informations.
Cela serait un bon exercice selon et pourrait rendre ton script utile pour plus de personnes.
Bon courage et félicitations.
EDIT : peut-être préciser que l'adresse IP donnée est l'adresse IP locale.
Re: [Ex] Popup informations système
Posté : ven. 20 mai 2016 14:03
par walkson
Bonjour
Merci pour ce partage.
Un petit mot pour dire que Je suis du même avis que blacksoul305. Pour ma part, j'utilise un petit programme qui me renvoie le CPU sans utiliser winmgmts. Il marche bien sauf qu'il a des sauts d'humeur (120% ou +)... Je vais donc tester votre code.
Je me renvoie aussi mon IP public avec ce code (il n'est pas de moi) placé sur mon site et m'évite d'interroger des sites étrangers
Code : Tout sélectionner
<?php
$ip = $_SERVER['REMOTE_ADDR'];//On obtient l'adresse IP
$gethostbyaddr = gethostbyaddr($ip);
$dyn = explode('.', $gethostbyaddr);
$nb_points = substr_count($gethostbyaddr, '.');// Nombre de point(s) dans la ligne
echo '<strong>',$ip,'</strong><br />',"\r\n"
,'</a>';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr"><head>
<meta http-equiv="Content-LANGUAGE" content="French" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="GENERATOR" content="PHP Designer 2005" />
<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Style-Type" content="text/ccs" />
<meta name="author" content="Nuel Guillaume" />
<title></title>
</head><body>
<?php
$ip = $_SERVER['REMOTE_ADDR'];//On obtient l'adresse IP
$gethostbyaddr = gethostbyaddr($ip);
$dyn = explode('.', $gethostbyaddr);
$nb_points = substr_count($gethostbyaddr, '.');// Nombre de point(s) dans la ligne
if(IsSet($dyn[$nb_points],$dyn[$nb_points - 1])){
$fichier = $dyn[$nb_points - 1].'.'.$dyn[$nb_points];// Adresse du fichier
if(@fopen('http://www.'.$fichier,'r') || @fopen('http://'.$fichier,'r')){//Il existe ;-)
echo '<span class="Gras">',$ip,'</span><br />',"\r\n"
,'</a>';
}else{
echo '<div style="text-align:center; color:#FF0000;"></div>',"\r\n";// Il n' existe pas :'(
}
}else{
echo '<div style="text-align:center;"></div>',"\r\n";
}
?>
</body></html>
En tout cas, encore merci
[Edit] retour:
error: $GUI_FONTNORMAL: undeclared global variable.
Je l'ai remplacé par 0
Sinon, on ferme comment votre programme
?
Re: [Ex] Popup informations système
Posté : ven. 20 mai 2016 22:38
par juju3301
Salut à tous,
Merci pour vos retours et vos idées. C'est une bonne idée de prévoir la modification des indicateurs affichées par l'utilisateur. Je vais m'atteler à coder cela.
@walkson, l'idée initiale du programme n'était pas de pouvoir être fermé par l'utilisateur.. Donc obligé de passer par le gestionnaire des tâches. Bon je vais également modifier cela en trouvant un autre moyen
Re: [Ex] Popup informations système
Posté : mer. 12 oct. 2016 18:40
par marcgforce
Ce script est tout a fait génial, et j'en remercie l'auteur, il m'a donné l'idée de l'utiliser au boulot pour donner des infos importantes à l'utilisateur et d’éviter de coller des étiquettes partout sur les écrans....
j'y ai rajouté une option (un debuggage en quelque sorte) car j'ai vite vu qu'en cas de changement de resolution d'ecran en plus grand ou plus petit, le programme ne s'adapte pas (c'est ennuyeux)
donc un petit test de resolution d'ecran dans la boucle plus loin permet d'afficher la fenêtre graphique dans le coin a droite même en cas de changement de la résolution... pratique
#NoTrayIcon #include <GUIConstantsEx.au3> #include <FontConstants.au3> #include <WindowsConstants.au3> #include <ColorConstantS.au3> #include <MsgBoxConstants.au3> Global $resolution_x=@DesktopWidth, $resolution_y=@DesktopHeight ; Ici je rentre la resolution en dur pour la comparer dans la fonction _testResolution Opt("GUICloseOnESC", 0) ; Désactive la fermeture du programme via la touche ESCAPE DisplaySystemInfo
() Func DisplaySystemInfo
() $FenPosSizeX = @DesktopWidth - 300 $FenPosSizeY = @DesktopHeight - 153 $aMem = MemGetStats() $Form1 = GUICreate("",300,110,$FenPosSizeX,$FenPosSizeY,$WS_POPUP,$WS_EX_TOOLWINDOW) GUISetBkColor("0xfff7b2") GUISetFont(9, $FW_NORMAL, $GUI_FONTNORMAL, "Courier New") WinSetTrans($Form1, "", 170) Local $iOldOpt = Opt("GUICoordMode", 2) GUICtrlCreateLabel("Adresse IP : " & @IPAddress1, 5, 5, 300) GUICtrlCreateLabel("Nom de l'ordinateur : " & @ComputerName, -1, -5) GUICtrlCreateLabel("Utilisateur : " & @UserName, -1, -5) GUICtrlCreateLabel("Système : " & @OSVersion & " - " & @OSServicePack & " - " & @OSArch, -1, -5) GUICtrlCreateLabel("Taille écran : " & @DeskTopWidth & "x" & @DesktopHeight, -1, -5) GUICtrlCreateLabel("Mémoire : " & $aMem[0] & "% " & "Processeur : ", -1, -5) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;Exit EndSwitch ; Récupère l'utilisation de la mémoire $aMem = MemGetStats() GUICtrlSetData(-1,"Mémoire : " & $aMem[0] & "% " & "Processeur : "&_Processor_Usage
()) _testResolution
() ; On envoi le test de la resolution d'ecran voir si elle a changée Sleep(1000) WEnd $iOldOpt = Opt("GUICoordMode", $iOldOpt) Opt("GUICloseOnESC", 0) EndFunc Func _Processor_Usage
() Local $s_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor') Local $Obj_Item For $Obj_Item In $Col_Items Local $s_Text = $Obj_Item.PercentProcessorTime & '%' Next Return String($s_Text) Else Return 0 EndIf EndFunc Func _testResolution
() ; la fonction de test If $resolution_x <> @DesktopWidth or $resolution_y <> @DesktopHeight Then ; la resolution est comparée avec celle du départ, si elle a changé $resolution_x = @DesktopWidth ; on la met en memoire $resolution_y = @DesktopHeight GUISetState(@SW_HIDE); on efface la precedente fenêtre DisplaySystemInfo
() ; on rafraichis Else Return ; sinon on boucle EndIf EndFunc
Re: [Ex] Popup informations système
Posté : ven. 14 oct. 2016 18:37
par marcgforce
Je reviens sur le précédent post, car en l'utilisant je me suis aperçu que la GUI disparaissait sous les autres fenêtres et ne restait pas non plus sur le bureau. La valeur $WS_EX_TOOLWINDOW l’empêche d'apparaitre dans le "ALT-TAB" windows, donc pour la faire réapparaitre c'est un peu galère.
j'ai pensé utiliser la fonction $WS_EX_TOPMOST en complément, pour qu'elle reste tout le temps affiché par dessus les autres fenêtre, mais j'ai constaté qu'elle pouvait gêner avec certains logiciels pour attraper des commandes dans le coin de l’écran.
d’où l'idée de cliquer dessus pour la faire disparaitre quelques secondes, le temps faire sa manipulation, puis de la faire réapparaitre :
Case $GUI_EVENT_PRIMARYDOWN ; si la gui est cliqué avec la souris GUISetState(@SW_HIDE) ; on efface la fenêtre pour permettre a l'utilisateur d’accéder a ce qui se trouve en dessous sleep(1000); ici le temps (1 secondes) peut être modifié selon les besoins GUISetState(@SW_SHOW)
Malheureusement je suis gêné par le rafraichissement des données mémoire et processeur, car j'ai du faire baisser drastiquement le sleep à 10 pour que le clic souris soit pris en compte instantanément. dans l'exemple j'ai enlevé la ligne de rafraichissement de la mémoire et du processeur et cela fonctionne, si quelqu'un à une idée pour que cela fonctionne avec, ce sera toujours enrichissant !
Voilà le script modifié et commenté pour avoir un aperçu
#NoTrayIcon #include <GUIConstantsEx.au3> #include <FontConstants.au3> #include <WindowsConstants.au3> #include <ColorConstantS.au3> #include <MsgBoxConstants.au3> Global $resolution_x=@DesktopWidth, $resolution_y=@DesktopHeight ; Ici je rentre la resolution en dur pour la comparer dans la fonction _testResolution Opt("GUICloseOnESC", 0) ; Désactive la fermeture du programme via la touche ESCAPE DisplaySystemInfo
() Func DisplaySystemInfo
() $FenPosSizeX = @DesktopWidth - 300 $FenPosSizeY = @DesktopHeight - 153 $aMem = MemGetStats() $Form1 = GUICreate("",300,110,$FenPosSizeX,$FenPosSizeY,$WS_POPUP,BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetBkColor("0xfff7b2") GUISetFont(9, $FW_NORMAL, $GUI_FONTNORMAL, "Courier New") WinSetTrans($Form1, "", 170) Local $iOldOpt = Opt("GUICoordMode", 2) GUICtrlCreateLabel("Adresse IP : " & @IPAddress1, 5, 5, 300) GUICtrlCreateLabel("Nom de l'ordinateur : " & @ComputerName, -1, -5) GUICtrlCreateLabel("Utilisateur : " & @UserName, -1, -5) GUICtrlCreateLabel("Système : " & @OSVersion & " - " & @OSServicePack & " - " & @OSArch, -1, -5) GUICtrlCreateLabel("Taille écran : " & @DeskTopWidth & "x" & @DesktopHeight, -1, -5) ;GUICtrlCreateLabel("Mémoire : " & $aMem[0] & "% " & "Processeur : ", -1, -5) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;Exit Case $GUI_EVENT_PRIMARYDOWN ; si la gui est cliqué avec la souris GUISetState(@SW_HIDE) ; on efface la fenêtre pour permettre a l'utilisateur d'acceder a ce qui se trouve en dessous sleep(1000); ici le temps (1 secondes) peut être modifié selon les besoins GUISetState(@SW_SHOW) EndSwitch ; Récupère l'utilisation de la mémoire $aMem = MemGetStats() ;GUICtrlSetData(-1,"Mémoire : " & $aMem[0] & "% " & "Processeur : "&_Processor_Usage()) _testResolution
() ; On envoi le test de la resolution d'ecran voir si elle a changée Sleep(10); si le sleep est superieur, la reaction du clic a l'evenement $GUI_EVENT_PRIMARYDOWN est très retardé WEnd $iOldOpt = Opt("GUICoordMode", $iOldOpt) Opt("GUICloseOnESC", 0) EndFunc Func _Processor_Usage
() Local $s_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor') Local $Obj_Item For $Obj_Item In $Col_Items Local $s_Text = $Obj_Item.PercentProcessorTime & '%' Next Return String($s_Text) Else Return 0 EndIf EndFunc Func _testResolution
() ; la fonction de test If $resolution_x <> @DesktopWidth or $resolution_y <> @DesktopHeight Then ; la resolution est comparée avec celle du départ, si elle a changé $resolution_x = @DesktopWidth ; on la met en memoire $resolution_y = @DesktopHeight GUISetState(@SW_HIDE); on efface la precedente fenêtre DisplaySystemInfo
() ; on rafraichis Else Return ; sinon on boucle EndIf EndFunc
Re: [Ex] Popup informations système
Posté : lun. 17 oct. 2016 14:41
par orax
On peut utiliser
AdlibRegister()
pour faire ça. Dans cet exemple, toutes les secondes (1000 ms) la fonction _stats est appelée.
#NoTrayIcon#include <GUIConstantsEx.au3>#include <FontConstants.au3>#include <WindowsConstants.au3>#include <ColorConstantS.au3>#include <MsgBoxConstants.au3>Global $resolution_x = @DesktopWidth, $resolution_y = @DesktopHeight ; Ici je rentre la resolution en dur pour la comparer dans la fonction _testResolutionOpt("GUICloseOnESC", 0) ; Désactive la fermeture du programme via la touche ESCAPEAdlibRegister("_stats", 1000)DisplaySystemInfo
()Func DisplaySystemInfo
() $FenPosSizeX = @DesktopWidth - 300 $FenPosSizeY = @DesktopHeight - 153 $aMem = MemGetStats() $Form1 = GUICreate("", 300, 110, $FenPosSizeX, $FenPosSizeY, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetBkColor("0xfff7b2") GUISetFont(9, $FW_NORMAL, $GUI_FONTNORMAL, "Courier New") WinSetTrans($Form1, "", 170) Local $iOldOpt = Opt("GUICoordMode", 2) GUICtrlCreateLabel("Adresse IP : " & @IPAddress1, 5, 5, 300) GUICtrlCreateLabel("Nom de l'ordinateur : " & @ComputerName, -1, -5) GUICtrlCreateLabel("Utilisateur : " & @UserName, -1, -5) GUICtrlCreateLabel("Système : " & @OSVersion & " - " & @OSServicePack & " - " & @OSArch, -1, -5) GUICtrlCreateLabel("Taille écran : " & @DesktopWidth & "x" & @DesktopHeight, -1, -5) ;GUICtrlCreateLabel("Mémoire : " & $aMem[0] & "% " & "Processeur : ", -1, -5) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;Exit Case $GUI_EVENT_PRIMARYDOWN ; si la gui est cliqué avec la souris GUISetState(@SW_HIDE) ; on efface la fenêtre pour permettre a l'utilisateur d'acceder a ce qui se trouve en dessous Sleep(1000); ici le temps (1 secondes) peut être modifié selon les besoins GUISetState(@SW_SHOW) EndSwitch WEnd $iOldOpt = Opt("GUICoordMode", $iOldOpt) Opt("GUICloseOnESC", 0)EndFunc ;==>DisplaySystemInfoFunc _stats
() ; Récupère l'utilisation de la mémoire $aMem = MemGetStats() GUICtrlSetData(-1, "Mémoire : " & $aMem[0] & "% " & "Processeur : " & _Processor_Usage
()) _testResolution
() ; On envoi le test de la resolution d'ecran voir si elle a changéeEndFunc ;==>_statsFunc _Processor_Usage
() Local $s_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor') Local $Obj_Item For $Obj_Item In $Col_Items Local $s_Text = $Obj_Item.PercentProcessorTime & '%' Next Return String($s_Text) Else Return 0 EndIfEndFunc ;==>_Processor_UsageFunc _testResolution
() ; la fonction de test If $resolution_x <> @DesktopWidth Or $resolution_y <> @DesktopHeight Then ; la resolution est comparée avec celle du départ, si elle a changé $resolution_x = @DesktopWidth ; on la met en memoire $resolution_y = @DesktopHeight GUISetState(@SW_HIDE); on efface la precedente fenêtre DisplaySystemInfo
() ; on rafraichis Else Return ; sinon on boucle EndIfEndFunc ;==>_testResolution
Re: [Ex] Popup informations système
Posté : lun. 17 oct. 2016 21:07
par marcgforce
Super ! c'est ce qu'il fallait, par contre tu as déplacé la fonction le contrôle de la résolution dans la fonction _stat et ça détecte pas bien... je l'ai re-déplacé dans le while 1
donc ça donne
#NoTrayIcon #include <GUIConstantsEx.au3> #include <FontConstants.au3> #include <WindowsConstants.au3> #include <ColorConstantS.au3> #include <MsgBoxConstants.au3> Global $resolution_x = @DesktopWidth, $resolution_y = @DesktopHeight ; Ici je rentre la resolution en dur pour la comparer dans la fonction _testResolution Opt("GUICloseOnESC", 0) ; Désactive la fermeture du programme via la touche ESCAPE AdlibRegister("_stats", 1000) DisplaySystemInfo
() Func DisplaySystemInfo
() $FenPosSizeX = @DesktopWidth - 300 $FenPosSizeY = @DesktopHeight - 153 $aMem = MemGetStats() $Form1 = GUICreate("", 300, 110, $FenPosSizeX, $FenPosSizeY, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetBkColor("0xfff7b2") GUISetFont(9, $FW_NORMAL, $GUI_FONTNORMAL, "Courier New") WinSetTrans($Form1, "", 170) Local $iOldOpt = Opt("GUICoordMode", 2) GUICtrlCreateLabel("Adresse IP : " & @IPAddress1, 5, 5, 300) GUICtrlCreateLabel("Nom de l'ordinateur : " & @ComputerName, -1, -5) GUICtrlCreateLabel("Utilisateur : " & @UserName, -1, -5) GUICtrlCreateLabel("Système : " & @OSVersion & " - " & @OSServicePack & " - " & @OSArch, -1, -5) GUICtrlCreateLabel("Taille écran : " & @DesktopWidth & "x" & @DesktopHeight, -1, -5) GUICtrlCreateLabel("Mémoire : " & $aMem[0] & "% " & "Processeur : ", -1, -5) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;Exit Case $GUI_EVENT_PRIMARYDOWN ; si la gui est cliqué avec la souris GUISetState(@SW_HIDE) ; on efface la fenêtre pour permettre a l'utilisateur d'acceder a ce qui se trouve en dessous Sleep(1000); ici le temps (1 secondes) peut être modifié selon les besoins GUISetState(@SW_SHOW) EndSwitch _testResolution
() WEnd $iOldOpt = Opt("GUICoordMode", $iOldOpt) Opt("GUICloseOnESC", 0) EndFunc ;==>DisplaySystemInfo Func _stats
() ; Récupère l'utilisation de la mémoire $aMem = MemGetStats() GUICtrlSetData(-1, "Mémoire : " & $aMem[0] & "% " & "Processeur : " & _Processor_Usage
()) ; On envoi le test de la resolution d'ecran voir si elle a changée EndFunc ;==>_stats Func _Processor_Usage
() Local $s_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor') Local $Obj_Item For $Obj_Item In $Col_Items Local $s_Text = $Obj_Item.PercentProcessorTime & '%' Next Return String($s_Text) Else Return 0 EndIf EndFunc ;==>_Processor_Usage Func _testResolution
() ; la fonction de test If $resolution_x <> @DesktopWidth Or $resolution_y <> @DesktopHeight Then ; la resolution est comparée avec celle du départ, si elle a changé $resolution_x = @DesktopWidth ; on la met en memoire $resolution_y = @DesktopHeight GUISetState(@SW_HIDE); on efface la precedente fenêtre DisplaySystemInfo
() ; on rafraichis Else Return ; sinon on boucle EndIf EndFunc ;==>_testResolution
Re: [Ex] Popup informations système
Posté : mar. 18 oct. 2016 03:39
par illwind33
Bonjour,
Pour cacher une fenêtre j'utilise cette fonction:
je clique 2 fois sur le 'tray icon' , je switche @SW_SHOW/@SW_HIDE selon la valeur de WinGetState($hSplash, '') (un BitAND($iState, 2) )
(ma fenêtre c'est un 'SplashTextOn' pour faire simple)
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_UseX64=y#AutoIt3Wrapper_Run_Tidy=y#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****#include <Misc.au3>#include <TrayConstants.au3>#include <WinAPIDiag.au3> ; pour _WinAPI_IsInternetConnected;#include <_NetworkStatistics.au3> ; pour traffic()_Singleton(@ScriptName, 0)Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.Opt("TrayOnEventMode", 1)Global $larg = 100, $haut = 60Global $PosW = @DesktopWidth - $larg, $PosH = @DesktopHeight - $haut - 50 ; en bas a droite;Global Const $PosW = 1, $PosH = @DesktopHeight - $haut - 50 ; en bas a gaucheGlobal $hSplash = SplashTextOn("Traffic Internet", '', $larg, $haut, $PosW, $PosH, 4 + 16, '', 8, 100)Func Tray
() TraySetIcon("netshell.dll", 142) TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "TrayEvent") TraySetState($TRAY_ICONSTATE_SHOW)EndFunc ;==>TrayFunc TrayEvent
() ;cw('TrayEvent'&@TAB&@TRAY_ID) Switch @TRAY_ID Case $TRAY_EVENT_PRIMARYDOUBLE $iState = WinGetState($hSplash, '') ;cw('WinGetState'&@TAB&$iState) Switch BitAND($iState, 2) Case False WinSetState($hSplash, '', @SW_SHOW) TraySetState($TRAY_ICONSTATE_STOPFLASH) Case True WinSetState($hSplash, '', @SW_HIDE) TraySetState($TRAY_ICONSTATE_FLASH) EndSwitch EndSwitchEndFunc ;==>TrayEventTray
()While 1 $connected = 'Internet:' & _WinAPI_IsInternetConnected() ControlSetText($hSplash, '', 'Static1', $connected) Sleep(1000 * 10)WEndFunc cw
($text, $line = @ScriptLineNumber) ConsoleWrite(StringFormat("%04d", $line) & @TAB & '|') ConsoleWrite($text) ConsoleWrite('|' & @LF)EndFunc ;==>cw
A+
Re: [Ex] Popup informations système
Posté : mar. 18 oct. 2016 09:41
par marcgforce
Effectivement j'avais pensé à mettre ces informations dans le tray icon, mais (pour des raisons de simplification du travail), j'ai besoin que l'utilisateur ai les informations sous les yeux en permanence et n'ai pas besoin de chercher une icône dans le systray - d’ailleurs j'essayerai d'adapter ce super script a ce mode -
J'en finis là avec une petite option (au choix), je pensais que faire disparaitre la gui en cliquant peut être rébarbatif a force, j'ai donc modifié le script pour que la gui disparaisse lorsque la souris passe dessus... simple et efficace : au lieu de enlèvement clic on intègre un if qui prend la position de la souris, quand elle arrive dans la zone de la GUI - disparition - pause - réapparition.
voilà le code :
#NoTrayIcon #include <GUIConstantsEx.au3> #include <FontConstants.au3> #include <WindowsConstants.au3> #include <ColorConstantS.au3> #include <MsgBoxConstants.au3> Global $resolution_x = @DesktopWidth, $resolution_y = @DesktopHeight ; Ici je rentre la resolution en dur pour la comparer dans la fonction _testResolution Opt("GUICloseOnESC", 0) ; Désactive la fermeture du programme via la touche ESCAPE AdlibRegister("_stats", 1000) DisplaySystemInfo
() Func DisplaySystemInfo
() $FenPosSizeX = @DesktopWidth - 300 $FenPosSizeY = @DesktopHeight - 153 $aMem = MemGetStats() $Form1 = GUICreate("", 300, 110, $FenPosSizeX, $FenPosSizeY, $WS_POPUP, BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)) GUISetBkColor("0xfff7b2") GUISetFont(9, $FW_NORMAL, $GUI_FONTNORMAL, "Courier New") WinSetTrans($Form1, "", 170) Local $iOldOpt = Opt("GUICoordMode", 2) GUICtrlCreateLabel("Adresse IP : " & @IPAddress1, 5, 5, 300) GUICtrlCreateLabel("Nom de l'ordinateur : " & @ComputerName, -1, -5) GUICtrlCreateLabel("Utilisateur : " & @UserName, -1, -5) GUICtrlCreateLabel("Système : " & @OSVersion & " - " & @OSServicePack & " - " & @OSArch, -1, -5) GUICtrlCreateLabel("Taille écran : " & @DesktopWidth & "x" & @DesktopHeight, -1, -5) GUICtrlCreateLabel("Mémoire : " & $aMem[0] & "% " & "Processeur : ", -1, -5) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE ;Exit Case $GUI_EVENT_MOUSEMOVE, $GUI_EVENT_PRIMARYDOWN ; lorsque la souris bouge ou si elle est cliquée $mouse=MouseGetPos() if $mouse[0] >= $FenPosSizeX and $mouse[1] >= $FenPosSizeY Then ; si la souris arrive à la GUI GUISetState(@SW_HIDE); on efface la fenêtre pour permettre a l'utilisateur d'acceder a ce qui se trouve en dessous sleep(5000) ;=> modifiable et gérable dans un ini de conf GUISetState(@SW_SHOW) endif EndSwitch _testResolution
() ; test de la résolution écran pour voir si elle a changée WEnd $iOldOpt = Opt("GUICoordMode", $iOldOpt) Opt("GUICloseOnESC", 0) EndFunc ;==>DisplaySystemInfo Func _stats
() ; Récupère l'utilisation de la mémoire $aMem = MemGetStats() GUICtrlSetData(-1, "Mémoire : " & $aMem[0] & "% " & "Processeur : " & _Processor_Usage
()) ; On envoi le test de la resolution d'ecran voir si elle a changée EndFunc ;==>_stats Func _Processor_Usage
() Local $s_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2'); If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor') Local $Obj_Item For $Obj_Item In $Col_Items Local $s_Text = $Obj_Item.PercentProcessorTime & '%' Next Return String($s_Text) Else Return 0 EndIf EndFunc ;==>_Processor_Usage Func _testResolution
() ; la fonction de test If $resolution_x <> @DesktopWidth Or $resolution_y <> @DesktopHeight Then ; la resolution est comparée avec celle du départ, si elle a changé $resolution_x = @DesktopWidth ; on la met en memoire $resolution_y = @DesktopHeight GUISetState(@SW_HIDE); on efface la precedente fenêtre DisplaySystemInfo
() ; on rafraichis Else Return ; sinon on boucle EndIf EndFunc ;==>_testResolution
Re: [Ex] Popup informations système
Posté : mar. 18 oct. 2016 14:42
par marcgforce
Voilà cher illwind33, avec un peu de temps j'ai adapté le script avec ta méthode, et c'est pas mal, ça laisse le choix à la personne qui voudra utiliser le script de prendre l'une ou l'autre !
le code adapté :
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_UseX64=y#AutoIt3Wrapper_Run_Tidy=y#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****#include <Misc.au3>#include <TrayConstants.au3>#include <WinAPIDiag.au3> ; pour _WinAPI_IsInternetConnected;#include <_NetworkStatistics.au3> ; pour traffic()_Singleton(@ScriptName, 0)$aMem = MemGetStats()Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode.Opt("TrayOnEventMode", 1)Global $larg = 250, $haut = 120Global $PosW = @DesktopWidth - $larg, $PosH = @DesktopHeight - $haut - 65 ; en bas a droite;Global Const $PosW = 1, $PosH = @DesktopHeight - $haut - 65 ; en bas a gaucheGlobal $hSplash = SplashTextOn("~-INFORMATIONS SYSTEME-~", '', $larg, $haut, $PosW, $PosH, 4 + 16, '', 8, 100)AdlibRegister("_stats", 1000)Func Tray
() TraySetIcon("shell32.dll", 24) TraySetOnEvent($TRAY_EVENT_PRIMARYDOUBLE, "TrayEvent") TraySetState($TRAY_ICONSTATE_SHOW)EndFunc ;==>TrayFunc TrayEvent
() ;cw('TrayEvent'&@TAB&@TRAY_ID) Switch @TRAY_ID Case $TRAY_EVENT_PRIMARYDOUBLE $iState = WinGetState($hSplash, '') ;cw('WinGetState'&@TAB&$iState) Switch BitAND($iState, 2) Case False WinSetState($hSplash, '', @SW_SHOW) TraySetState($TRAY_ICONSTATE_STOPFLASH) Case True WinSetState($hSplash, '', @SW_HIDE) TraySetState($TRAY_ICONSTATE_FLASH) EndSwitch EndSwitchEndFunc ;==>TrayEventTray
()While 1 $connected = "Adresse IP : " & @IPAddress1 & @CRLF & _
"Nom de l'ordinateur : " & @ComputerName & @CRLF & _
"Utilisateur : " & @UserName & @CRLF & _
"Système : " & @OSVersion & " - " & @OSServicePack & " - " & @OSArch & @CRLF & _
"Taille écran : " & @DesktopWidth & "x" & @DesktopHeight & @CRLF & _
"Mémoire : " & $aMem[0] & "% " & "Processeur : " & _Processor_Usage
() & @CRLF & _
"Internet : " & _internetOK
() ControlSetText($hSplash, '', 'Static1', $connected) Sleep(1000 * 10)WEndFunc cw
($text, $line = @ScriptLineNumber) ConsoleWrite(StringFormat("%04d", $line) & @TAB & '|') ConsoleWrite($text) ConsoleWrite('|' & @LF)EndFunc ;==>cwFunc _stats
() ; Récupère l'utilisation de la mémoire $aMem = MemGetStats() _Processor_Usage
()EndFunc ;==>_statsFunc _Processor_Usage
() Local $s_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2') ; If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor') Local $Obj_Item For $Obj_Item In $Col_Items Local $s_Text = $Obj_Item.PercentProcessorTime & '%' Next Return String($s_Text) Else Return 0 EndIfEndFunc ;==>_Processor_UsageFunc _internetOK
() If _WinAPI_IsInternetConnected() Then Return "OK" Else Return "KO" EndIfEndFunc ;==>_internetOK
Re: [Ex] Popup informations système
Posté : jeu. 20 oct. 2016 05:07
par illwind33
Bonjour,
Amusons-nous un peu avec ce nouveau jouet:
;You can not register a function using parameters;Return xxxx ca marche pas non plus;GROS AVANTAGE: si on a une fonction bloquante, ça ne bloque pas le reste;dans mon cas un sleep de 10sec dans trafic_internet()AdlibRegister("Mem", $g_idelai)AdlibRegister("CPUrasim", $g_idelai)AdlibRegister("Systray", $g_idelai)AdlibRegister("internetOK",$g_idelai)AdlibRegister("trafic_Internet",$g_idelai)AdlibRegister("stats", $g_idelai)While 1 Sleep(100)WEndFunc stats
() Local $connected = "Adresse IP : " & @IPAddress1 & @CRLF & _
"Nom de l'ordinateur : " & @ComputerName & @CRLF & _
"Utilisateur : " & @UserName & @CRLF & _
"Système : " & @OSVersion & " - " & @OSServicePack & " - " & @OSArch & @CRLF & _
"Taille écran : " & @DesktopWidth & "x" & @DesktopHeight & @CRLF & _
$g_smem & ' ' & $g_sCPUrasim & ' ' & $g_sSystray & @CRLF & _
$g_sinternet & ' ' & $g_strafic_Internet ControlSetText($hSplash, '', 'Static1', $connected)EndFunc ;==>stats
la fonction 'wmic cpu get loadpercentage' ne fonctionne pas chez moi (même sous dos)
j'en ai trouvé une autre sur le site anglais qui ne fait pas appel a wmi
;---------------------------------------Global $IDLETIME, $KERNELTIME, $USERTIMEGlobal $StartIdle, $StartKernel, $StartUserGlobal $EndIdle, $EndKernel, $EndUser;https://www.autoitscript.com/forum/topic/72689-cpumon/$IDLETIME = DllStructCreate("dword;dword")$KERNELTIME = DllStructCreate("dword;dword")$USERTIME = DllStructCreate("dword;dword");---------------------------------------Func GetSysTime
(ByRef $sIdle, ByRef $sKernel, ByRef $sUser) ;https://www.autoitscript.com/forum/topic/72689-cpumon/ DllCall("kernel32.dll", "int", "GetSystemTimes", "ptr", DllStructGetPtr($IDLETIME), _
"ptr", DllStructGetPtr($KERNELTIME), _
"ptr", DllStructGetPtr($USERTIME)) $sIdle = DllStructGetData($IDLETIME, 1) $sKernel = DllStructGetData($KERNELTIME, 1) $sUser = DllStructGetData($USERTIME, 1)EndFunc ;==>_GetSysTimeFunc CPUrasim
() ;https://www.autoitscript.com/forum/topic/72689-cpumon/ Local $iSystemTime, $iTotal, $iCalcIdle, $iCalcKernel, $iCalcUser GetSysTime
($EndIdle, $EndKernel, $EndUser) $iCalcIdle = ($EndIdle - $StartIdle) $iCalcKernel = ($EndKernel - $StartKernel) $iCalcUser = ($EndUser - $StartUser) $iSystemTime = ($iCalcKernel + $iCalcUser) $iTotal = Int(($iSystemTime - $iCalcIdle) * (100 / $iSystemTime)) GetSysTime
($StartIdle, $StartKernel, $StartUser) If $iTotal > 0 or $iTotal < 100 Then $g_sCPUrasim = "ProcR:" & $iTotal & "%"EndFunc ;==>_CPUCalc
j'ai modifié la fonction tray() pour faire comme les 'autres prg' : click left = show/hide , click right = menu
Func About
() MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _
"Version: " & @AutoItVersion & @CRLF & _
"Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) ; Find the folder of a full path.EndFunc ;==>AboutFunc Tray
() TraySetClick(8) ;8 = Pressing secondary mouse button mouseclicks will display the tray menu TrayCreateItem("About") TrayItemSetOnEvent(-1, "About") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitScript") TraySetIcon("shell32.dll", 24) TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "TrayEvent") TraySetState($TRAY_ICONSTATE_SHOW)EndFunc ;==>TrayFunc TrayEvent
() ;cw('TrayEvent'&@TAB&@TRAY_ID) Local $iState Switch @TRAY_ID Case $TRAY_EVENT_PRIMARYDOWN $iState = WinGetState($hSplash, '') ;cw('WinGetState'&@TAB&$iState) Switch BitAND($iState, 2) Case False WinSetState($hSplash, '', @SW_SHOW) ;TraySetState($TRAY_ICONSTATE_STOPFLASH) Case True WinSetState($hSplash, '', @SW_HIDE) ;TraySetState($TRAY_ICONSTATE_FLASH) EndSwitch EndSwitchEndFunc ;==>TrayEventFunc ExitScript
() ExitEndFunc ;==>ExitScript
Pour le même prix je vous rajoute une fonction qui nous donne le trafic sur
une carte spécifique
#include <_NetworkStatistics.au3> ; pour trafic_internet();https://www.autoitscript.com/forum/topic/151920-network-interface-info-statistics-and-traffic/Func trafic_Internet
() ; connaitre le trafic réseeau sur une carte spécifique Local $aT1, $ideb, $ifin, $ispeed, $i Local $idelai=1000*10 Local $aT = _Network_IPv4AdaptersInfoEx
() ;ad($aT) ;22|6|1|0|DE-99-B7-14-2F-4E|0|Remote NDIS based Internet Sharing Device #2||{91E21E37-DF50-4B23-B51D-FCE6F903C252}|||192.168.42.33|255.255.255.0|192.168.42.129|255.255.255.255|192.168.42.129|255.255.255.255|1476862776|1476866376|||| ;13|71|1|0|02-20-29-2D-2F-9C|0|Carte réseau sans fil Atheros AR9285||{5900A094-F668-481A-AB6F-BE5AC36ECC05}|||0.0.0.0|0.0.0.0|0.0.0.0|255.255.255.255|||0|0|||| ;11|6|0|0|20-CF-30-D1-26-D1|0|Atheros AR8131 PCI-E Gigabit Ethernet Controller (NDIS 6.20)||{04BC288C-E28C-4D84-A201-27CF188AE015}|||192.168.1.200|255.255.255.0|0.0.0.0|255.255.255.255|||||||| Return ;pour faire fonctionner la suite changer le nom de la carte réseau ;mon 'Remote NDIS' n'est pas fiable donc je suis obligé de vérifier souvent sa présence ;si c'est une carte filiaire on peut ne la chercher qu'une fois au lancement du programme ;Local $scarte = 'Atheros AR8131' ; RJ45 sur le réseau local Local $scarte = 'Remote NDIS' ; accés internet sur le smartphone branché en USB $i = _ArraySearch($aT, $scarte , 0, 0, 0, 1, 0, 6) ;22|6|1|0|9E-A6-99-1B-8B-F2|0|Remote NDIS based If $i = -1 Then erreur
('ne trouve pas la carte: ' & $scarte ) Return EndIf $aT1 = _Network_InterfaceEntryInfo
($aT[$i][0]) ; numero de la carte reseau col 0 ici 22 $ideb = $aT1[10] ; data receive colonne 10 Sleep($idelai) ; je recois des data pendant 10sec $aT1 = _Network_InterfaceEntryInfo
($aT[$i][0]) $ifin = $aT1[10] $ispeed = ($ifin - $ideb) / $idelai $ispeed = ($ispeed * 1000) / 1024 If $ispeed > 0 Then $g_strafic_Internet=Int($ispeed)&'Ko/s'EndFunc ;==>trafic_total
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****#AutoIt3Wrapper_Icon=icon\Système et maintenance.ico#AutoIt3Wrapper_UseX64=y#AutoIt3Wrapper_Run_Tidy=y#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****#include <Misc.au3>#include <array.au3>#include <TrayConstants.au3>#include <GuiToolbar.au3> ; pour Class:Shell_TrayWnd#include <WinAPIDiag.au3> ; pour _WinAPI_IsInternetConnected#include <_NetworkStatistics.au3> ; pour trafic_internet();https://www.autoitscript.com/forum/topic/151920-network-interface-info-statistics-and-traffic/;---------------------------------------Global $IDLETIME, $KERNELTIME, $USERTIMEGlobal $StartIdle, $StartKernel, $StartUserGlobal $EndIdle, $EndKernel, $EndUser;https://www.autoitscript.com/forum/topic/72689-cpumon/$IDLETIME = DllStructCreate("dword;dword")$KERNELTIME = DllStructCreate("dword;dword")$USERTIME = DllStructCreate("dword;dword");---------------------------------------_Singleton(@ScriptName, 0)Opt("TrayMenuMode", 3)Opt("TrayOnEventMode", 1)Opt("MustDeclareVars", 1)Global $larg = 250, $haut = 120Global $PosW = @DesktopWidth - $larg, $PosH = @DesktopHeight - $haut - 65 ; en bas a droite;Global Const $PosW = 1, $PosH = @DesktopHeight - $haut - 65 ; en bas a gaucheGlobal $hSplash = SplashTextOn("~-INFORMATIONS SYSTEME-~", '', $larg, $haut, $PosW, $PosH, 4 + 16, '', 8, 100)Global $g_smem, $g_sCPUrasim, $g_sSystray, $g_sinternet, $g_strafic_InternetGlobal $g_idelai = 1000 * 5Tray
();You can not register a function using parameters;Return xxxx ca marche pas non plus;GROS AVANTAGE: si on a une fonction bloquante, ca ne bloque pas le reste;dans mon cas un sleep de 10sec dans trafic_internet()AdlibRegister("Mem", $g_idelai)AdlibRegister("CPUrasim", $g_idelai)AdlibRegister("Systray", $g_idelai)AdlibRegister("internetOK", $g_idelai)AdlibRegister("trafic_Internet", $g_idelai)AdlibRegister("stats", $g_idelai)While 1 Sleep(100)WEndFunc stats
() Local $connected = "Adresse IP : " & @IPAddress1 & @CRLF & _
"Nom de l'ordinateur : " & @ComputerName & @CRLF & _
"Utilisateur : " & @UserName & @CRLF & _
"Système : " & @OSVersion & " - " & @OSServicePack & " - " & @OSArch & @CRLF & _
"Taille écran : " & @DesktopWidth & "x" & @DesktopHeight & @CRLF & _
$g_smem & ' ' & $g_sCPUrasim & ' ' & $g_sSystray & @CRLF & _
$g_sinternet & ' ' & $g_strafic_Internet ControlSetText($hSplash, '', 'Static1', $connected)EndFunc ;==>statsFunc trafic_Internet
() ; connaitre le trafic réseeau sur une carte spécifique Local $aT1, $ideb, $ifin, $ispeed, $i Local $idelai = 1000 * 10 Local $aT = _Network_IPv4AdaptersInfoEx
() ;ad($aT) ;22|6|1|0|DE-99-B7-14-2F-4E|0|Remote NDIS based Internet Sharing Device #2||{91E21E37-DF50-4B23-B51D-FCE6F903C252}|||192.168.42.33|255.255.255.0|192.168.42.129|255.255.255.255|192.168.42.129|255.255.255.255|1476862776|1476866376|||| ;13|71|1|0|02-20-29-2D-2F-9C|0|Carte réseau sans fil Atheros AR9285||{5900A094-F668-481A-AB6F-BE5AC36ECC05}|||0.0.0.0|0.0.0.0|0.0.0.0|255.255.255.255|||0|0|||| ;11|6|0|0|20-CF-30-D1-26-D1|0|Atheros AR8131 PCI-E Gigabit Ethernet Controller (NDIS 6.20)||{04BC288C-E28C-4D84-A201-27CF188AE015}|||192.168.1.200|255.255.255.0|0.0.0.0|255.255.255.255|||||||| Return ;pour faire fonctionner la suite changer le nom de la carte réseau ;mon 'Remote NDIS' n'est pas fiable donc je suis obligé de vérifier souvent sa présence ;si c'est une carte filiaire on peux ne la chercher qu'une fois au lancement du programme ;Local $scarte = 'Atheros AR8131' ; RJ45 sur le réseau local Local $scarte = 'Remote NDIS' ; accés internet sur le smartphone branché en USB $i = _ArraySearch($aT, $scarte, 0, 0, 0, 1, 0, 6) ;22|6|1|0|9E-A6-99-1B-8B-F2|0|Remote NDIS based If $i = -1 Then Erreur
('ne trouve pas la carte: ' & $scarte) Return EndIf $aT1 = _Network_InterfaceEntryInfo
($aT[$i][0]) ; numero de la carte reseau col 0 ici 22 $ideb = $aT1[10] ; data receive colonne 10 Sleep($idelai) ; je recois des data pendant 10sec $aT1 = _Network_InterfaceEntryInfo
($aT[$i][0]) $ifin = $aT1[10] $ispeed = ($ifin - $ideb) / $idelai $ispeed = ($ispeed * 1000) / 1024 If $ispeed >= 0 Then $g_strafic_Internet = Int($ispeed) & 'Ko/s'EndFunc ;==>trafic_Internet;-------------------------------Func GetSysTime
(ByRef $sIdle, ByRef $sKernel, ByRef $sUser) ;https://www.autoitscript.com/forum/topic/72689-cpumon/ DllCall("kernel32.dll", "int", "GetSystemTimes", "ptr", DllStructGetPtr($IDLETIME), _
"ptr", DllStructGetPtr($KERNELTIME), _
"ptr", DllStructGetPtr($USERTIME)) $sIdle = DllStructGetData($IDLETIME, 1) $sKernel = DllStructGetData($KERNELTIME, 1) $sUser = DllStructGetData($USERTIME, 1)EndFunc ;==>GetSysTimeFunc CPUrasim
() ;https://www.autoitscript.com/forum/topic/72689-cpumon/ Local $iSystemTime, $iTotal, $iCalcIdle, $iCalcKernel, $iCalcUser GetSysTime
($EndIdle, $EndKernel, $EndUser) $iCalcIdle = ($EndIdle - $StartIdle) $iCalcKernel = ($EndKernel - $StartKernel) $iCalcUser = ($EndUser - $StartUser) $iSystemTime = ($iCalcKernel + $iCalcUser) $iTotal = Int(($iSystemTime - $iCalcIdle) * (100 / $iSystemTime)) GetSysTime
($StartIdle, $StartKernel, $StartUser) If $iTotal >= 0 And $iTotal <= 100 Then $g_sCPUrasim = "ProcR:" & $iTotal & "%"EndFunc ;==>CPUrasim;---------------------------------------Func Systray
() ;je cherche 'CPU Usage' dans le systray ;https://technet.microsoft.com/en-us/sysinternals/bb896653.aspx ;Process Explorer - Sysinternals 'CPU Usage: 21%' Return Local $schaine = 'CPU' Local $hSysTray = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]') Local $i, $stray, $iCount = _GUICtrlToolbar_ButtonCount($hSysTray) ;cw($hSysTray & @TAB & $iCount) For $i = 0 To $iCount - 1 $stray = _GUICtrlToolbar_GetButtonText($hSysTray, $i) ;cwU($stray) If StringRegExp($stray, $schaine, 0) = 1 Then ;cwU($stray) ;CPU Usage: 21% ;AutoIt3_x64.exe: 10% $stray = StringRegExpReplace($stray, '.*: (.*?)%\n.*', '${1}') ;entre le 1° ': ' et %\n = Pourcent Linefeed If @extended <> 1 Then Return If Number($stray) >= 0 And Number($stray) <= 100 Then $g_sSystray = "ProcS:" & $stray & "%" EndIf NextEndFunc ;==>SystrayFunc internetOK
() If _WinAPI_IsInternetConnected() Then $g_sinternet = "Internet:OK" Else $g_sinternet = "Internet:KO" EndIfEndFunc ;==>internetOKFunc Mem
() Local $aMem = MemGetStats() $g_smem = "Mem: " & $aMem[0] & "%"EndFunc ;==>MemFunc About
() MsgBox($MB_SYSTEMMODAL, "", "AutoIt tray menu example." & @CRLF & @CRLF & _
"Version: " & @AutoItVersion & @CRLF & _
"Install Path: " & StringLeft(@AutoItExe, StringInStr(@AutoItExe, "\", 0, -1) - 1)) ; Find the folder of a full path.EndFunc ;==>AboutFunc Tray
() TraySetClick(8) ;8 = Pressing secondary mouse button mouseclicks will display the tray menu TrayCreateItem("About") TrayItemSetOnEvent(-1, "About") TrayCreateItem("") TrayCreateItem("Exit") TrayItemSetOnEvent(-1, "ExitScript") TraySetIcon("shell32.dll", 24) TraySetOnEvent($TRAY_EVENT_PRIMARYDOWN, "TrayEvent") TraySetState($TRAY_ICONSTATE_SHOW)EndFunc ;==>TrayFunc TrayEvent
() ;cw('TrayEvent'&@TAB&@TRAY_ID) Local $iState Switch @TRAY_ID Case $TRAY_EVENT_PRIMARYDOWN $iState = WinGetState($hSplash, '') ;cw('WinGetState'&@TAB&$iState) Switch BitAND($iState, 2) Case False WinSetState($hSplash, '', @SW_SHOW) ;TraySetState($TRAY_ICONSTATE_STOPFLASH) Case True WinSetState($hSplash, '', @SW_HIDE) ;TraySetState($TRAY_ICONSTATE_FLASH) EndSwitch EndSwitchEndFunc ;==>TrayEventFunc ExitScript
() ExitEndFunc ;==>ExitScriptFunc AD
($T, $line = @ScriptLineNumber) If Not IsArray($T) Then Return _ArrayDisplay($T, $line)EndFunc ;==>ADFunc wt
($texte = @ScriptLineNumber, $titre = @ScriptLineNumber) If MsgBox(1, $titre, '|' & $texte & '|') <> 1 Then ExitEndFunc ;==>wtFunc Erreur
($Message) ToolTip($Message, 1, 1, '', 1, 1) Run('rundll32 user32.dll,MessageBeep') Sleep(5000) ToolTip('')EndFunc ;==>ErreurFunc cw
($text, $line = @ScriptLineNumber) ConsoleWrite(StringFormat("%04d", $line) & @TAB & '|') ConsoleWrite($text) ConsoleWrite('|' & @LF)EndFunc ;==>cwFunc cwU
($text, $line = @ScriptLineNumber) ;https://www.autoitscript.fr/forum/viewtopic.php?f=11&t=5523 Local $aResult = DllCall("kernel32.dll", "int", "WideCharToMultiByte", "uint", 65001, "dword", 0, "wstr", $text, "int", -1, _
"ptr", 0, "int", 0, "ptr", 0, "ptr", 0) If @error Then Return SetError(1, @error, 0) Local $tText = DllStructCreate("char[" & $aResult[0] & "]") $aResult = DllCall("Kernel32.dll", "int", "WideCharToMultiByte", "uint", 65001, "dword", 0, "wstr", $text, "int", -1, _
"ptr", DllStructGetPtr($tText), "int", $aResult[0], "ptr", 0, "ptr", 0) If @error Then Return SetError(2, @error, 0) ConsoleWrite(StringFormat("%04d", $line) & @TAB & '|') ConsoleWrite(DllStructGetData($tText, 1)) ConsoleWrite('|' & @LF)EndFunc ;==>cwUFunc _Processor_Usage
() ; ne fonctionne pas chez moi (win7 pro 64b) ;meme sous dos ca ne fonctionne pas ;http://www.robvanderwoude.com/wmiexamples.php#CPULoad ;https://teckadmin.wordpress.com/2014/05/23/cpu-checks-in-windows-commandline/ ;wmic cpu get loadpercentage ;@for /f “skip=1″ %p in (‘wmic cpu get loadpercentage’) do @echo %p% ;typeperf “\Processor(_Total)\% Processor Time” Local $s_Text = '' Dim $Obj_WMIService = ObjGet('winmgmts:\\' & @ComputerName & '\root\cimv2') If (IsObj($Obj_WMIService)) And (Not @error) Then Dim $Col_Items = $Obj_WMIService.ExecQuery('SELECT * FROM Win32_PerfFormattedData_PerfOS_Processor') Local $Obj_Item For $Obj_Item In $Col_Items cw
(IsObj($Obj_Item)) Local $s_Text = $Obj_Item.PercentProcessorTime & '%' cw
($s_Text) Next Return String($s_Text) Else Return 0 EndIfEndFunc ;==>_Processor_Usage
a+