Test computer with an internet connection ?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: Test computer with an internet connection ?

  1. #1
    Join Date
    Sep 2007
    Posts
    197

    Test computer with an internet connection ?

    I want to search the code your computer with an internet connection, note: not the case on or off the network card

  2. #2
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,091

    Re: Test computer with an internet connection ?

    You need to use the InternetGetConnectedState API, here is a small example I have which I porbably downloaded a long time ago from someone somewhere, or made myself - Honestly, I cannot remember :

    Code:
    Option Explicit
    
    Private Declare Function InternetGetConnectedState Lib "wininet" (ByRef dwflags As Long, _
    ByVal dwReserved As Long) As Long
    
    Private Const CONNECT_LAN As Long = &H2
    Private Const CONNECT_MODEM As Long = &H1
    Private Const CONNECT_PROXY As Long = &H4
    Private Const CONNECT_OFFLINE As Long = &H20
    Private Const CONNECT_CONFIGURED As Long = &H40
    
    Public Function IsWebConnected(Optional ByRef ConnType As String) As Boolean
    
    Dim dwflags As Long
    Dim WebTest As Boolean
    ConnType = ""
    WebTest = InternetGetConnectedState(dwflags, 0&)
    Select Case WebTest
    Case dwflags And CONNECT_LAN: ConnType = "LAN"
    Case dwflags And CONNECT_MODEM: ConnType = "Modem"
    Case dwflags And CONNECT_PROXY: ConnType = "Proxy"
    Case dwflags And CONNECT_OFFLINE: ConnType = "Offline"
    Case dwflags And CONNECT_CONFIGURED: ConnType = "Configured"
    End Select
    IsWebConnected = WebTest
    End Function
    
    Private Sub Command1_Click()
    
    Dim msg As String
    If IsWebConnected(msg) Then
    msg = "You are connected to the Internet via: " & msg
    Else
    msg = "You are not connected to the Internet."
    End If
    MsgBox msg, vbOKOnly, "Internet Connection Status"
    End Sub

  3. #3
    Join Date
    Sep 2007
    Posts
    197

    Re: Test computer with an internet connection ?

    Your example code is incorrect results if the network card icon in the system tray of bright windows, then your code has internet connection(You are connected to the Internet via...), network card icon on the system tray clock am not sure if internet

  4. #4
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Test computer with an internet connection ?

    just shell "ping google.com" > File name
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center