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?
Printable View
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?
Ping a site that is usually online.
VB Code:
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 [url]www.google.com[/url] >> D:\ping.txt", "D:\", SW_SHOWNORMAL Shell "notepad D:\ping.txt", SW_SHOWNORMAL End Sub
You can also try this to
VB Code:
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