Library tutorials & articles

Controlling Dial Up Networking using the WinInet API

Page 3 of 3
  1. Introduction
  2. Are we connected?
  3. Connecting & Disconnecting

Connecting & Disconnecting

So now how do you connect to the ISP of the EU if they are not connected to do your things? Easy just go back to your oh faithful WinInet API.

Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetAttemptConnect Lib "WinInet" (ByVal dwReserved As Long) As Long
Const scUserAgent = "WinInet Example"
Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Public Function ConnectToISP() As Boolean
   If InternetAttemptConnect(0) <> 0 Then Exit Function
   If InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0) = 0 Then ConnectToISP = False Else ConnectToISP = True
End Function

How about hanging Up the darn modem? Yep you guessed it... back to the WinInet API.

Private Declare Function InternetAutodialHangup Lib "wininet.dll" (ByVal dwReserved_ As Long) As Long
Public Function HangUpModem() As Boolean
    If InternetAutodialHangup(0&) = 0 Then HangUpModem = False Else HangUpModem = True
End Function

There! Three functions you'll need if you are wanting to make an internet related application which may require you to connect/disconnect and check the status of hte connection to continue.

Remember to use the Windows API as much as possible when checking for stuff related to the system. Not only is it faster but its most likely easier for you as the developer to use the API function than searching Registry Keys or other things. Next time around I'll show you how to get some information about the Dialup Networking Connection. I've attached a VB6 project so you can add that module to your projects. If your a VB5 user open the .VBP file in Notepad and remove the 'Retained' key.

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).

AddThis

Related discussion