Library tutorials & articles

Controlling Dial Up Networking using the WinInet API

Introduction

This article explains the basics of controling your DUN([D]ial [U]p [N]etworking) via the WinInet API Function to see if theres an active connection, dial a connection if there isnt or hangup if there is.If your working on a browser based or something to do with the internet then this article may help you.

I've seen many people using the following to get the status of the internet connection:

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

The above code was taken from a project by someone else, and I DON'T TAKE ANY CREDIT FOR IT. The code is alright if you arr prepared to add the API functions for the Windows Registry. But if your like me, I like to do things and keep the code to the minimal. I usually code my functions into a handy DLL (ActiveX DLL-[D]ynamic [L]ink [L]ibrary) which I use it mostly all my projects. Its easier and more efficent in some ways. If you were to add the above code to a DLL then you would add the registry code or add dependencies to one.

Comments

  1. 09 Jul 2005 at 06:24

    Hi guys does anybody in this place have any idea of how to create a shortcut to an existing dial-up connection in VB (or any language)???
    I'm sick of searching this,i'm searching this for around a month without any success..
    if you guys have any idea just let me know..i'm so greatful for that..
    Thushan i hope you'll have some solution on this matter as you seems like pretty concern on this subject..
    thank you...!

  2. 19 Jun 2004 at 05:24
    Quote:
    [1]Posted by misslav on 2 Apr 2004 02:33 AM[/1]
    Does someone know how to hide dial-up dialog box?


    i have teh same issue and can't find a solution. do you found out how to do it?
    cheers
    daniel
  3. 02 Apr 2004 at 02:33

    Does someone know how to hide dial-up dialog box?

  4. 03 Feb 2004 at 06:12
    How can I prevent the dial up dialog box from being displayed?
  5. 16 Dec 2003 at 16:07

    ummmm i'm confused Farad'n, what exactly do you mean rip from a COM server?

  6. 16 Dec 2003 at 14:21

    Just have to check the auto dial on the  dun windows and that will be it. of coarse you loose a securyty level by bi-passing the user name and password but if the dun windows would not be showed that securety level would be bi-pass any way... i believe the user is aloud to be aware that the modem is or could be dialing long distance.. so the only use for the disaperance of the dun window would be for develorer witch have bad intention and usualy those dont know how to programe well and dont know how to work api well. i think they should do like  all beguiner and get ripp'of by getting ocx and activex control and get the under running code that come's whit it (since those that make activex only mmake a nice pakage of api fonction that look that do only one thing but does alote of other that run in back coding)


    any way have fun making your little rip


    farad'n

  7. 28 Jun 2002 at 02:07

    okay well heres a quicky....


    Code:

    Option Explicit
    Private Declare Function InternetAutodial Lib "wininet.dll" (ByVal dwFlags As Long, ByVal hwndParent As Long) As Long
    Private Const INTERNETAUTODIALFORCEONLINE = 1&
    Private Const INTERNET
    AUTODIALFORCEUNATTENDED = 2&
    Private Const INTERNETAUTODIALFAILIFSECURITYCHECK = 4&
    Public Enum AutoDialsFlags
       ADFFORCEONLINE = INTERNETAUTODIALFORCEONLINE
       ADF
    FORCEUNATTENDED = INTERNETAUTODIALFORCEUNATTENDED
    End Enum


    Public Function Autodial(hwndParentWindow As Long, lOption As AutoDialsFlags, Optional bFailIfSecurityCheck As Boolean = True) As Boolean
    Dim lFlags As Long, lRetValue As Long
    On Error GoTo ErrHandle
       If bFailIfSecurityCheck Then lFlags = lOption Or INTERNETAUTODIALFAILIFSECURITYCHECK
       lRetValue = InternetAutodial(lFlags, hwndParentWindow)
       If lRetValue <> 0 Then Autodial = True Else Autodial = False
    ErrHandle:
       Exit Function
    End Function



    call it like this to get AutoDial without just showing the dialog:


    Autodial hWnd, ADFFORCEUNATTENDED, True


    I had exams last 2 weeks so I'm not really in the mood to write any tutorials yet. Give me some time off and I will(its holidays now - woohoooo! )


    Hope that helps!


    Good Luck!

  8. 28 Jun 2002 at 01:59

    hey,


    thanks. I am working on Part II of this tutorial which will tell you how to do Auto-Dialing and some other cool features and wrap it all in a nice class module.


    If you cant wait till then I can send you a partly completed code by email. Its not commented yet though.

  9. 27 Jun 2002 at 23:19

    The codes look nice. But what if my ISP require password and username for authentication? When i run the codes, my modem doesn't autodial?

  10. 01 Jan 1999 at 00:00

    This thread is for discussions of Controlling Dial Up Networking using the WinInet API.

Leave a comment

Sign in or Join us (it's free).

Thushan Fernando Currently I'm working at Hammond Street Developments Pty Ltd. My time on DeveloperFusion is limited due to workloads, I do however keep a Blog that gets updated fairly regularly with lots of Techno...

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

We'd love to hear what you think! Submit ideas or give us feedback