Welcome !
         

 VBS to check for active internet connection?

Author Message
kriemer

  • Total Posts : 94
  • Scores: 0
  • Reward points : 0
  • Joined: 9/26/2008
  • Status: offline
VBS to check for active internet connection? Thursday, October 23, 2008 11:56 AM (permalink)
0
I have a number of VBScripts that open programs which slurp data from the internet, do something else, then end. 

If the internet is down for any reason I get an error message which stops any later scripts from executing the same routine at a later time when the internet may be up. 

A solution would be to check for an active internet connection, if True continue, if False end.

Is this possible?  Any ideas?

Thanks in advance

k
 
 
#1
    TNO

    • Total Posts : 2149
    • Scores: 43
    • Reward points : 0
    • Joined: 12/18/2004
    • Location: Earth
    • Status: offline
    RE: VBS to check for active internet connection? Thursday, October 23, 2008 1:36 PM (permalink)
    0
    choose some random site, like google and then ping the website every once in awhile or use xmlhttprequest
    To iterate is human, to recurse divine. -- L. Peter Deutsch
     
    #2
      kriemer

      • Total Posts : 94
      • Scores: 0
      • Reward points : 0
      • Joined: 9/26/2008
      • Status: offline
      RE: VBS to check for active internet connection? Thursday, October 23, 2008 2:29 PM (permalink)
      0
      Both ideas would seem to do what I want but I can't figure out how to inject the "TRUE" into my VBS routine.

      I Goggled xmlhttprequestand and it would seem the best of the 2 solutions.  While there is a lot of stuff on the subject out there I'm just not skilled enough to proceed.

      Thanks


      k
       
      #3
        Fredledingue

        • Total Posts : 585
        • Scores: -5
        • Reward points : 0
        • Joined: 5/9/2005
        • Location: Europe
        • Status: offline
        RE: VBS to check for active internet connection? Friday, October 24, 2008 8:20 AM (permalink)
        0
         Dim WshShell
         Set WshShell = createobject("wscript.shell") 
         strURL = "www.yahoo.com"
         set png = WshShell.exec("ping -n 1 " & strURL) 
             do until png.status = 1 
          wscript.sleep 100 
          loop 
         strPing = lcase(png.stdout.readall) 
             Select Case True 
                 Case InStr(strPing, "reply from") > 1 
                     strReply = True      '------"Request timed out" 
                 Case Else 
                     strReply = False 
             End Select 
         msgbox strReply 

         
        HTH
        Fred
         
        #4
          kriemer

          • Total Posts : 94
          • Scores: 0
          • Reward points : 0
          • Joined: 9/26/2008
          • Status: offline
          RE: VBS to check for active internet connection? Saturday, October 25, 2008 10:07 AM (permalink)
          0
          Thank you 10^6

          So far as I can see (and tested) I need to insert my run if connected as shown below:

          Dim WshShell
          Set WshShell = createobject("wscript.shell")
          strURL = "www.yahoo.com"
          set png = WshShell.exec("ping -n 1 " & strURL)
          do until png.status = 1
          wscript.sleep 100
          loop
          strPing = lcase(png.stdout.readall)
          Select Case True
               Case InStr(strPing, "reply from") > 1

          ' INSERT CODE TO RUN HERE - IF INTERNET CONNECTION ACTIVE

            Case Else
            End Select

          If there is no connection the procedure ends.  Is this right?


          Thanks

          k
          <message edited by kriemer on Saturday, October 25, 2008 12:11 PM>
           
          #5
            ebgreen

            • Total Posts : 9079
            • Scores: 161
            • Reward points : 0
            • Joined: 7/12/2005
            • Status: offline
            RE: VBS to check for active internet connection? Monday, October 27, 2008 2:35 AM (permalink)
            0
            Well to be more specific, for the code that you posted if the connection doesn't exist, the connection specific code just never runs.
            Stop the Help Vampires: http://slash7.com/2006/12/22/vampires/
            VB is NOT VB.Net which is NOT VBA which is NOT VBScript
             
            #6
              Fredledingue

              • Total Posts : 585
              • Scores: -5
              • Reward points : 0
              • Joined: 5/9/2005
              • Location: Europe
              • Status: offline
              RE: VBS to check for active internet connection? Monday, October 27, 2008 5:01 AM (permalink)
              0

              If there is no connection the procedure ends.  Is this right?

               
              I think you'r right.
              Fred
               
              #7
                kriemer

                • Total Posts : 94
                • Scores: 0
                • Reward points : 0
                • Joined: 9/26/2008
                • Status: offline
                RE: VBS to check for active internet connection? Monday, October 27, 2008 7:48 AM (permalink)
                0
                ebgreen,

                    That is exactly what I need, to have the procedure run ONLY if the connection to the internet is active.

                fred,

                    Thanks for the code and the feedback.  This has already proven to be of value.  BTW, by changing the line "wscript.sleep 1000" to
                "Application.Wait (Now + TimeValue("0:00:01"))" your code runs as VBA within Excel; also of value to me.


                Wonderful forum.

                k
                <message edited by kriemer on Monday, October 27, 2008 7:56 AM>
                 
                #8
                  binarydigit0101

                  • Total Posts : 19
                  • Scores: 0
                  • Reward points : 0
                  • Joined: 3/9/2011
                  • Status: offline
                  Re: RE: VBS to check for active internet connection? Thursday, March 10, 2011 4:55 AM (permalink)
                  0
                  could it be this source always returns false?
                  see you!
                   
                  #9
                    faulkkev

                    • Total Posts : 601
                    • Scores: 13
                    • Reward points : 0
                    • Joined: 11/1/2005
                    • Location: Kansas City, MO
                    • Status: offline
                    Re: RE: VBS to check for active internet connection? Friday, March 11, 2011 3:21 AM (permalink)
                    0
                    you could also use webpage load test to verify content comes back and use a list of pings and loads combined to afford icmp blocks for pings or a url that is down which, both could lead to a false internet failure indicator.  This way if a particular site or ping fails it may not be indicitive of true no internet.
                     
                     
                        
                    on error resume next

                    arraywebsite = array("www.google.com","www.yahoo.com")



                    for each objUrl in arraywebsite 

                    Set objHTTP = CreateObject("MSXML2.XMLHTTP")

                    strurl = "http://" & objUrl 



                    objHTTP.Open "GET", strURL, FALSE

                    objHTTP.Send



                      if objHTTP.statusText = "OK" then

                        wscript.echo now & " Url Status " & objHTTP.statusText & " For " & strUrl



                       else

                         wscript.echo now & " Error Connecting to " & strurl



                      end if



                    next
                     
                     
                    #10
                      binarydigit0101

                      • Total Posts : 19
                      • Scores: 0
                      • Reward points : 0
                      • Joined: 3/9/2011
                      • Status: offline
                      Re: RE: VBS to check for active internet connection? Friday, March 11, 2011 4:32 AM (permalink)
                      0
                      thank you for your source... but it tried to connect and return me the errors.
                       
                      #11
                        faulkkev

                        • Total Posts : 601
                        • Scores: 13
                        • Reward points : 0
                        • Joined: 11/1/2005
                        • Location: Kansas City, MO
                        • Status: offline
                        Re: RE: VBS to check for active internet connection? Friday, March 11, 2011 6:19 AM (permalink)
                        0
                        I tested it before I ran it.  maybe something didn't come across right in the paste.  I have had issues before.  Anyway it was more of an idea to help make the scripts decision internet up or down more accurate.   I use similar code above to monitor internal web server pages so I know they are down before they are even reported. 
                         
                        #12
                          binarydigit0101

                          • Total Posts : 19
                          • Scores: 0
                          • Reward points : 0
                          • Joined: 3/9/2011
                          • Status: offline
                          Re: RE: VBS to check for active internet connection? Saturday, March 12, 2011 4:58 AM (permalink)
                          0
                          okay.
                          thank you! i resolved.
                           
                          here's the code: (i trasformed it into a function!)
                           
                           Function Connessione()
                          Set WshShell = CreateObject("WScript.Shell")
                          PINGFlag = Not CBool(WshShell.run("ping -n 1 www.google.it",0,True))
                           If PINGFlag = True Then
                           'Successful ping
                           Connessione = True
                           Else
                           'Unsuccessful ping
                           Connessione = False
                           End If
                          End Function 

                           
                          #13
                            TNO

                            • Total Posts : 2149
                            • Scores: 43
                            • Reward points : 0
                            • Joined: 12/18/2004
                            • Location: Earth
                            • Status: offline
                            Re: RE: VBS to check for active internet connection? Saturday, March 12, 2011 6:47 AM (permalink)
                            0
                            You need to declare your variables
                            To iterate is human, to recurse divine. -- L. Peter Deutsch
                             
                            #14
                              binarydigit0101

                              • Total Posts : 19
                              • Scores: 0
                              • Reward points : 0
                              • Joined: 3/9/2011
                              • Status: offline
                              Re: RE: VBS to check for active internet connection? Saturday, March 12, 2011 7:20 AM (permalink)
                              0
                              what do you mean?
                               
                              #15
                                TNO

                                • Total Posts : 2149
                                • Scores: 43
                                • Reward points : 0
                                • Joined: 12/18/2004
                                • Location: Earth
                                • Status: offline
                                Re: RE: VBS to check for active internet connection? Saturday, March 12, 2011 7:42 AM (permalink)
                                0
                                Try to run your code with Option Explicit and you'll see what I mean:
                                 
                                 Option Explicit
                                Function Connessione()
                                Set WshShell = CreateObject("WScript.Shell")
                                PINGFlag = Not CBool(WshShell.run("ping -n 1 www.google.it",0,True))
                                 If PINGFlag = True Then
                                 'Successful ping
                                 Connessione = True
                                 Else
                                 'Unsuccessful ping
                                 Connessione = False
                                 End If
                                End Function 
                                
                                Dim Result : Result = Connessione() 

                                 
                                You need to "Dim" variables before you assign to them:
                                 
                                Dim foo : foo = "bar"
                                Dim quux : Set quux = SomeObject
                                To iterate is human, to recurse divine. -- L. Peter Deutsch
                                 
                                #16
                                  binarydigit0101

                                  • Total Posts : 19
                                  • Scores: 0
                                  • Reward points : 0
                                  • Joined: 3/9/2011
                                  • Status: offline
                                  Re: RE: VBS to check for active internet connection? Saturday, March 12, 2011 9:07 AM (permalink)
                                  0
                                  okay... sorry.
                                   
                                  i posted only the function.
                                   
                                  see you :-)
                                   
                                  #17
                                    TNO

                                    • Total Posts : 2149
                                    • Scores: 43
                                    • Reward points : 0
                                    • Joined: 12/18/2004
                                    • Location: Earth
                                    • Status: offline
                                    Re: RE: VBS to check for active internet connection? Saturday, March 12, 2011 9:31 AM (permalink)
                                    0
                                    binarydigit0101


                                    okay... sorry.

                                    i posted only the function.

                                    see you :-)

                                    Nothing to apologize about. The point is that if you don't do that then you could be changing the values of variables outside the function leading to weird bugs that are hard to fix
                                    To iterate is human, to recurse divine. -- L. Peter Deutsch
                                     
                                    #18
                                      binarydigit0101

                                      • Total Posts : 19
                                      • Scores: 0
                                      • Reward points : 0
                                      • Joined: 3/9/2011
                                      • Status: offline
                                      Re: RE: VBS to check for active internet connection? Saturday, March 12, 2011 6:30 PM (permalink)
                                      0
                                      i didn't declare variables because i used the name of the function inside a conditional statement.
                                       
                                      anyway... okay, thank you for the suggestion! ;-)
                                       
                                      #19
                                        Online Bookmarks Sharing: Share/Bookmark

                                        Jump to:

                                        Current active users

                                        There are 0 members and 1 guests.

                                        Icon Legend and Permission

                                        • New Messages
                                        • No New Messages
                                        • Hot Topic w/ New Messages
                                        • Hot Topic w/o New Messages
                                        • Locked w/ New Messages
                                        • Locked w/o New Messages
                                        • Read Message
                                        • Post New Thread
                                        • Reply to message
                                        • Post New Poll
                                        • Submit Vote
                                        • Post reward post
                                        • Delete my own posts
                                        • Delete my own threads
                                        • Rate post

                                        2000-2014 ASPPlayground.NET Forum Version 3.9