Results 1 to 3 of 3

Thread: Detecting an Internet connection

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    At my computer
    Posts
    187
    I want to make an application which does something (say, display a message box) every time the user connects to the Internet. Does anyone know how I can do this?

    [Edited by Allen Schoessler on 09-26-2000 at 07:20 PM]
    - Visual Basic 6.0
    - Windows XP Home

  2. #2
    Guest
    Try this:

    Code:
    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
    Dim TRasCon(255) As RASCONN95
    Dim lg As Long
    Dim lpcon As Long
    Dim RetVal As Long
    Dim Tstatus As RASCONNSTATUS95
    '
    TRasCon(0).dwSize = 412
    lg = 256 * TRasCon(0).dwSize
    '
    RetVal = RasEnumConnections(TRasCon(0), lg, lpcon)
    If RetVal <> 0 Then
                        MsgBox "ERROR"
                        Exit Function
                        End If
    '
    Tstatus.dwSize = 160
    RetVal = RasGetConnectStatus(TRasCon(0).hRasCon, Tstatus)
    If Tstatus.RasConnState = &H2000 Then
                             IsConnected = True
                             Else
                             IsConnected = False
                             End If
    
    End Function
    
    
    
    Usage:
    
    Private Sub Command1_Click()
    If IsConnected() <> 0 Then
    Msgbox "Connected!"
    Else
    Msgbox "Not Connected!"
    End If
    End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2000
    Location
    At my computer
    Posts
    187

    Thumbs up

    Thanks a bunch, that's exactly what I needed!

    Allen
    - Visual Basic 6.0
    - Windows XP Home

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width