Furqan Sehgal
Furqan Sehgal

Reputation: 4997

Detecting if Internet is connected

How can I check through my application if computer is connected with internet or not (at the moment) I need a message if net is connected.

Thanks a lot Furqan

Upvotes: 2

Views: 3755

Answers (4)

Rangga Stephen
Rangga Stephen

Reputation: 11

Use this code :

If My.Computer.Network.IsAvailable Then
    MsgBox("Computer is connected.")
Else
    MsgBox("Computer is not connected.")
End If

Refer to this link.

Upvotes: 0

Joel Coehoorn
Joel Coehoorn

Reputation: 415735

Internet connectivity should be handled similar to file availability.

With files, you should typically not use File.Exists() to first see if you can open a file because the results might change on you between when you perform the check and when you act on the results, let alone the difference between mere existence and read permissions. You have to handle the exceptions anyway, and so that's really a better place to concentrate your efforts.

The same is true for internet access. The best option is generally to just go and do it, and concentrate your development time on your exception handler.

Upvotes: 2

MaQleod
MaQleod

Reputation: 999

ping. Dim response As Boolean = False response = My.Computer.Network.ping(google.com)

True, you have access, false, you don't, or the world is ending because google is offline.

Upvotes: 4

BitKFu
BitKFu

Reputation: 3697

I would try that. It's from VB 6, but I think you can easily convert it.

Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef
dwflags As Long, ByVal dwReserved As Long) As Long

Public Function IsOnline() As Boolean
Dim LFlags As Long
IsOnline = InternetGetConnectedState(LFlags, 0&)
End Function

http://bytes.com/topic/visual-basic/answers/14551-detecting-internet-connection

Upvotes: 3

Related Questions