bills4 Posted August 31, 2013 Share Posted August 31, 2013 I am running program with IE , but sometimes my internet was disconnected , when internet was disconnected i want my program stop run . Please help Link to comment Share on other sites More sharing options...
JohnOne Posted August 31, 2013 Share Posted August 31, 2013 I think _GetIP() fails if you are not connected to internet. I don't think it's a function you should call in a tight loop though. There's are other alternatives. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Newb Posted August 31, 2013 Share Posted August 31, 2013 You can try run a Ping(site) and if it's equal to 0 then call a ProcessExists/ProcessClose combination on it. I'm a compulsive poster. When I post something, come to read it at least 5 minutes later after the posting, because I will edit it. I edited even this signature a few minutes later after I wrote it. Link to comment Share on other sites More sharing options...
JohnOne Posted August 31, 2013 Share Posted August 31, 2013 (edited) There is also a Windows API which checks the state locally, via a call to system dll. Just cannot quite remember its name. EDIT: Possibly InternetGetConnectedState Edited August 31, 2013 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
dragan Posted September 1, 2013 Share Posted September 1, 2013 This will check for your internet connection state: expandcollapse popupOpt("TrayAutoPause", 0) Global $CheckingForOffline = True _GetInitialState() While 1 Sleep (250) _CheckInternetState() WEnd ;======================================================================================================== ;========================== Function: =================================================================== Func _GetInitialState() Local $IsConnected = _ISConnectedToInternet() If @error Then ConsoleWrite('!> Error: ' & @error & ', Couldn''t access "wininet.dll", and "InternetGetConnectedState" function' & @CRLF) MsgBox(16, 'Error: ' & @error, 'Couldn''t access "wininet.dll", and "InternetGetConnectedState" function' & @CRLF & _ @CRLF & _ 'Press OK to quit the script.') Exit Else If $IsConnected Then $CheckingForOffline = True ConsoleWrite('-> checking for internet disconnection started...' & @CRLF & @CRLF) Else $CheckingForOffline = False ConsoleWrite('>> checking for internet reconnection started...' & @CRLF & @CRLF) EndIf EndIf EndFunc Func _CheckInternetState() Local $IsConnected = _ISConnectedToInternet() If @error Then ConsoleWrite('!> Error: ' & @error & ', Couldn''t access "wininet.dll", and "InternetGetConnectedState" function' & @CRLF) MsgBox(16, 'Error: ' & @error, 'Couldn''t access "wininet.dll", and "InternetGetConnectedState" function' & @CRLF & _ @CRLF & _ 'Press OK to quit the script.') Exit Else If $CheckingForOffline Then If NOT $IsConnected Then ConsoleWrite('!> Internet has just been disconnected' & @CRLF) ;~ Exit;<------------- Enable this line if you want your script to close if you get disconnected $CheckingForOffline = False ConsoleWrite('>> checking for internet reconnection started...' & @CRLF & @CRLF) EndIf Else If $IsConnected Then ConsoleWrite('+> Internet has just been reconnected' & @CRLF) $CheckingForOffline = True ConsoleWrite('-> checking for internet disconnection started...' & @CRLF & @CRLF) EndIf EndIf EndIf EndFunc Func _ISConnectedToInternet() Local $aDllRet = DllCall("wininet.dll", "int", "InternetGetConnectedState", "long_ptr", 0, "long", 0) If @error OR NOT IsArray($aDllRet) then Return SetError(1, 0, 0) If $aDllRet[0] > 0 Then Return True Else Return False EndIf EndFunc ;======================================================================================================== ;======================================================================================================== 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