Visual Basic Programming Code Examples Visual Basic > API and Miscellaneous Code Examples Finding Out If A Computer Is Connected To The Internet Finding Out If A Computer Is Connected To The Internet Public Declare Function RasEnumConnections Lib "RasApi32.dll" _ Alias "RasEnumConnectionsA" (lpRasCon As Any, lpcb As Long, _ lpcConnections As Long) As Long Public Declare Function RasGetConnectStatus Lib "RasApi32.dll" _ Alias "RasGetConnectStatusA" (ByVal hRasCon As Long, _ lpStatus As Any) As Long Public Const RAS95_MaxEntryName = 256 Public Const RAS95_MaxDeviceType = 16 Public Const RAS95_MaxDeviceName = 32 Public Type RASCONN95 dwSize As Long hRasCon As Long szEntryName(RAS95_MaxEntryName) As Byte szDeviceType(RAS95_MaxDeviceType) As Byte szDeviceName(RAS95_MaxDeviceName) As Byte End Type Public Type RASCONNSTATUS95 dwSize As Long RasConnState As Long dwError As Long szDeviceType(RAS95_MaxDeviceType) As Byte szDeviceName(RAS95_MaxDeviceName) As Byte End Type Public Function IsConnected() As Boolean 'Dimension Variables. Dim TRasCon(255) As RASCONN95 Dim lg As Long Dim lpcon As Long Dim RetVal As Long Dim Tstatus As RASCONNSTATUS95 'Find out whether the target computer is connected. TRasCon(0).dwSize = 412 lg = 256 * TRasCon(0).dwSize RetVal = RasEnumConnections(TRasCon(0), lg, lpcon) If RetVal <> 0 Then 'An error has occured. Handle it here. Exit Function End If Tstatus.dwSize = 160 RetVal = RasGetConnectStatus(TRasCon(0).hRasCon, Tstatus) 'Return whether we are connected or not. If Tstatus.RasConnState = &H2000 Then IsConnected = True Else IsConnected = False End If End Function