Jump to content

Recommended Posts

Posted

I am running program with IE , but sometimes my internet was disconnected , when internet was disconnected i want my program stop run .

Please help

Posted

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.

Posted

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

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
  • Recently Browsing   0 members

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