internetgetconnectedstate
Hello,
This is the code
VB Code:
Private Sub cmdgetstate_Click()
Dim lres As Long
lres = InternetGetConnectedState(lret, 0&)
If (lret And INTERNET_CONNECTION_CONFIGURED) = INTERNET_CONNECTION_CONFIGURED Then
MsgBox ("This system has a valid internet connection ")
End If
If (lret And INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN Then
MsgBox ("This system is connected to internet through LAN")
End If
If (lret And INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM Then
MsgBox ("This system is connected to internet through modem")
End If
If (lret And INTERNET_CONNECTION_OFFLINE) = INTERNET_CONNECTION_OFFLINE Then
MsgBox ("This system is presently offline")
End If
If (lret And INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY Then
MsgBox ("This system is connected to internet through proxy")
End If
If (lret And INTERNET_RAS_INSTALLED) = INTERNET_RAS_INSTALLED Then
MsgBox ("This system has RAS installed ")
End If
End Sub
Message box is being displayed only for INTERNET_CONNECTION_LAN and INTERNET_RAS_INSTALLED.
How come the function detecting the valid internet connection says "NO" , but the function detecting connection through lan says "YES"?
This being the case , how do I check to see if a user of my program is connected to the internet?
Thank you.
Re: internetgetconnectedstate
According to MSDN the actual messages are more along the lines of:
Local system uses a local area network to connect to the Internet.
This does not imply that the computer is connected, merely that the default connection is through a LAN.
Re: internetgetconnectedstate
Thank you.
How do I check to see if the local system is connected to the internet?
Re: internetgetconnectedstate
You were using it in post #1:
Quote:
lres = InternetGetConnectedState(lret, 0&)
True if connected, false if not.
Re: internetgetconnectedstate
May be I should explain more. I have a broadband connection. The program is responding in similar way even if I have logged out of my internet account.
I checked lres by logging in and logging out . In both cases it is true.
So , what do I do
Re: internetgetconnectedstate
Hmm..maybe you can try this Here
Re: internetgetconnectedstate
Not much luck with that either:
Following message is being displayed. It doesn't matter whether I have logged into my internet account or not.
connected : LAN connection
connection uses LAN
connection is not configured
system has RAS installed
Searching for this on the forum, I came across one thread in which it was said that if we are connected to the net through a router, it is not possible to check the connection status with this api. My networking knowledge is next to nothing, so I don't know if I am connected through a router.
This being the case what next?
Re: internetgetconnectedstate
How about you try this? Try to connect to a site and see if you manage or not :
VB Code:
Private Const FLAG_ICC_FORCE_CONNECTION = &H1
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()
'KPD-Team 2001
'URL: [url]http://www.allapi.net/[/url]
If InternetCheckConnection("http://www.allapi.net/", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
MsgBox "Connection to [url]http://www.allapi.net/[/url] failed!", vbInformation
Else
MsgBox "Connection to [url]http://www.allapi.net/[/url] succeeded!", vbInformation
End If
End Sub
Re: internetgetconnectedstate
Good one. I should be sure that I am connecting to a site that is hosted at the time I am checking the connection, I believe. Any other method that can be tried ? Or any other method that is generally used?
Thank you.
Re: internetgetconnectedstate
Here are other codes that may or may not work :
VB Code:
Private Const INTERNET_CONNECTION_CONFIGURED = &H40
Private Const INTERNET_CONNECTION_LAN = &H2
Private Const INTERNET_CONNECTION_MODEM = &H1
Private Const INTERNET_CONNECTION_OFFLINE = &H20
Private Const INTERNET_CONNECTION_PROXY = &H4
Private Const INTERNET_RAS_INSTALLED = &H10
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
Private Sub Form_Load()
'KPD-Team 2001
'URL: [url]http://www.allapi.net/[/url]
Dim Ret As Long
Me.AutoRedraw = True
'retrieve the connection status
InternetGetConnectedState Ret, 0&
'show the result
If (Ret And INTERNET_CONNECTION_CONFIGURED) = INTERNET_CONNECTION_CONFIGURED Then Me.Print "Local system has a valid connection to the Internet, but it may or may not be currently connected."
If (Ret And INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN Then Me.Print "Local system uses a local area network to connect to the Internet."
If (Ret And INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM Then Me.Print "Local system uses a modem to connect to the Internet."
If (Ret And INTERNET_CONNECTION_OFFLINE) = INTERNET_CONNECTION_OFFLINE Then Me.Print "Local system is in offline mode."
If (Ret And INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY Then Me.Print "Local system uses a proxy server to connect to the Internet."
If (Ret And INTERNET_RAS_INSTALLED) = INTERNET_RAS_INSTALLED Then Me.Print "Local system has RAS installed."
End Sub
I think the above is the same as your first one...
VB Code:
Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
Private Sub Form_Load()
MsgBox "Is connected to the internet: " + CStr(IsConnected)
End Sub
Public Function IsConnected() As Boolean
If InternetGetConnectedState(0&, 0&) = 1 Then
IsConnected = True
Else
IsConnected = False
End If
End Function
VB Code:
Const NETWORK_ALIVE_AOL = &H4
Const NETWORK_ALIVE_LAN = &H1
Const NETWORK_ALIVE_WAN = &H2
Private Type QOCINFO
dwSize As Long
dwFlags As Long
dwInSpeed As Long 'in bytes/second
dwOutSpeed As Long 'in bytes/second
End Type
Private Declare Function IsDestinationReachable Lib "SENSAPI.DLL" Alias "IsDestinationReachableA" (ByVal lpszDestination As String, ByRef lpQOCInfo As QOCINFO) As Long
Private Sub Form_Load()
'KPD-Team 2001
'URL: [url]http://www.allapi.net/[/url]
Dim Ret As QOCINFO
Ret.dwSize = Len(Ret)
If IsDestinationReachable("www.allapi.net", Ret) = 0 Then
MsgBox "The destination cannot be reached!"
Else
MsgBox "The destination can be reached!" + vbCrLf + _
"The speed of data coming in from the destination is " + Format$(Ret.dwInSpeed / 1024, "#.0") + " Kb/s," + vbCrLf + _
"and the speed of data sent to the destination is " + Format$(Ret.dwOutSpeed / 1024, "#.0") + " Kb/s."
End If
End Sub
VB Code:
Private Declare Function InternetGetConnectedStateEx Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal lpszConnectionName As String, ByVal dwNameLen As Integer, ByVal dwReserved As Long) As Long
Dim sConnType As String * 255
Private Sub Form_Load()
Dim Ret As Long
Ret = InternetGetConnectedStateEx(Ret, sConnType, 254, 0)
If Ret = 1 Then
MsgBox "You are connected to Internet via a " & sConnType, vbInformation
Else
MsgBox "You are not connected to internet", vbInformation
End If
End Sub
Try these and see if anything works! I got them all from the API Guide.
Re: internetgetconnectedstate
Internetgetconnectedstate or internetgetconnectedstateex : Both these functions are giving true , whether I am logged into my internet account or not.
When I am trying isdestinationreachable , system is hanging. Even after waiting for 3 minutes , there is no response. But for this , this issue is almost resolved.
I should try connecting to a site to see if I am connected to the internet.