[RESOLVED] how to know the internet connection is available or not?
hi guys
I#m new in VB and this forum..
I have question about, the synbtax to recognize an internet connection.
so, I want to make a program that automatically start when the internet is online or when its connected to the LAN..
can u guys help me with the syntax necessary?
Re: how to know the internet connection is available or not?
One API call:
Declarations:
VB Code:
Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
Private Const FLAG_ICC_FORCE_CONNECTION = &H1
Code Neccessary:
VB Code:
If InternetCheckConnection("http://www.google.com/", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
MsgBox "Connection to google failed!", vbInformation
Else
MsgBox "Connection to google succeeded!", vbInformation
End If
That should do it.
Re: how to know the internet connection is available or not?
but that means, if the LAN available but the internet does not, it will have failed message..
I was thinking about checking the activities in komputer port. or there is much more simple way to do it?
where can i find the documentation of that function?
thanks
Re: how to know the internet connection is available or not?
That should tell you if you are connected to a network. It will also tell you which type.
VB Code:
Const NETWORK_ALIVE_AOL = &H4
Const NETWORK_ALIVE_LAN = &H1
Const NETWORK_ALIVE_WAN = &H2
Private Declare Function IsNetworkAlive Lib "SENSAPI.DLL" (ByRef lpdwFlags As Long) As Long
Private Sub Form_Load()
Dim Ret As Long
If IsNetworkAlive(Ret) = 0 Then
MsgBox "The local system is not connected to a network!"
Else
MsgBox "The local system is connected to a " + IIf(Ret = NETWORK_ALIVE_AOL, "AOL", IIf(Ret = NETWORK_ALIVE_LAN, "LAN", "WAN")) + " network!"
End If
End Sub
Re: how to know the internet connection is available or not?
ok bro now i understand now.. thank you a lot for helping me..
thanks