Advertisement
3DotDev

Tester la connexion à Internet

Aug 24th, 2014
1,001
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.22 KB | None | 0 0
  1. Imports System.Runtime.InteropServices
  2. Imports System.Threading.Tasks
  3.  
  4. Public Class Cls_Internet
  5.  
  6. #Region " Enumerations "
  7.     Private Enum InternetConnectionStates
  8.         Unknown = 0
  9.         Modem = 1
  10.         LAN = 2
  11.         Proxy = 4
  12.         RasInstalled = 16
  13.         Offline = 32
  14.         Configured = 64
  15.     End Enum
  16. #End Region
  17.  
  18. #Region " Win32 "
  19.     <DllImport("wininet.dll")> _
  20.     Private Shared Function InternetGetConnectedState(ByRef lpdwFlags As InternetConnectionStates, dwReserved%) As Boolean
  21.     End Function
  22. #End Region
  23.  
  24. #Region " Methods "
  25.     Public Shared Function IsConnectedToInternet() As Boolean
  26.         Return Threading.Tasks.Task(Of Boolean).Factory.StartNew(Function() IsConnectedToInternet(InternetConnectionStates.Unknown)).Result
  27.     End Function
  28.  
  29.     Private Shared Function IsConnectedToInternet(ByRef connectionStates As InternetConnectionStates) As Boolean
  30.         Return InternetGetConnectedState(connectionStates, 0)
  31.     End Function
  32. #End Region
  33.  
  34. End Class
  35.  
  36.  
  37.  
  38. '############################### Comment l'utiliser ###########################
  39.  
  40. MsgBox(If(Cls_Internet.IsConnectedToInternet() = True, "Vous êtes connectés à Internet", "Vous n'êtes pas connectés à Internet"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement