Internet Connections

I am looking for a small sample app that will show me how to pick an Internet connection, either a RAS connection or LAN connection.  Check to see if a connection to the Internet connection is established, and determine if the connection has been dropped.  I am creating an application that will be able to do updates via the Internet.  When the user clicks on the Update button, I need the program to go out to the Internet and pull down the latest information.  I know how to use FTP and that part works fine.  I want the user to pick the Internet connection they want to use in an option menu so that when they click the Update button the program will automatically connect and pull down the files.  I have a few users that have a LAN connection to the Internet but do not want to use this to due the update, they want to use a dial-up session, don’t ask me why.  One problem I’m having is that the program always tries to use the LAN connection. Does anyone know of a good sample app that I can take a look at?  Please let me know ASAP.  Thanks in advance.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

RuchiConnect With a Mentor Commented:
"There are some WinInet API functions that allow establishing and breaking connection, to define the presence of current Internet connection and its properties. WinInet is responsible for controlling the state of system. There are two states: Offline and Online."

may point you to answer some of your questions

'Add this code to a Module:
Option Explicit

Declare Function RasEnumConnections Lib "RasApi32.dll" Alias _
        "RasEnumConnectionsA" (lpRasCon As Any, lpcb As Long, _
        lpcConnections As Long) As Long

Declare Function RasGetConnectStatus Lib "RasApi32.dll" Alias _
        "RasGetConnectStatusA" (ByVal hRasCon As Long, _
        lpStatus As Any) As Long

Public Const RAS95_MaxEntryName = 256
Public Const RAS95_MaxDeviceType = 16
Public Const RAS95_MaxDeviceName = 32

Public Type RASCONN95
   dwSize As Long
   hRasCon As Long
   szEntryName(RAS95_MaxEntryName) As Byte
   szDeviceType(RAS95_MaxDeviceType) As Byte
   szDeviceName(RAS95_MaxDeviceName) As Byte
End Type

   dwSize As Long
   RasConnState As Long
   dwError As Long
   szDeviceType(RAS95_MaxDeviceType) As Byte
   szDeviceName(RAS95_MaxDeviceName) As Byte
End Type

Public Function IsConnected() As Boolean

   Dim TRasCon(255) As RASCONN95
   Dim lg As Long
   Dim lpcon As Long
   Dim RetCDec As Long
   Dim Tstatus As RASCONNSTATUS95

   TRasCon(0).dwSize = 412
   lg = 256 * TRasCon(0).dwSize

   RetCDec = RasEnumConnections(TRasCon(0), lg, lpcon)
   Tstatus.dwSize = 160
   RetCDec = RasGetConnectStatus(TRasCon(0).hRasCon, Tstatus)

   If Tstatus.RasConnState = &H2000 Then
      IsConnected = True
      IsConnected = False
   End If

End Function

'From anywhere in code use this to check if there is an active connection:

Dim cActive As Boolean
cActive = IsConnected
'-- End --'
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

"Determining Network Connections with InternetGetConnectedState"

"Determining an Active Internet Dialup Connection"
johnczimmAuthor Commented:
Somehow this question was posted twice.  I'll delete the other one, but for future reference:
mdougan posted comment:
I don't have any sample code for this, but I can give you a few things to think about.  First, the reason that some users don't want to do the update through their LAN connections is that they are probably connected to the Internet through a Proxy Server and this server may not allow any FTP (it's pretty standard security to disable the port for that in many companies).  So, by using a modem connection they could get by that restriction.

I know that the names of the RAS dial-ups are stored in the registry, but I can't remember which registry key they are under.  Most likely if you use REGEDIT.EXE and search HKEY_CURRENT_USER or HKEY_LOCAL_MACHINE you'll find the name of one of yours, and you'll be able to see the structure.  Then, it would just be a matter of writing the code in your app to search the registry to pull out the names of each of the RAS Dial-Ups into your listbox.

I also don't know off the top of my head what the command is to fire off the dial-up, but if you right-click the shortcut to one in your MyComputer/Dial-up folder, and look at the shortcut, you'll be able to code the same thing in a Shell statement in VB to kick off the dial-up.

Since you don't want to use the LAN connection in many cases, I think that you should always pop up a dialog box that has each of the dial-ups listed and an option button that says use a dial-up connection, and another that says use a LAN connection.  If the user selects the RAS option and selects a dial-up name, then you should shell out to run the dialer.  If the user selects the LAN option, then you could try to retrieve a web page to test the connection, if it fails, then you have to prompt the user that they do not have an active LAN connection, and put them back in the dialog for choosing a dial-up instead.

Take a look on my code at
There are 3 ways to determine Internet connection. First way is for RAS connection only, second and third are for RAS/LAN. Each method have it's own advantages and disadvantages and they  are included within the application. You can combine two methods (1 and 2). If your users connect via proxy, second method always return True, but first return true only if you are connected via modem. Then, if first method return false, you can use Azra's link to establish Dial Up connection or simply:

Public Sub Connect(strConnectName As String, blnPressConnect As Boolean)

Shell "rundll32.exe rnaui.dll,RnaDial " & strConnectName, 0

If (blnPressConnect = True) Then
  SendKeys "{ENTER}"
End If

End Sub

Private Sub cmdConnect_Click()
Connect "Freeserve", True
End Sub
johnczimmAuthor Commented:
Thanks for the tips.  Sorry it took so long to get back to the question, but I was trying to finish the program.  When I get the program up and running I'll post a link to it under this question so that you can take a look at it.  Thanks to all that have helped.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.