PDA

Click to See Complete Forum and Search --> : Checking for an Internet connection


mocsr123
Oct 10th, 2005, 09:12 PM
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?

dglienna
Oct 10th, 2005, 09:47 PM
Ping a site that is usually online.

Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

Private Const SW_SHOWNORMAL As Long = 1
Private Const SW_HIDE As Long = 0

Private Sub Command1_Click()
ShellExecute Me.hwnd, "Open", "C:\Windows\System32\CMD.exe", " /c ping www.google.com >> D:\ping.txt", "D:\", SW_SHOWNORMAL
Shell "notepad D:\ping.txt", SW_SHOWNORMAL
End Sub

dreamvb
Oct 10th, 2005, 09:49 PM
You can also try this to


Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" _
(ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long

Private Sub Form_Load()
Dim IsConnected As Boolean

IsConnected = InternetCheckConnection("http://www.google.com", &H1, ByVal 0&)

If Not IsConnected Then
MsgBox "No Internet Connection Found", vbExclamation
Else
MsgBox "Your connected to the internet", vbInformation
End If

End Sub