Jump to content

Internet Check: Run File If No Connection Is Found


Recommended Posts

Hello there! I am new to AutoIt so please help me. I got this script but it doesn't work as I want. It checks if a internet connection exists and starts a file when there is no connection for X seconds. When a connection is found it should do nothing but end itself and doesn't check again. Now it repeats the checks and opens the file after X seconds again and again and again.. what to do?

$sFile2Run = "Restart.bat"; The file that will be executed 
$sTimeInSeconds = 3*60; How long the internet can be disconnected before the file starts
While 1 
If Not _CheckInet() Then 
ConsoleWrite("!" & @CRLF) 
$hTi = TimerInit() 
While TimerDiff($hTi) <= $sTimeInSeconds*1000 
If _CheckInet() Then ExitLoop 2 
Sleep(1000) 
WEnd 
Run($sFile2Run) 
ConsoleWrite(@error & @CRLF) 
EndIf 
Sleep(1000) 
WEnd 

Func _CheckInet() 
Local $aDll,$sRet 
$aDll = DllCall("WinInet.dll","int","InternetGetConnectedState","int*",0,"int",0) 
If @error Then Return SetError(1,0,-1) 
If nOt IsArray($aDll) Then SetError(2,0,-1) 
If $aDll[0] = 0 Then Return False 
Return True 
EndFunc
Edited by MYST
Link to comment
Share on other sites

This is my guess...

$sFile2Run = "Restart.bat"; The file that will be executed
$sTimeInSeconds = 3 * 60; How long the internet can be disconnected before the file starts
;While 1
    If Not _CheckInet() Then
        ConsoleWrite("!" & @CRLF)
        $hTi = TimerInit()
        While TimerDiff($hTi) <= $sTimeInSeconds * 1000
            If _CheckInet() Then Exit ;Loop 2
            Sleep(1000)
        WEnd
        Run($sFile2Run)
        ConsoleWrite(@error & @CRLF)
    EndIf
    ;Sleep(1000)
;WEnd

Func _CheckInet()
    Local $aDll, $sRet
    $aDll = DllCall("WinInet.dll", "int", "InternetGetConnectedState", "int*", 0, "int", 0)
    If @error Then Return SetError(1, 0, -1)
    If Not IsArray($aDll) Then SetError(2, 0, -1)
    If $aDll[0] = 0 Then Return False
    Return True
EndFunc   ;==>_CheckInet

8)

NEWHeader1.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...