Link to home
Start Free TrialLog in
Avatar of johnczimm
johnczimm

asked on

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.
Avatar of AzraSound
AzraSound
Flag of United States of America image

http://www.shrinkwrapvb.com/vbras_hu.htm

may point you to answer some of your questions
Avatar of Ruchi
Ruchi

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 --'
"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
ASKER CERTIFIED SOLUTION
Avatar of Ruchi
Ruchi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of johnczimm

ASKER

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.

Avatar of Ark
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
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.