>>
Home

>>
All About Me

>>
Books

>>
Events

>>
Links

>>
Photo Gallery

>>
Downloads

>>
Visual Basic .Net

>>
SE IERP

>>
FPU

>>
My Tubes



Login
Register

All content is the property of TimKey.Net unless noted otherwise in the content. All rights reserved




Check for internet connection

Posted by on Monday, November 08, 2004 (CST)

Ever need to check for an internet connection in your application? Here's how.

In order to check for an internet connection you need to use the Windows API function InternetGetConnectedState which returns either true or false.  You can also get the connection type from the dwFlags parameter.  In our example I will popup a dialog box but you can do what ever you deem necessary with the results according to your specific needs.

 

    'Declare the API function

    Private Declare Function InternetGetConnectedState Lib "wininet" _
        (ByRef dwFlags As Long, ByVal dwReserved As Long) As Long

    'Define possible connection types
    Private Enum ConnectStates
        LAN = &H2
        Modem = &H1
        Proxy = &H4
        Offline = &H20
        Configured = &H40
        RasInstalled = &H10
    End Enum

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim lng_dwFlags As Long
        Dim blnConnected As Boolean = (InternetGetConnectedState(lng_dwFlags, 0&) <> 0)
        Dim strMessage As String
        Dim ConnectionType As ConnectStates

        If blnConnected Then
            strMessage += "Computer is Connected" & ControlChars.NewLine

            'Display the connection flags
            strMessage += "Connection Flags: " & ControlChars.NewLine
            For Each connectiontype In _
                System.Enum.GetValues(GetType(ConnectStates))
                If (ConnectionType And lng_dwFlags) = ConnectionType Then
                    strMessage += "     " & ConnectionType.ToString() & ControlChars.NewLine
                End If
            Next
        End If

        MessageBox.Show(strMessage)
    End Sub


 

'This code does not verify that a connection is active just that the computer is currently configured for the internet.


Add Your Comment



Trinity Faith Fellowship

Most good judgment comes from experience. Most experience comes from bad judgment.
--- Anonymous

 

New Books

  • Enchanters' End Game
    Publishers Weekly
    "Absorbing. Touches all the right Fantasy bases. Warring gods, political intrigues, supernatural creatures, and appealingly human magicians."


  • The Misanthrope and Tartuffe
    Two classic plays translated by a Pulitzer Prize-winning poet into English verse. Introductions by Richard Wilbur.



  • Castle of Wizardry
    This is like Bonanza, or like I Love Lucy. There will be other fantasy series, but there can never be another that's so seminal, that so captures the essence of fantasy. Big Dave and Little Leigh grow their heroes from the ground up, and they grow the best.

  •  

    New Links

  • Kids and Guns
    My Daughter getting shooting lessons from my Dad. She should listen better...

  • QuickVerse Starter 2005
    Free KJV Bible for your PC. This is the best PC Bible software I have found anywhere and believe me I have looked and tested for years.

  • Free Bug Tracking Software
    Get your free version of PR-Tracker

  •  

    New Posts

  • on site visit
    Posted by linda on Friday, November 14, 2008 (CST)

  • ERP 5.2 Return Material Authorisation troubleshooting
    Posted by Noreen on Tuesday, August 12, 2008 (CST)

  • ERP 7.2 Buyers Workbench
    Posted by rcanavan on Wednesday, November 28, 2007 (CST)

  •  

    Most Popular Books
  • Loose That Man And Let Him Go
    FROM THE PUBLISHER
    Never in the history of the church has there been a time when God has so urgently stirred the hearts of men to become all He created them to be and accomplish all He created them to accomplish.


  • Why Do Men Have Nipples? Hundreds of Questions You'd Only Ask a Doctor After Your Third Martini
    Is There a Doctor in the House? You will laugh outloud as you read this book. This is one of my favorite books of all time. Told in a very humorous manner but with all seriousness, you will be enlightened about hundreds of areas of life we have al

  • Silent No More
    “Silent No More,” expounds upon the issues of our day, including judicial tyranny, race relations, poverty, homosexuality, Islam, education, and the right to life. Pastor Parsley provides practical action steps to engage readers and motivate them to act.


  • Home   |  All About Me   |  Books   |  Events   |  Links   |  Photo Gallery   |  Downloads   |  Visual Basic .Net   |  SE IERP   |  FPU   |  My Tubes