Sign in to follow this  
Followers 0
MYST

Internet Check: Run File If No Connection Is Found

4 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

it works! thank you muttley

Share this post


Link to post
Share on other sites

you could always do a ping for "www.google.com" and it'll return 1 if it succeeds and 0 if it fails. It is a much better way to check for a connection because it requires one to succeed.

Share this post


Link to post
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
Sign in to follow this  
Followers 0