|
-
Oct 10th, 2005, 09:12 PM
#1
Thread Starter
New Member
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?
-
Oct 10th, 2005, 09:47 PM
#2
Re: Checking for an Internet connection
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
-
Oct 10th, 2005, 09:49 PM
#3
Hyperactive Member
Re: Checking for an Internet connection
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|