Results 1 to 11 of 11

Thread: internetgetconnectedstate

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    internetgetconnectedstate

    Hello,
    This is the code
    VB Code:
    1. Private Sub cmdgetstate_Click()
    2. Dim lres As Long
    3.  
    4. lres = InternetGetConnectedState(lret, 0&)
    5.  
    6. If (lret And INTERNET_CONNECTION_CONFIGURED) = INTERNET_CONNECTION_CONFIGURED Then
    7.   MsgBox ("This system has a valid internet connection ")
    8. End If
    9.  
    10. If (lret And INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN Then
    11.   MsgBox ("This system is connected to internet through LAN")
    12. End If
    13.  
    14. If (lret And INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM Then
    15.   MsgBox ("This system is connected to internet through modem")
    16. End If
    17.  
    18. If (lret And INTERNET_CONNECTION_OFFLINE) = INTERNET_CONNECTION_OFFLINE Then
    19.   MsgBox ("This system is presently offline")
    20. End If
    21.  
    22. If (lret And INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY Then
    23.   MsgBox ("This system is connected to internet through proxy")
    24. End If
    25.  
    26. If (lret And INTERNET_RAS_INSTALLED) = INTERNET_RAS_INSTALLED Then
    27.   MsgBox ("This system has RAS installed ")
    28. End If
    29.  
    30. 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.

  2. #2
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    Re: internetgetconnectedstate

    Thank you.
    How do I check to see if the local system is connected to the internet?

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: internetgetconnectedstate

    You were using it in post #1:
    lres = InternetGetConnectedState(lret, 0&)
    True if connected, false if not.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    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

  6. #6
    Member
    Join Date
    Mar 2006
    Posts
    62

    Re: internetgetconnectedstate

    Hmm..maybe you can try this Here

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    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?

  8. #8
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: internetgetconnectedstate

    How about you try this? Try to connect to a site and see if you manage or not :

    VB Code:
    1. Private Const FLAG_ICC_FORCE_CONNECTION = &H1
    2. Private Declare Function InternetCheckConnection Lib "wininet.dll" Alias "InternetCheckConnectionA" (ByVal lpszUrl As String, ByVal dwFlags As Long, ByVal dwReserved As Long) As Long
    3. Private Sub Form_Load()
    4.     'KPD-Team 2001
    5.     'URL: [url]http://www.allapi.net/[/url]
    6.     'E-Mail: [email][email protected][/email]
    7.     If InternetCheckConnection("http://www.allapi.net/", FLAG_ICC_FORCE_CONNECTION, 0&) = 0 Then
    8.         MsgBox "Connection to [url]http://www.allapi.net/[/url] failed!", vbInformation
    9.     Else
    10.         MsgBox "Connection to [url]http://www.allapi.net/[/url] succeeded!", vbInformation
    11.     End If
    12. End Sub


    Has someone helped you? Then you can Rate their helpful post.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    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.

  10. #10
    Super Moderator manavo11's Avatar
    Join Date
    Nov 2002
    Location
    Around the corner from si_the_geek
    Posts
    7,171

    Re: internetgetconnectedstate

    Here are other codes that may or may not work :

    VB Code:
    1. Private Const INTERNET_CONNECTION_CONFIGURED = &H40
    2. Private Const INTERNET_CONNECTION_LAN = &H2
    3. Private Const INTERNET_CONNECTION_MODEM = &H1
    4. Private Const INTERNET_CONNECTION_OFFLINE = &H20
    5. Private Const INTERNET_CONNECTION_PROXY = &H4
    6. Private Const INTERNET_RAS_INSTALLED = &H10
    7. Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
    8. Private Sub Form_Load()
    9.     'KPD-Team 2001
    10.     'URL: [url]http://www.allapi.net/[/url]
    11.     'E-Mail: [email][email protected][/email]
    12.     Dim Ret As Long
    13.     Me.AutoRedraw = True
    14.     'retrieve the connection status
    15.     InternetGetConnectedState Ret, 0&
    16.     'show the result
    17.     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."
    18.     If (Ret And INTERNET_CONNECTION_LAN) = INTERNET_CONNECTION_LAN Then Me.Print "Local system uses a local area network to connect to the Internet."
    19.     If (Ret And INTERNET_CONNECTION_MODEM) = INTERNET_CONNECTION_MODEM Then Me.Print "Local system uses a modem to connect to the Internet."
    20.     If (Ret And INTERNET_CONNECTION_OFFLINE) = INTERNET_CONNECTION_OFFLINE Then Me.Print "Local system is in offline mode."
    21.     If (Ret And INTERNET_CONNECTION_PROXY) = INTERNET_CONNECTION_PROXY Then Me.Print "Local system uses a proxy server to connect to the Internet."
    22.     If (Ret And INTERNET_RAS_INSTALLED) = INTERNET_RAS_INSTALLED Then Me.Print "Local system has RAS installed."
    23. End Sub

    I think the above is the same as your first one...

    VB Code:
    1. 'Example by Vijay Phulwadhawa ([email protected])
    2. Private Declare Function InternetGetConnectedState Lib "wininet.dll" (ByRef lpdwFlags As Long, ByVal dwReserved As Long) As Long
    3. Private Sub Form_Load()
    4.     MsgBox "Is connected to the internet: " + CStr(IsConnected)
    5. End Sub
    6. Public Function IsConnected() As Boolean
    7.     If InternetGetConnectedState(0&, 0&) = 1 Then
    8.         IsConnected = True
    9.     Else
    10.         IsConnected = False
    11.     End If
    12. End Function

    VB Code:
    1. Const NETWORK_ALIVE_AOL = &H4
    2. Const NETWORK_ALIVE_LAN = &H1
    3. Const NETWORK_ALIVE_WAN = &H2
    4. Private Type QOCINFO
    5.     dwSize As Long
    6.     dwFlags As Long
    7.     dwInSpeed As Long 'in bytes/second
    8.     dwOutSpeed As Long 'in bytes/second
    9. End Type
    10. Private Declare Function IsDestinationReachable Lib "SENSAPI.DLL" Alias "IsDestinationReachableA" (ByVal lpszDestination As String, ByRef lpQOCInfo As QOCINFO) As Long
    11. Private Sub Form_Load()
    12.     'KPD-Team 2001
    13.     'URL: [url]http://www.allapi.net/[/url]
    14.     'E-Mail: [email][email protected][/email]
    15.     Dim Ret As QOCINFO
    16.     Ret.dwSize = Len(Ret)
    17.     If IsDestinationReachable("www.allapi.net", Ret) = 0 Then
    18.         MsgBox "The destination cannot be reached!"
    19.     Else
    20.         MsgBox "The destination can be reached!" + vbCrLf + _
    21.            "The speed of data coming in from the destination is " + Format$(Ret.dwInSpeed / 1024, "#.0") + " Kb/s," + vbCrLf + _
    22.            "and the speed of data sent to the destination is " + Format$(Ret.dwOutSpeed / 1024, "#.0") + " Kb/s."
    23.     End If
    24. End Sub

    VB Code:
    1. 'Example by Vijay Phulwadhawa ([email protected])
    2. 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
    3. Dim sConnType As String * 255
    4. Private Sub Form_Load()
    5.     Dim Ret As Long
    6.     Ret = InternetGetConnectedStateEx(Ret, sConnType, 254, 0)
    7.     If Ret = 1 Then
    8.         MsgBox "You are connected to Internet via a " & sConnType, vbInformation
    9.     Else
    10.         MsgBox "You are not connected to internet", vbInformation
    11.     End If
    12. End Sub

    Try these and see if anything works! I got them all from the API Guide.


    Has someone helped you? Then you can Rate their helpful post.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Feb 2006
    Location
    Hyderabad, India
    Posts
    233

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width