Library tutorials & articles
Controlling Dial Up Networking using the WinInet API
- Introduction
- Are we connected?
- 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.
Related articles
Related discussion
-
Run-time error '91'
by crazyidane (0 replies)
-
Problem handling Redirects with MSXML2.XMLHTTP
by brandoncampbell (2 replies)
-
vbinputbox pauses code while it waits on response. How can I reproduce that?
by brandoncampbell (1 replies)
-
Sending SMS in VB 6
by sirobnole (6 replies)
-
Comboxbox listindex in ActiveX Control
by brandoncampbell (1 replies)
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...!
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
Does someone know how to hide dial-up dialog box?
How can I prevent the dial up dialog box from being displayed?
ummmm i'm confused Farad'n, what exactly do you mean rip from a COM server?
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
okay well heres a quicky....
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 INTERNETAUTODIALFORCEUNATTENDED = 2&
Private Const INTERNETAUTODIALFAILIFSECURITYCHECK = 4&
Public Enum AutoDialsFlags
ADFFORCEONLINE = INTERNETAUTODIALFORCEONLINE
ADFFORCEUNATTENDED = 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!
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.
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?
This thread is for discussions of Controlling Dial Up Networking using the WinInet API.