AutoDial with WinInet API

This is an addition to my collection of the Windows Inet DLL functions. Shows how to Auto-Dial without the user having to insert usernames and passwords. All Automated!

Simply insert this into a module:

Option Explicit
Private Declare Function InternetAutodial Lib "wininet.dll" (ByVal dwFlags As Long, ByVal hwndParent As Long) As Long
Private Const INTERNET_AUTODIAL_FORCE_ONLINE = 1&
Private Const INTERNET_AUTODIAL_FORCE_UNATTENDED = 2&
Private Const INTERNET_AUTODIAL_FAILIFSECURITYCHECK = 4&
Public Enum AutoDialsFlags
   ADF_FORCE_ONLINE = INTERNET_AUTODIAL_FORCE_ONLINE
   ADF_FORCE_UNATTENDED = INTERNET_AUTODIAL_FORCE_UNATTENDED
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 INTERNET_AUTODIAL_FAILIFSECURITYCHECK
   lRetValue = InternetAutodial(lFlags, hwndParentWindow)
   If lRetValue <> 0 Then Autodial = True Else Autodial = False
ErrHandle:
   Exit Function
End Function


then call the function to autodial like this:

Autodial hWnd, ADF_FORCE_UNATTENDED, True


This would be a godsend to those writing download managers etc!

You might also like...

Comments

Thushan Fernando Senior Developer working at Readify on cool new technology and platforms.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity.” - Dennis Ritchie