MYST Posted July 10, 2008 Share Posted July 10, 2008 (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 July 10, 2008 by MYST Link to comment Share on other sites More sharing options...
Valuater Posted July 10, 2008 Share Posted July 10, 2008 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) Link to comment Share on other sites More sharing options...
MYST Posted July 10, 2008 Author Share Posted July 10, 2008 it works! thank you muttley Link to comment Share on other sites More sharing options...
Kitsune Posted July 10, 2008 Share Posted July 10, 2008 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. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now