Solved

Internet Connections

Posted on 2000-05-10
8
239 Views
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.
0
Comment
Question by:johnczimm
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
http://www.shrinkwrapvb.com/vbras_hu.htm

may point you to answer some of your questions
0
 
LVL 9

Expert Comment

by:Ruchi
Comment Utility
From http://hjem.get2net.dk/vcoders/cm/tips/internet_checkconnect.htm

'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

Public Type RASCONNSTATUS95
   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
   Else
      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 --'
0
 
LVL 28

Expert Comment

by:AzraSound
Comment Utility
0
 
LVL 9

Expert Comment

by:Ruchi
Comment Utility
"Determining Network Connections with InternetGetConnectedState"
http://www.mvps.org/vbnet/code/network/internetgetconnectedstate.htm

"Determining an Active Internet Dialup Connection"
http://www.mvps.org/vbnet/code/reg/activeconnect.htm
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 9

Accepted Solution

by:
Ruchi earned 200 total points
Comment Utility
"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."
http://www.vbip.com/wininet/wininet_connection_01.asp
0
 
LVL 1

Author Comment

by:johnczimm
Comment Utility
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.

0
 
LVL 27

Expert Comment

by:Ark
Comment Utility
Hi
Take a look on my code at http://www.freevbcode.com/ShowCode.Asp?ID=632
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
  DoEvents
  SendKeys "{ENTER}"
End If

End Sub

Private Sub cmdConnect_Click()
Connect "Freeserve", True
End Sub
 
Cheers
0
 
LVL 1

Author Comment

by:johnczimm
Comment Utility
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.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now