Titre: Détecte connexion.
Description:
Détecte si connecté à internet et le type de connexion.
Le code:
LOption Explicit Private Declare Function InternetGetConnectedState _ Lib "wininet.dll" (ByRef lpdwFlags As Long, _ ByVal dwReserved As Long) As Long Private Const INTERNET_CONNECTION_MODEM As Long = &H1 Private Const INTERNET_CONNECTION_LAN As Long = &H2 Private Const INTERNET_CONNECTION_PROXY As Long = &H4 Private Const INTERNET_CONNECTION_MODEM_BUSY As Long = &H8 Private Const INTERNET_CONNECTION_OFFLINE As Long = &H20 Private Const INTERNET_CONNECTION_CONFIGURED As Long = &H40 Private Sub Form_Load() TimerEpie.Interval = 1000 End Sub Private Sub TimerEpie_Timer() If IsNetConnectOnline() = True Then LblConnect = "Connecté" If IsNetConnectViaLAN() = True Then Lbltype.Caption = "LAN" ElseIf IsNetConnectViaModem() = True Then Lbltype.Caption = "Modem" ElseIf IsNetConnectViaProxy() = True Then Lbltype.Caption = "Proxy" Else Lbltype.Caption = "Inconnu" End If Else LblConnect = "Non connecté" Lbltype.Caption = "" End If End Sub Public Function IsNetConnectOnline() As Boolean IsNetConnectOnline = InternetGetConnectedState(0&, 0&) End Function Public Function IsNetConnectViaLAN() As Boolean Dim dwFlags As Long Call InternetGetConnectedState(dwFlags, 0&) IsNetConnectViaLAN = dwFlags And INTERNET_CONNECTION_LAN End Function Public Function IsNetConnectViaModem() As Boolean Dim dwFlags As Long Call InternetGetConnectedState(dwFlags, 0&) IsNetConnectViaModem = dwFlags And INTERNET_CONNECTION_MODEM End Function Public Function IsNetConnectViaProxy() As Boolean Dim dwFlags As Long Call InternetGetConnectedState(dwFlags, 0&) IsNetConnectViaProxy = dwFlags And INTERNET_CONNECTION_PROXY End Function |