Results 1 to 3 of 3

Thread: Checking for an Internet connection

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    9

    Checking for an Internet connection

    In my app that uses winsocks, if there is no Internet connection then the winsock gives an error when it tries to connect. How do I check if there is an Internet connection before I try to connect the winsock?

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: Checking for an Internet connection

    Ping a site that is usually online.

    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
    4. ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    5.  
    6. Private Const SW_SHOWNORMAL As Long = 1
    7. Private Const SW_HIDE As Long = 0
    8.  
    9. Private Sub Command1_Click()
    10.     ShellExecute Me.hwnd, "Open", "C:\Windows\System32\CMD.exe", " /c ping [url]www.google.com[/url] >> D:\ping.txt", "D:\", SW_SHOWNORMAL
    11.     Shell "notepad D:\ping.txt", SW_SHOWNORMAL
    12. End Sub

  3. #3
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    UK
    Posts
    417

    Re: Checking for an Internet connection

    You can also try this to

    VB Code:
    1. Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" _
    2. (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
    3.  
    4. Private Sub Form_Load()
    5. Dim IsConnected As Boolean
    6.  
    7.     IsConnected = InternetCheckConnection("http://www.google.com", &H1, ByVal 0&)
    8.    
    9.     If Not IsConnected Then
    10.         MsgBox "No Internet Connection Found", vbExclamation
    11.     Else
    12.         MsgBox "Your connected to the internet", vbInformation
    13.     End If
    14.    
    15. End Sub
    When your dreams come true.
    On error resume pulling hair out.

Posting Permissions

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



Click Here to Expand Forum to Full Width