Announcement

Collapse
No announcement yet.

Detecting if Dialup is active

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Detecting if Dialup is active

    I saw this somewhere but my search was fruitless ;(

    I just want to know if the user is connected through his DUN (Dialup Networking)..
    If he's not I want to sit tight, if he is, I go to work ...


    Thanks


    Scott


    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

  • #2
    Download my RAS wrapper from www.basicguru.com/dickinson
    There is code within that will enumerate the active RAS connections.
    It will also Dial and Disconnect connections.

    --Don

    ------------------
    www.basicguru.com/dickinson
    Don Dickinson
    www.greatwebdivide.com

    Comment


    • #3
      + On my site, in the helpfile(faq) is a topic, dialup...


      ------------------
      [email protected]
      hellobasic

      Comment


      • #4
        E.B.,

        How about posting a URL... Thanks!

        --Dave


        ------------------
        Home of the BASIC Gurus
        www.basicguru.com
        Home of the BASIC Gurus
        www.basicguru.com

        Comment


        • #5
          In IE4 + there is a special function InternetGetConnectedState
          Code:
          #Compile Exe
          
          Declare Function InternetGetConnectedState Lib "wininet.dll" Alias "InternetGetConnectedState" (lpdwFlags As Long, _
             ByVal dwReserved As Long) As Long
          
          %INTERNET_CONNECTION_MODEM      = &H1&
          %INTERNET_CONNECTION_LAN        = &H2&
          %INTERNET_CONNECTION_PROXY      = &H4&
          %INTERNET_CONNECTION_MODEM_BUSY = &H8&
          %INTERNET_RAS_INSTALLED         = &H10&
          %INTERNET_CONNECTION_OFFLINE    = &H20&
          %INTERNET_CONNECTION_CONFIGURED = &H40&
          
          Function PbMain
             Dim dwflags As Long
             InternetGetConnectedState dwflags, 0&
             MsgBox Hex$(dwFlags)
          End Function
          ------------------
          E-MAIL: [email protected]

          Comment


          • #6
            My site is allways in my profile.
            (In case my site name changes)




            ------------------
            [email protected]
            hellobasic

            Comment


            • #7
              I think that just might do it, I'm not so much concerned with the dialup, just with ANY connection, and that appears to do it.

              if it comes back as 20 I assume it's failing ??? Otherwise it would appear to have a connection...

              Scott

              ------------------
              Scott
              mailto:[email protected][email protected]</A>
              Scott Turchin
              MCSE, MCP+I
              http://www.tngbbs.com
              ----------------------
              True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

              Comment


              • #8
                Would this be a safe assumption?
                Code:
                Function IsInternetAvailable() As Long
                   Dim dwflags As Long
                   InternetGetConnectedState dwflags, 0&
                   Select Case dwFlags
                          Case 1,2,4,8,10
                               Function = %TRUE
                          Case Else
                               Function = %FALSE
                   End Select
                End Function
                ------------------
                Scott
                mailto:[email protected][email protected]</A>
                Scott Turchin
                MCSE, MCP+I
                http://www.tngbbs.com
                ----------------------
                True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                Comment


                • #9
                  You should test Return Value, not dwflags (I was interesting in type of connection)

                  InternetGetConnectedState Function

                  --------------------------------------------------------------------------------

                  Retrieves the connected state of the local system.

                  Syntax

                  BOOL InternetGetConnectedState(
                  OUT LPDWORD lpdwFlags,
                  IN DWORD dwReserved
                  );

                  Parameters

                  lpdwFlags
                  Address of an unsigned long integer variable where the connection description should be returned. This can be a combination of the following values:
                  INTERNET_CONNECTION_CONFIGURED
                  Local system has a valid connection to the Internet, but it may or may not be currently connected.
                  INTERNET_CONNECTION_LAN
                  Local system uses a local area network to connect to the Internet.
                  INTERNET_CONNECTION_MODEM
                  Local system uses a modem to connect to the Internet.
                  INTERNET_CONNECTION_MODEM_BUSY
                  No longer used.
                  INTERNET_CONNECTION_OFFLINE
                  Local system is in offline mode.
                  INTERNET_CONNECTION_PROXY
                  Local system uses a proxy server to connect to the Internet.
                  INTERNET_RAS_INSTALLED
                  Local system has RAS installed.
                  dwReserved
                  Reserved. Must be set to zero.

                  Return Value

                  Returns TRUE if there is an Internet connection, or FALSE otherwise.



                  ------------------
                  E-MAIL: [email protected]

                  Comment


                  • #10
                    Ahhhhh I see the light!


                    Thanks, So I think the guy has a dialup, i tell it a dialup configured and test for it....(??)..
                    makes sense...

                    ------------------
                    Scott
                    mailto:[email protected][email protected]</A>
                    Scott Turchin
                    MCSE, MCP+I
                    http://www.tngbbs.com
                    ----------------------
                    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                    Comment


                    • #11
                      This seems to work rather nicely:

                      Code:
                      Function IsInternetAvailable() As Long
                      Dim dwflags     As Long
                      Dim lResult     As Long
                      %INTERNET_CONNECTION_OFFLINE    = &H20&
                      
                      
                      lResult = InternetGetConnectedState(dwflags, 0&)
                      If lResult = %INTERNET_CONNECTION_OFFLINE Then
                         Function = %FALSE
                      Else
                         Function = %TRUE
                      End If
                      End Function
                      ------------------
                      Scott
                      mailto:[email protected][email protected]</A>
                      Scott Turchin
                      MCSE, MCP+I
                      http://www.tngbbs.com
                      ----------------------
                      True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                      Comment


                      • #12
                        Scott,

                        I have had some experience using InternetGetConnectedState in a custom program for a client, and I have found that while it is a useful function, it is not reliable on its own for detecting an active connection.

                        Here's why:

                        First, as I recall it looks for the connection which has been set up as the default connection for the machine, which may or may not be the connection that the user ordinarily uses or is currently using.

                        Second, if the system uses a LAN to connect, this function may report an active connection even if the LAN is not currently connected to the net.

                        Third, if the system uses a modem, InternetGetConnectedState will report a connection even if the modem is in the process of dialing, or otherwise running but not connected.

                        If you're going to use this function, I would strongly suggest you do some further checking on the connection, as in the following pseudo-code:

                        Code:
                        Call InternetGetConnectedState
                        
                        IF ConnectionMeathod = "Modem" THEN
                            CALL rsActiveConnections and then rsGetConnectionStatus on any connections you find
                        
                        ELSEIF ConnectionMeathod = "LAN" OR ConnectionMeathod = "Proxy Server" THEN
                        	hInet = InternetOpen(AppTitle, %INTERNET_OPEN_TYPE_PRECONFIG, zNull, zNull, 0&)
                         	IF hInet THEN
                            		Flags = %INTERNET_FLAG_KEEP_CONNECTION OR %INTERNET_FLAG_NO_CACHE_WRITE OR %INTERNET_FLAG_RELOAD
                                  hUrl = InternetOpenUrl(hInet, zURL, zNull, 0, Flags, 0)
                                  IF hUrl THEN
                                    ConnectionActive = %True
                                  ELSE
                                        ConnectionActive = %False
                                 	END IF
                                 	CALL InternetCloseHandle(hInet)
                            	End If
                        END IF
                        Originally posted by Scott Turchin:
                        This seems to work rather nicely:

                        Code:
                        Function IsInternetAvailable() As Long
                        Dim dwflags     As Long
                        Dim lResult     As Long
                        %INTERNET_CONNECTION_OFFLINE    = &H20&
                        
                        
                        lResult = InternetGetConnectedState(dwflags, 0&)
                        If lResult = %INTERNET_CONNECTION_OFFLINE Then
                           Function = %FALSE
                        Else
                           Function = %TRUE
                        End If
                        End Function


                        ------------------
                        Peter Amick
                        Baybuild Solutions
                        Peter Amick
                        Baybuild Solutions

                        Comment


                        • #13
                          Scott,

                          I just picked up this article from the knowledge base:

                          SUMMARY
                          Many of you want to know if a computer has an active Internet connection before trying to connect to the Internet using the WinInet API or some other communication interface. The internet connection is important if you don't want your application to cause Windows to automatically dial the default Internet modem connection.
                          This article provides a mechanism for determining if an Internet site is accessible without the risk of you being prompted to dial into another Internet Service Provider.
                          MORE INFORMATION
                          Usually the best way to determine if you have a connection to a particular computer is to attempt the connection. If the autodial feature of Windows is enabled then attempting the connection may cause the default Internet dialup connectoid to be opened, and you will be prompted with your credentials to connect.
                          To avoid having the default Internet connectoid dialed, the InternetGetConnectedState function can be used to determine if there is a default Internet dialup connectoid configured and whether it is currently active or not. If there is a default Internet dialup connectoid configured and it is not currently active then InternetGetConnectedState will return FALSE. If InternetGetConnectedState returns TRUE then you can attempt to connect to the Internet resource without fear of being prompted to connect to another Internet Service Provider.
                          The following code demonstrates how you would do this:
                          Code:
                          if (InternetGetConnectedState(...) == FALSE)
                          {
                              // Don't attempt connection or it will bring up the dialog
                              ...
                          }
                          else
                          {
                              //Attempt connection
                              if (InternetOpenURL(...) == NULL)
                              {
                                  // Call failed
                                  err = GetLastError();
                                  if ((err == ERROR_INTERNET_NAME_NOT_RESOLVED) | |
                                      (err == ERROR_INTERNET_CANNOT_CONNECT) | |
                                      (err == ERROR_INTERNET_TIMEOUT))
                                  {
                                      // probably not connected...handle appropriately
                                      ...
                                  }
                              }
                              // We're connected!!!
                              ....
                          }
                          You cannot rely solely on the fact that InternetGetConnectedState returning TRUE means that you have a valid active Internet connection. It is impossible for InternetGetConnectedState to determine if the entire connection to the Internet is functioning without sending a request to a server. This is why you need to send a request to determine if you are really connected or not. You can be assured however that if InternetGetConnectedState returns TRUE, that attempting your connection will NOT cause you to be prompted to connect to the default Internet Service Provider.
                          Be aware that InternetGetConnectedState only reports the status of the default Internet connectoid on Internet Explorer 4.x. If a nondefault connectoid is connected, InternetGetConnectedState always returns FALSE (unless a LAN connection is used). With Internet Explorer 4.x configured to use a LAN connection, InternetGetCo
                          nectedState always returns TRUE.
                          Internet Explorer 5 behaves differently. If you are currently dialed into a different dial-up in Internet Explorer 5, InternetGetConnectedState reports dial-up connection status as long as any connectoid is dialed or an active LAN connection exists.


                          There are some other ways to try to determine if you currently have a connection to a particular network resource. The IsDestinationReachable() function can be used to find out if there is a current connection to an address. However, he IsDestinationReachable() function is only concerned with whether the IP address is reachable from your computer. It does not work through HTTP proxies or firewalls that restrict ICMP ping packets.
                          It is also possible to use RasEnumConnections to enhance your code so that you can tell if there is an active dialup connection that might have Internet access even though it is not the default Internet dialup connectoid.


                          ------------------
                          Peter Amick
                          Baybuild Solutions

                          [This message has been edited by Peter Amick (edited December 16, 2000).]
                          Peter Amick
                          Baybuild Solutions

                          Comment


                          • #14
                            For the purpose of just making sure the guy is online before sending an email the above one should work just fine.
                            I know he's not on a lan and it's a dialup, now the concern would be maybe he has two dialups but we have information that it's not so that should work pretty good


                            But I will make a note of the other one as well, that's a nice looking function

                            Thanks!


                            Scott


                            ------------------
                            Scott
                            mailto:[email protected][email protected]</A>
                            Scott Turchin
                            MCSE, MCP+I
                            http://www.tngbbs.com
                            ----------------------
                            True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                            Comment

                            Working...
                            X