' 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
|