Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleSee if the modem is connected
Keywordsmodem, connected, disconnected
CategoriesUtilities
 
Thanks to Bob Askey.

Use the RegQueryValueEx API function to examine the System Registry. In the HKEY_LOCAL_MACHINE section, check the following key:

    System\CurrentControlSet\Services\RemoteAccess

Look at the value

Remote Connection
.
 
' Return True if the modem is connected.
' (Actually this also returns False if there is
' an error reading the registry.)
Function ModemIsConnected() As Boolean
Dim result As Long
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

    ModemIsConnected = False

    lpSubKey = _
        "System\CurrentControlSet\Services\RemoteAccess"
    If RegOpenKey(HKEY_LOCAL_MACHINE, lpSubKey, phkResult) _
        <> ERROR_SUCCESS Then Exit Function

    hKey = phkResult
    lpValueName = "Remote Connection"
    lpReserved = APINULL
    lpType = APINULL
    lpData = APINULL
    lpcbData = APINULL

    If RegQueryValueEx(hKey, lpValueName, lpReserved, _
        lpType, ByVal lpData, lpcbData) _
        <> ERROR_SUCCESS _
    Then
        RegCloseKey hKey
        Exit Function
    End If
    lpcbData = Len(lpData)

    If RegQueryValueEx(hKey, lpValueName, lpReserved, _
        lpType, lpData, lpcbData) _
        <> ERROR_SUCCESS _
    Then
        RegCloseKey hKey
        Exit Function
    End If

    ModemIsConnected = (lpData <> 0)

    RegCloseKey hKey
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated