Results 1 to 2 of 2

Thread: DIsconnecting the modem

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Location
    Singapore
    Posts
    3

    Cool

    Hi, need help from whoever know how to do it.

    From my VB program, I shell a application to dial thru modem to get some information from some hardware. Then I kill that application, but my modem is still connected. How to disconnect the modem?

    Another thing is how to detect the modem is connected? I am not using Dialup Network and not connected to internet. How to check the status?

    Thanks for helping.

  2. #2
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    You can use this to see if there's a connection active:
    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:
    
    If ActiveConnection Then MsgBox "The modem is currently connected"
    I'm not sure about how to force it to cut off. Just above, if lpData has some value other than 0, it means there's a connection. Perhaps if you write 0 into that section of the registry, it will force the connection to stop, but I've never tried using the registry other than to look at something.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

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