Ping.au3

Opt("WinTitleMatchMode", 2)
 
#include <GUIConstants.au3>
 
HotKeySet("!{ESC}", "Terminate")
HotKeySet("!a", "_anzeigen")
HotKeySet("!v", "_verstecken")
HotKeySet("!s", "_soundtoggle")
HotKeySet("!h", "_hilfe")
HotKeySet("!l", "_log")
 
Global $GUIWidth = 300
Global $GUIHeight = 250
Global $pcnummer[1000]
Global $pcstate[1000]
Global $temp = ""
Dim $exit = 0
Dim $linearray[10]
Dim $filename = "pcliste.txt"
Dim $t
Dim $ll = 0
Global $W = @DesktopWidth - 315
Global $H = 20
Global $toolstatus = 1
Global $i
Global $sound = "off"
Global $edit
Global $striche =  "-----------------------------S"
Global $log = "off"
Global $striche2 = "-----------------------------L"
 
Run("notepad.exe " & @ScriptDir & "\pcliste.txt")
WinWaitActive("pcliste.txt - Editor")
WinMove("pcliste.txt - Editor", "", 500, 200, 200, 500)
WinWaitClose("pcliste.txt - Editor")
 
;datei mit pc namen einlesen
$file = FileOpen($filename, 0)
If $file = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
$i = 1
While 1
    $line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    If StringLeft($line, 1) <> ";"  Then
        $t = StringInStr($line, " ")
        If $t <> 0 Then
            $pcnummer[$i] = StringStripWS(StringLeft($line, $t),3)
        Else
            $pcnummer[$i] = $line
        EndIf
        $i = $i + 1
    EndIf
WEnd
$i = $i - 1
FileClose($file)
_stati()
_anzeigen()
 
;hauptschleife
While 1
    For $x = 0 To $i
        $zeit = @YEAR & "/" & @MON & "/" & @MDAY & " - " & @HOUR & ":" & @MIN & ":" & @SEC
        $var = Ping($pcnummer[$x], 50)
        If $var <> $pcstate[$x] Then
            $ll = $x
            If $var == 0 Then
                TrayTip("Statusänderung", $pcnummer[$x] & " : (" & $var & ") offline", 10, 1)
                If $sound = "off"  Then
                    ;SoundPlay("C:\WINDOWS\Media\ringout.wav")
	    beep(800,500)
                EndIf
	if $log == "off" Then
	    _RunDOS('echo ' & $zeit & ' : ' & $pcnummer[$x] & ' jetzt offline >> ping.log' )
	EndIf
            EndIf
            If ($var > 0) And ($pcstate[$x] == 0) Then
                TrayTip("Statusänderung", $pcnummer[$x] & " : (" & $var & ") online", 10, 1)
                If $sound = "off"  Then
                    ;SoundPlay("C:\WINDOWS\Media\ringout.wav")
	    beep(800,500)
                EndIf
	if $log == "off" Then
	    _RunDOS('echo ' & $zeit & ' : ' & $pcnummer[$x] & ' jetzt online >> ping.log')
	EndIf
            EndIf
            $pcstate[$x] = $var
        EndIf
        _stati2($x, $ll)
        _anzeigen()
    Next
    sleep(500)
WEnd
 
; Funktionen =======================================
 
Func _stati()
    $temp = ""
    For $x = 1 To $i
        $var = Ping($pcnummer[$x], 10)
        $pcstate[$x] = $var
        $temp = $temp & StringRight("0" & $x, 2) & " : " & $pcnummer[$x] & " -> " & _
                       $pcstate[$x] & @CRLF
        ToolTip($temp, $W, $H)
    Next
EndFunc   ;==>_stati
 
Func _stati2($z, $ll)
    $temp = ""
    For $x = 1 To $i
        If $x = $z Then
            $zz = " => "
        Else
            $zz = " -> "
        EndIf
        $temp = $temp & StringRight("0" & $x, 2) & " : " & $pcnummer[$x] & $zz & $pcstate[$x]
        If $x = $ll Then
            $temp = $temp & "*"
        EndIf
        $temp = $temp & @CRLF
    Next
EndFunc   ;==>_stati2
 
Func _anzeigen()
    If $toolstatus = 1 Then
        $zeit = @YEAR & "/" & @MON & "/" & @MDAY & " - " & @HOUR & ":" & @MIN & ":" & @SEC
        $info = $striche2 & @CRLF & "Hilfe mit Alt+H"
        ToolTip($zeit & @CRLF & $striche & @CRLF & $temp & $info, $W, $H)
    EndIf
EndFunc   ;==>_anzeigen
 
Func _hilfe()
    MsgBox(0, "Pingtool Hilfe", "Anzeigen/Verstecken" & @TAB & "Alt+V" & @CRLF & _
                               "Sound on/off   " & @TAB & @TAB & "Alt+S" & @CRLF & _
		               "Log on/off   " & @TAB & @TAB & "Alt+L" & @crlf & _
 		               "Beenden " & @TAB & @TAB & @TAB & "Alt+ESC       ")
EndFunc   ;==>_hilfe
 
Func _verstecken()
    ToolTip("")
    If $toolstatus == 1 Then
        $toolstatus = 0
    Else
        $toolstatus = 1
    EndIf
EndFunc   ;==>_verstecken
 
Func _soundtoggle()
    If $sound = "on"  Then
        $sound = "off"
        Global $striche = "---------------------------S"
    Else
        $sound = "on"
        Global $striche = "-----------------------------"
    EndIf
    _anzeigen()
EndFunc   ;==>_soundtoggle
 
Func _log()
	if $log == "on" Then
		$log = "off"
		$striche2 = "---------------------------L"
	Else
		$log = "on"
		$striche2 = "-----------------------------"
	EndIf
EndFunc
 
Func Terminate()
    MsgBox(0, "Pingtool", "Überwachung beendet", 2)
    Exit 0
EndFunc   ;==>Terminate
Func _RunDOS($sCommand)
    Return RunWait(@ComSpec & " /C " & $sCommand, "", @SW_HIDE)
EndFunc   ;==>_RunDOS

Kommentare

Baloons müssen aktiviert sein

Sollten die Baloons nicht angezeigt werden, mussen sie aktiviert werden. Dazu kann folgender Text als "BallonOn.reg" abgespeichert werden. Ein Doppelklick auf die Datei aktiviert dann die Baloons.

---8<---
Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced]
"EnableBalloonTips"=dword:00000000
---8<---

Wolfgang