Results 1 to 4 of 4

Thread: Pls help: Internet connection state

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Posts
    219
    Does anyone know how to get the internet connection state in VB?

  2. #2
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    Next time if you want a quicker response use "SEARCH" thats where this came from . It was originaly posted by Mathew Gates
    Code:
    To detect Internet connection: 
    
    
    
    code:--------------------------------------------------------------------------------'In a module
    
    Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey _
    As Long) As Long
    
    Declare Function RegOpenKey Lib "advapi32.dll" _
    Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As _
    String, phkResult As Long) As Long
    
    Declare Function RegQueryValueEx Lib "advapi32.dll" _
    Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal _
    lpValueName As String, ByVal lpReserved As Long, lpType As _
    Long, lpData As Any, lpcbData As Long) As Long
    
    Public Const ERROR_SUCCESS As Long = 0
    Public Const APINULL As Long = 0
    Public Const HKEY_LOCAL_MACHINE As Long = &H80000002
    
    Public Function ActiveConnection() As Boolean
       
       Dim hKey As Long
       Dim lpSubKey As String
       Dim phkResult As Long
       Dim lpValueName As String
       Dim lpReserved As Long
       Dim lpType As Long
       Dim lpData As Long
       Dim lpcbData As Long
       Dim ReturnCode As Long
       
       ActiveConnection = False
       
       lpSubKey = "System\CurrentControlSet\Services\RemoteAccess"
       
       ReturnCode = RegOpenKey(HKEY_LOCAL_MACHINE, lpSubKey, phkResult)
       
       If ReturnCode = ERROR_SUCCESS Then
          hKey = phkResult
          lpValueName = "Remote Connection"
          lpReserved = APINULL
          lpType = APINULL
          lpData = APINULL
          lpcbData = APINULL
          
          ReturnCode = RegQueryValueEx(hKey, lpValueName, _
          lpReserved, lpType, ByVal lpData, lpcbData)
          
          lpcbData = Len(lpData)
          
          ReturnCode = RegQueryValueEx(hKey, lpValueName, _
          lpReserved, lpType, lpData, lpcbData)
          
          If ReturnCode = ERROR_SUCCESS Then
             If lpData = 0 Then
                ActiveConnection = False
             Else
                ActiveConnection = True
             End If
          End If
             
          RegCloseKey (hKey)
       End If
       
    End Function
    
    
    Usage
    
    'In form1's Timer:
    
    
    Private Sub Timer1_Timer()
    If ActiveConnection Then 
    Caption = "Internet Connection Detected!"
    Else
    Caption = "No Internet Connection Detected!"
    End Sub
    []P
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  3. #3
    Hyperactive Member marnitzg's Avatar
    Join Date
    Oct 2000
    Location
    South Africa
    Posts
    372
    This is smaller and works if the machine was reset while still connected to the internet. The other one returns true even if not connected after this happens. But yes, this comes off the VB-World site!!!!!
    Code:
    Private Declare Function InternetGetConnectedState _
    Lib "wininet.dll" (ByRef lpSFlags As Long, _
    ByVal dwReserved As Long) As Long
    
    Private Const INTERNET_CONNECTION_MODEM As Long = &H1
    
    Public Function ViaModem() As Boolean
    
    Dim SFlags As Long
    'return the flags associated with the connection
    Call InternetGetConnectedState(SFlags, 0&)
    
    'True if the Sflags has a modem connection
    ViaModem = SFlags And INTERNET_CONNECTION_MODEM
    
    End Function
    
    
    Private Sub Command1_Click()
    If ViaModem Then MsgBox "Connected"
    End Sub

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Sep 2000
    Posts
    219
    Thanks guys.

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