Adam Caudill

Security Leader, Researcher, Developer, Writer, & Photographer

IsOnline

This post was imported from an old blog archive, and predates the creation of AdamCaudill.com.

This is a simple function that checks to see if you’re online…

API: #

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: #

Public Function IsOnline() 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& )
    IsOnline = (lRetVal <> 0)
End Function

Returns true if you’re online, otherwise returns false. Simple eh?

Adam Caudill