Guten Mittag, liebe AutoIt'ler,
mir war langweilig und da habe ich mir ein kleines Skript geschrieben, welches in gewissem Abstand checkt, ob man eine Verbindung zum Internet hat oder eben nicht.
Außerdem wird jedes mal für 5 Sekunden eine kleine Meldung rechts unten angezeigt, wenn dieser Status wechselt.
Es gibt keine GUI, nur ein Tray-Icon (+Tray-Menü), über das man alles steuern kann.
Wenn man das Programm mit einer Zahl als Parameter startet, wird diese Zeit als Delay voreingestellt.
Ich habe das Script und das Icon in einer .zip angehängt.
Funktionen
- Überprüfung pausieren
- Alle x Sekunden checken (Delay)
- Verknüpfung erstellen lassen (Voreingestellter Zeit-Parameter)
Source
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Icon\ICS.ico
#AutoIt3Wrapper_Res_Fileversion=1.0.0.0
#AutoIt3Wrapper_Res_LegalCopyright=Rafael K. (Joriktos)
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <Constants.au3>
[/autoit] [autoit][/autoit] [autoit]TraySetIcon(@SystemDir & "\shell32.dll", 16739)
Opt("TrayMenuMode", 3)
TraySetClick(8)
Global $bConnected
Global $bPause = False
Global $iDelay = 5000
Global $iPing = Ping("www.google.com")
If $iPing = 0 Then $iPing += Ping("www.autoit.de") + Ping("www.web.de")
If $CmdLine[0] <> 0 Then
If StringIsDigit($CmdLine[1]) = 1 Then
$iDelay = $CmdLine[1] * 1000
EndIf
EndIf
Global $idTrayPause = TrayCreateItem("Pause Checking")
TrayItemSetState($idTrayPause, $TRAY_DEFAULT)
Global $idTrayCheck = TrayCreateItem("Start Checking")
TrayItemSetState($idTrayCheck, $TRAY_DISABLE)
Global $idTrayDelay = TrayCreateItem("Delay")
TrayCreateItem("")
Global $idTrayShortcut = TrayCreateItem("Shortcut with Delay")
TrayCreateItem("")
Global $idTrayExit = TrayCreateItem("Exit")
If $iPing = 0 Then
$bConnected = False
TraySetIcon(@SystemDir & "\shell32.dll", 161)
TraySetToolTip("You're NOT connected to the Internet.")
ToolTip("You're not connected to the Internet.", @DesktopWidth - 233, @DesktopHeight - 70, "No Connection", 2)
Else
$bConnected = True
TraySetIcon(@SystemDir & "\shell32.dll", 14)
TraySetToolTip("You're connected to the Internet.")
ToolTip("You're connected to the Internet.", @DesktopWidth - 212, @DesktopHeight - 70, "Connected", 1)
EndIf
_ToolTipClose()
_Check()
Func _TrayMsg()
$nTrayMsg = TrayGetMsg()
Switch $nTrayMsg
Case $idTrayDelay
_Delay()
Case $idTrayPause
_Pause()
Case $idTrayCheck
_StartCheck()
Case $idTrayShortcut
_Shortcut()
Case $idTrayExit
Exit
EndSwitch
Return
EndFunc ;==>_TrayMsg
Func _Check()
While 1
$iTimer = TimerInit()
While TimerDiff($iTimer) < $iDelay
_TrayMsg()
WEnd
$iPing = Ping("www.google.com")
If $iPing = 0 Then $iPing += Ping("www.autoit.de") + Ping("www.web.de")
If $bConnected = True And $iPing = 0 Then
$bConnected = False
TraySetIcon(@SystemDir & "\shell32.dll", 161)
TraySetToolTip("You're NOT connected to the Internet")
ToolTip("You're not connected to the Internet anymore.", @DesktopWidth - 283, @DesktopHeight - 70, "Connection lost", 2)
_ToolTipClose()
ElseIf $bConnected = False And $iPing <> 0 Then
$bConnected = True
TraySetIcon(@SystemDir & "\shell32.dll", 14)
TraySetToolTip("You're connected to the Internet.")
ToolTip("You're now connected to the Internet.", @DesktopWidth - 238, @DesktopHeight - 70, "Connection found", 1)
_ToolTipClose()
EndIf
WEnd
EndFunc ;==>_Check
Func _Pause()
TraySetIcon(@SystemDir & "\shell32.dll", 16739)
TrayItemSetState($idTrayPause, $TRAY_DISABLE + $TRAY_DEFAULT)
TrayItemSetState($idTrayCheck, $TRAY_ENABLE + $TRAY_DEFAULT)
_ToolTipClose()
While 1
_TrayMsg()
WEnd
EndFunc ;==>_Pause
Func _StartCheck()
TrayItemSetState($idTrayCheck, $TRAY_DISABLE + $TRAY_DEFAULT)
TrayItemSetState($idTrayPause, $TRAY_ENABLE + $TRAY_DEFAULT)
$iPing = Ping("www.google.com")
If $iPing = 0 Then $iPing += Ping("www.autoit.de") + Ping("www.web.de")
If $iPing = 0 Then
$bConnected = False
TraySetIcon(@SystemDir & "\shell32.dll", 161)
TraySetToolTip("You're NOT connected to the Internet.")
ToolTip("You're not connected to the Internet.", @DesktopWidth - 233, @DesktopHeight - 70, "No Connection", 2)
Else
$bConnected = True
TraySetIcon(@SystemDir & "\shell32.dll", 14)
TraySetToolTip("You're connected to the Internet.")
ToolTip("You're connected to the Internet.", @DesktopWidth - 212, @DesktopHeight - 70, "Connected", 1)
EndIf
_ToolTipClose()
_Check()
EndFunc ;==>_StartCheck
Func _ToolTipClose()
$iTipTimer = TimerInit()
While TimerDiff($iTipTimer) < 5000
_TrayMsg()
WEnd
ToolTip("")
EndFunc ;==>_ToolTipClose
Func _Shortcut()
$iShortcutDelay = $iDelay / 1000
$sAnswer = InputBox("Delay after shortcut-start", "Insert the Delay (in Seconds) to check the connection:", $iShortcutDelay, " M3", 300, 125)
$bAnswerCheck = False
While $bAnswerCheck = False
If @error = 1 Then
Return
ElseIf StringIsDigit($sAnswer) = 1 And @error = 0 Then
$iShortcutDelay = $sAnswer
$bAnswerCheck = True
Else
$sAnswer = InputBox("Delay after shortcut-start", "Your Input was wrong. Try it again:" & @CRLF & @CRLF & "Insert the Delay (in Seconds) to check the connection:", $iShortcutDelay, " M3", 300, 150)
EndIf
WEnd
FileCreateShortcut(@ScriptFullPath, @ScriptDir & "\Internet Connection State.lnk", "", $iShortcutDelay, "", @SystemDir & "\shell32.dll", "", -14)
Return
EndFunc
Func _Delay()
$sAnswer = InputBox("Delay", "Insert the Delay (in Seconds) to check the connection:", $iDelay / 1000, " M3", 300, 125)
$bAnswerCheck = False
While $bAnswerCheck = False
If @error = 1 Then
Return
ElseIf StringIsDigit($sAnswer) = 1 And @error = 0 Then
$iDelay = $sAnswer * 1000
$bAnswerCheck = True
Else
$sAnswer = InputBox("Delay", "Your Input was wrong. Try it again:" & @CRLF & @CRLF & "Insert the Delay (in Seconds) to check the connection:", $iDelay / 1000, " M3", 300, 150)
EndIf
WEnd
Return
EndFunc ;==>_Delay
Gruß
Joriktos