Solved

Internet Connections

Posted on 2000-05-10
8
242 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
ID: 2796536
http://www.shrinkwrapvb.com/vbras_hu.htm

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

Expert Comment

by:Ruchi
ID: 2796551
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
ID: 2796575
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 9

Expert Comment

by:Ruchi
ID: 2796594
"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
 
LVL 9

Accepted Solution

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

Author Comment

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

0
 
LVL 28

Expert Comment

by:Ark
ID: 2798082
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
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.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
using web browser with BING 40 132
Access Object Property from VBA Module in Excel 2010 2 37
Add and format columns in vb6 7 63
Recommendation vb6 to vb.net or others 14 178
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

820 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