Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Check for Internet connection


Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" Alias _
"InternetGetConnectedStateExA" (lpdwFlags As Long , lpszConnectionName As Long , _
dwNameLen As Long , ByVal dwReserved As Long ) As Long

Function IsConnected() As Boolean
   Dim lNameLen             As Long
   Dim lRetVal              As Long
   Dim lConnectionFlags     As Long
   Dim LPTR                 As Long
   Dim lNameLenPtr          As Long
   Dim sConnectionName      As String
  sConnectionName = Space$(256)
  lNameLen = 256
  LPTR = StrPtr(sConnectionName)
  lNameLenPtr = VarPtr(lNameLen)
  lRetVal = InternetGetConnectedStateEx(lConnectionFlags, ByVal LPTR, ByVal lNameLen, 0&)
  IsConnected = (lRetVal <> 0)
End Function

'also, info is in the registry
HKEY_LOCAL_MACHINE \ System \ CurrentControlSet \ Services \ RemoteAccess \ Remote Connection Is non zero.