Les mémos
Je débute...
Visites

 987941 visiteurs

 3 visiteurs en ligne

Recherche
 
Fermer

Vérifier si une connexion Internet est active

Connexion par modem RTC (Port COM), Cable ou ADSL (Port USB)

'/
'/ A placer dans la partie déclarative
'/
Declare Function InternetGetConnectedState Lib "wininet.dll" _
                                           (lpdwFlags As Long, _
                                            ByVal dwReserved As Long) As Boolean

 La fonction :

Function fIsConnected() As Boolean
    Dim Stat As Long
    fIsConnected = (InternetGetConnectedState(Stat, 0&) <> 0)

End Function

Connexion via Réseau Local ou par Modem (RJ45)

'/
'/ A placer dans la partie déclarative
'/
Declare Function InternetOpen Lib "wininet.dll" _
                    Alias "InternetOpenA" _
                   (ByVal lpszAgent As String, _
                    ByVal dwAccessType As Long, _
                    ByVal lpszProxyName As String, _
                    ByVal lpszProxyBypass As String, _
                    ByVal dwFlags As Long) As Long

Declare Function InternetOpenUrl Lib "wininet.dll" _
                    Alias "InternetOpenUrlA" _
                    (ByVal hInet As Long, _
                     ByVal lpszUrl As String, _
                     ByVal lpszHeaders As String, _
                     ByVal dwHeadersLength As Long, _
                     ByVal dwFlags As Long, _
                     ByVal dwContext As Long) As Long

Declare Function InternetCloseHandle Lib "wininet.dll" _
                    (ByVal hInet As Long) As Long

Const INTERNET_OPEN_TYPE_PRECONFIG As Long = 0
Const INTERNET_FLAG_RELOAD As Long = &H80000000
Const INTERNET_FLAG_KEEP_CONNECTION As Long = &H400000
Const INTERNET_FLAG_NO_CACHE_WRITE As Long = &H4000000

La Fonction :

Function fOnLine() As Boolean
    Dim hInet As Long
    Dim hUrl As Long
    Dim Flags As Long

    hInet = InternetOpen("Test", INTERNET_OPEN_TYPE_PRECONFIG, _
                         vbNullString, vbNullString, 0&)

    If hInet Then
        Flags = INTERNET_FLAG_KEEP_CONNECTION Or _
                INTERNET_FLAG_NO_CACHE_WRITE Or _
                INTERNET_FLAG_RELOAD
        hUrl = InternetOpenUrl(hInet, "http://www.microsoft.com", vbNullString, 0&, Flags, 0&)

        If hUrl Then
            fOnLine = True
            Call InternetCloseHandle(hUrl)
        Else
            fOnLine = False
        End If
    End If

    Call InternetCloseHandle(hInet)

End Function


Catégorie : Les mémos - Net
Page lue 5310 fois