Jump to content

how can stop program if IE was disconnected


 Share

Recommended Posts

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

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 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

This will check for your internet connection state:

 

Opt("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

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...