Results 1 to 8 of 8

Thread: check for dialup connection

  1. #1

    Thread Starter
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930

    Question

    Can anyone tell me if there's a way to check to see if a dial up connection is already active with VB, and establish one if there isn't? It's for my cheapie browser, and I'm getting lazy in my old age

  2. #2
    Guest
    Detect Internet Connection:

    Code:
    Public Const ERROR_SUCCESS = 0&
    Public Const APINULL = 0&
    Public Const HKEY_LOCAL_MACHINE = &H80000002
    Public ReturnCode As Long
    
    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
                    
    Code
    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
    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 = True then
        Call MsgBox("You have an active connection.",vbInformation)
    Else
        Call MsgBox("You have no active connections.", vbInformation)
    End If
    To establish one:

    Code:
    Private Const INTERNET_AUTODIAL_FORCE_ONLINE = 1
    Private Const INTERNET_AUTODIAL_FORCE_UNATTENDED = 2
    
    
    Private Declare Function InternetAutodial Lib "wininet.dll" _
        (ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
    
    
    Usage
    
    InternetAutodial INTERNET_AUTODIAL_FORCE_UNATTENDED, 0

  3. #3

    Thread Starter
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930

    dialup stuff

    Thanks for that big chunk of code there. About the connection establishing thing, how does it know _what_ it's calling though? Or how can I pass it my dialup number before I force it to connect?

  4. #4
    Guest
    If you prefer to dial yourself, here is how:

    Code:
    Dim X
    '"ConnectionsName" is the name under the icon in Dial-up Networking
    X = Shell("rundll32.exe rnaui.dll,RnaDial " & "ConnectionsName", 1)
    DoEvents
    'You can type in your password before the { below.
    SendKeys "{enter}", True
    DoEvents

  5. #5

    Thread Starter
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930

    dialup stuff

    I tried the longer API method to force a connection, but it didn't seem to work. I stuck a thing to activate it in a command button, but when pressed, the hd did some stuff, and just sat there. The other way worked fine though, so I'll use that. What do the INTERNET_AUTODIAL_FORCE_ONLINE and INTERNET_AUTODIAL_FORCE_UNATTENDED constants do? I notice you only used one. The thing to check for a connection worked perfectly. Thanks. BTW, how do you make your VB code in the message look like it was done in the VB environment?

  6. #6
    Guest
    [code]your text[/code]

    I will get back to you with the answer to your question (I am in school right now) .

  7. #7
    Guest
    Okay, I'm home right now..until tomorrow at 6:45 AM when skool starts again .

    Here is the answer to your question:

    INTERNET_AUTODIAL_FORCE_ONLINE = To prompt the user to connect to the Net

    INTERNET_AUTODIAL_FORCE_UNATTENDED = To automatically start dialing

    Unfortunately, as you said, it doesn't work. I guess the code is crappy, sorry about that.

  8. #8

    Thread Starter
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    School is great isn't it? I'm in grad school, so it's not really bad. Anyway, that stuff you mentioned went way over my head. I've never even seen some of that code before, ever. Since you mentioned that WebBrowser event where I can get the address from, I can just set up a keypress that will download something. Thanks.

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