Library tutorials & articles
Controlling Dial Up Networking using the WinInet API
- Introduction
- Are we connected?
- Connecting & Disconnecting
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.
Related articles
Related discussion
-
Automating Excel from VB6.0
by epurdy (0 replies)
-
VB6 system conversion using VBA to Word 2007
by b.macgregor@vodamail.co.za (0 replies)
-
video not working with visual basic
by Jupiter 2 (9 replies)
-
Hyperterminal Data
by sengreen (1 replies)
-
vb6 - custom font
by Ruffsta3 (0 replies)
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...
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?
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.