Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Internet Connections

Posted on 2000-05-10
Medium Priority
Last Modified: 2010-05-02
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.
Question by:johnczimm
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
LVL 28

Expert Comment

ID: 2796536

may point you to answer some of your questions

Expert Comment

ID: 2796551

'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 --'
LVL 28

Expert Comment

ID: 2796575
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 2796594
"Determining Network Connections with InternetGetConnectedState"

"Determining an Active Internet Dialup Connection"

Accepted Solution

Ruchi earned 600 total points
ID: 2796609
"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."

Author Comment

ID: 2797325
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.

LVL 28

Expert Comment

ID: 2798082
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

Author Comment

ID: 2819070
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.

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question