MULTITHREADING

Change Page: 123 > | Showing page 1 of 3, messages 1 to 20 of 46
Author Message
giantlunarmoth

  • Total Posts : 47
  • Scores: 0
  • Reward points : 0
  • Joined: 3/9/2005
  • Location:
  • Status: offline
MULTITHREADING Monday, March 14, 2005 8:22 AM (permalink)
0
Can VBScript run shell commands in the "background"?

For example:

Set objShell = CreateObject("WScript.Shell")
objShell.run "ping 127.0.0.1"


Can the Shell object execute ping without launching the console? In this example, would it be objShell.somethingelse?

I'm also curious if anyone's had any experience working directly with Icmp.dll; pinging multiple hosts simultaneously on separate threads (which is ultimately what I'm trying to do ).

Thanks...GLM
 
#1
    mbouchard

    • Total Posts : 2110
    • Scores: 29
    • Reward points : 0
    • Joined: 5/15/2003
    • Location: USA
    • Status: offline
    Re: MULTITHREADING Monday, March 14, 2005 8:49 AM (permalink)
    0
    you could use WMI to ping without the need for the console.
    strMachines = "atl-dc-01;atl-win2k-01;atl-nt4-01;atl-dc-02"
    aMachines = split(strMachines, ";")
    
    For Each machine in aMachines
    Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
    ExecQuery("select * from Win32_PingStatus where address = '"_
    & machine & "'")
    For Each objStatus in objPing
    If IsNull(objStatus.StatusCode) or objStatus.StatusCode<>0 Then
    WScript.Echo("Computer " & machine & " is not reachable")
    End If
    Next
    Next
    
     
    #2
      tnoonan

      • Total Posts : 364
      • Scores: 0
      • Reward points : 0
      • Joined: 12/14/2004
      • Location:
      • Status: offline
      Re: MULTITHREADING Monday, March 14, 2005 8:59 AM (permalink)
       
      #3
        giantlunarmoth

        • Total Posts : 47
        • Scores: 0
        • Reward points : 0
        • Joined: 3/9/2005
        • Location:
        • Status: offline
        Re: MULTITHREADING Monday, March 14, 2005 9:28 AM (permalink)
        0
        Excellent...thank you both. The WMI solution is a breeze to implement, and executes quickly. OSICMP.dll is pretty dang cool in its own right.

        Thanks for your help.
         
        #4
          token

          • Total Posts : 1917
          • Scores: 0
          • Reward points : 0
          • Joined: 1/14/2005
          • Location:
          • Status: offline
          Re: MULTITHREADING Monday, March 14, 2005 10:45 AM (permalink)
          0
          How would you have multiple threads running simultaneously within the script though ?

           
          #5
            giantlunarmoth

            • Total Posts : 47
            • Scores: 0
            • Reward points : 0
            • Joined: 3/9/2005
            • Location:
            • Status: offline
            Re: MULTITHREADING Monday, March 14, 2005 2:44 PM (permalink)
            0
            I'm actually tryin to figure out how, conceptually, I can do anything simultaneously in a script. I have an app called MultiPing (not the Nessoft version)...mine is by one Thomasz Stelmach, and doesn't seem to have a home anymore. Anyway, if I remember correctly, on his now defunct webpage Thomas was explaining how Icmp.dll could support up to 50 simultaneous threads. I recently thought "there's gotta be a way to do this in a script!"...send a packet apiece to 50 hosts, then 50 more, etc. That would make pretty short work of speciallized network polling...still tryin to figure it out. :)
             
            #6
              token

              • Total Posts : 1917
              • Scores: 0
              • Reward points : 0
              • Joined: 1/14/2005
              • Location:
              • Status: offline
              Re: MULTITHREADING Monday, March 14, 2005 3:47 PM (permalink)
              0
              Since vbs is interpreted and requires cscript (or wscript) to run, isn't the multithreading capabilities of the script itself controlled or limited by cscript in some way ? Is cscript multithreading capable ?

              This is quite interesting.

               
              #7
                giantlunarmoth

                • Total Posts : 47
                • Scores: 0
                • Reward points : 0
                • Joined: 3/9/2005
                • Location:
                • Status: offline
                Re: MULTITHREADING Tuesday, March 15, 2005 3:23 AM (permalink)
                0
                I came across ThreadForker.vbs at http://cwashington.netreach.net/depo/view.asp?index=614&scripttype=vbscript. I'm curious what you guys make of this.
                 
                #8
                  giantlunarmoth

                  • Total Posts : 47
                  • Scores: 0
                  • Reward points : 0
                  • Joined: 3/9/2005
                  • Location:
                  • Status: offline
                  Re: MULTITHREADING Tuesday, March 15, 2005 8:48 AM (permalink)
                  0
                  I downloaded OSICMP.dll and the associated sample script "ping.vbs" from the link tnoonan provided above. Upon running ping.vbs, I was struck by the fact that the command output was being echoed to the "same" messagebox one line at a time. Actually, it appears as though each reply line gets its own box, but the box includes each previous reply, simulating "realtime" feedback. I think this may have some relevance to Juan Avila's post http://www.visualbasicscript.com/topic.asp?TOPIC_ID=2329 where he is trying to get realtime output into one messagebox.

                  The code of ping.vbs is below...I'm curious if anyone can detect any features in the script itself that would facilitate this method of stdout redirection, or if it's just a feature of the 3rd party dll. I've tried removing all OSICMP referrences, and substituting regular ping functions, but just get the one line per pop-up.

                  sHost = InputBox("Enter host name or IP address", "Ping", "localhost")
                  
                  Set WshShell = WScript.CreateObject("WScript.Shell")
                  Set oPing = WScript.CreateObject("OSICMP.Ping")
                  
                  For i = 0 To 10
                  oPing.Send sHost
                  
                  If i = 0 Then
                  If sHost <> oPing.IP Then s = sHost & " [" & oPing.IP & "]" Else s = sHost
                  sOutput = "Pinging " & s & " with " & oPing.PacketSize & " bytes of data:" & vbCrLf & vbCrLf
                  End If
                  
                  sOutput = sOutput & "Reply from " & _
                  oPing.IP & ": bytes=" & oPing.PacketSize & " time=" & _
                  oPing.RoundTripTime & "ms TTL=" & oPing.TTL & vbCrLf
                  
                  WshShell.Popup sOutput, 1, "Ping"
                  'oPing.Sleep 1000
                  Next
                  
                  sOutput = sOutput & vbCrLf & "Pinging complete."
                  WshShell.Popup sOutput, , "Ping (OSICMP Test)"
                  
                  Set oPing = Nothing
                  Set WshShell = Nothing
                   
                  #9
                    token

                    • Total Posts : 1917
                    • Scores: 0
                    • Reward points : 0
                    • Joined: 1/14/2005
                    • Location:
                    • Status: offline
                    Re: MULTITHREADING Tuesday, March 15, 2005 9:36 AM (permalink)
                    0
                    I'm not complaining or anything; I thought that the ThreadForker was something "real". Nonetheless, it is an interesting way of simulating multiple threads, and I've never thought of something like that before.

                    What exactly do you intend to achieve by ping the computers though ?

                     
                    #10
                      giantlunarmoth

                      • Total Posts : 47
                      • Scores: 0
                      • Reward points : 0
                      • Joined: 3/9/2005
                      • Location:
                      • Status: offline
                      Re: MULTITHREADING Tuesday, March 15, 2005 11:59 AM (permalink)
                      0
                      My superiors like to call in for up/down status on several so-called critical servers. In between our massive snmp polling cycles, it's nice to be able to get an instant status report. I already use batch and perl scripts for this and other things, but the reported "power" of WMI was quite seductive...the goal being to eventually get more than "up/down" status.

                      My interest in multithreading is very general, and, at this point, is fueled more by fantasy than practical application. We've many many thousand nodes, and I've found myself running, by "hand", several instances of the same script againts different chunks of hosts to save time...this is terrible practice, and ruins my day. :)
                       
                      #11
                        token

                        • Total Posts : 1917
                        • Scores: 0
                        • Reward points : 0
                        • Joined: 1/14/2005
                        • Location:
                        • Status: offline
                        Re: MULTITHREADING Tuesday, March 15, 2005 2:40 PM (permalink)
                        0
                        For the purpose of pinging, the results are important. In order to catch these results sent to the stdout, we will need to use files or EXEC. Simulating multithreading in this manner has its benefits of allowing us to set an arbitrary number of threads dynamically. The trick here is to determine how to track and use these results correctly and efficiently. In the case of using WMI or SICMP.Ping, it is rather difficult to dynamically change the number of threads and it is just might be as difficult to track the results.

                        I use WMI for determining the online status of a host on roughly 4000 hosts on a daily basis and it seems to be good enough for me under most circumstances.

                         
                        #12
                          giantlunarmoth

                          • Total Posts : 47
                          • Scores: 0
                          • Reward points : 0
                          • Joined: 3/9/2005
                          • Location:
                          • Status: offline
                          Re: MULTITHREADING Tuesday, March 15, 2005 3:53 PM (permalink)
                          0
                          Yes, getting precise results has always been a bit dicey for me. I used to use batch tokens, but would get erroneous positives, as border routers will return replies (i.e., "destination host unreachable") for down hosts depending on the circumstances (although, using the 9th token works pretty well most of the time: FOR /F "tokens=9" %%A IN ('ping -n 3 -w 3000 %IP%') DO whatever).

                          I'm fairly committed to sticking with WMI goin forward, as I'm tired of making all of these "niche" scripts. I'm curious as to the properties of Win32_PingStatus in terms of customization. Say a data circuit goes down, but a host is still up on a fail-over system (i.e., satellite)...can we adjust the timeout and extend the packet count to compensate? Or does WMI automatically keep trying for a certain amount of time?
                           
                          #13
                            token

                            • Total Posts : 1917
                            • Scores: 0
                            • Reward points : 0
                            • Joined: 1/14/2005
                            • Location:
                            • Status: offline
                            Re: MULTITHREADING Tuesday, March 15, 2005 4:54 PM (permalink)
                            0
                            I don't think you can adjust the timeout though. If memory serves me right, it is 1000ms.

                            Poor you, I can't even begin to imagine using batch FOR LOOP to parse the ping reply. =) I would've died instantly

                             
                            #14
                              giantlunarmoth

                              • Total Posts : 47
                              • Scores: 0
                              • Reward points : 0
                              • Joined: 3/9/2005
                              • Location:
                              • Status: offline
                              Re: MULTITHREADING Tuesday, March 15, 2005 5:59 PM (permalink)
                              0
                              Lol...I've had the same empathy for myself many a time . I think I have an inherent "when in Rome" mentality that predisposes me to shell scripting (I'm a bash-loyalist in Solaris as well). This drives my Perl-geek co-workers nuts...they've all had too much Cult of Larry Kool-Aid ("Hail Perl"). The only thing I use Perl for really is the Net::Telnet module, which is, admittedly, pretty damn useful (MS screwed us in the telnet dept.). Batch scripting's surely a trial, but it's my entrance into this whole game...and hell, it works right? Our production network is 90% windows, so I'm hoping WMI will become my secret weapon.
                               
                              #15
                                giantlunarmoth

                                • Total Posts : 47
                                • Scores: 0
                                • Reward points : 0
                                • Joined: 3/9/2005
                                • Location:
                                • Status: offline
                                Re: MULTITHREADING Tuesday, March 15, 2005 6:09 PM (permalink)
                                0
                                BTW token, do you have any thoughts on simulating real-time line echo to a single msgbox?
                                 
                                #16
                                  token

                                  • Total Posts : 1917
                                  • Scores: 0
                                  • Reward points : 0
                                  • Joined: 1/14/2005
                                  • Location:
                                  • Status: offline
                                  Re: MULTITHREADING Tuesday, March 15, 2005 6:30 PM (permalink)
                                  0
                                  I don't think you can appened any data using msgbox.

                                   
                                  #17
                                    giantlunarmoth

                                    • Total Posts : 47
                                    • Scores: 0
                                    • Reward points : 0
                                    • Joined: 3/9/2005
                                    • Location:
                                    • Status: offline
                                    Re: MULTITHREADING Tuesday, March 15, 2005 6:39 PM (permalink)
                                    0
                                    Right, but do you know how the above script is simulating it?
                                     
                                    #18
                                      token

                                      • Total Posts : 1917
                                      • Scores: 0
                                      • Reward points : 0
                                      • Joined: 1/14/2005
                                      • Location:
                                      • Status: offline
                                      Re: MULTITHREADING Tuesday, March 15, 2005 6:44 PM (permalink)
                                      0
                                      Above script ? ThreadForker ?
                                       
                                      #19
                                        giantlunarmoth

                                        • Total Posts : 47
                                        • Scores: 0
                                        • Reward points : 0
                                        • Joined: 3/9/2005
                                        • Location:
                                        • Status: offline
                                        Re: MULTITHREADING Tuesday, March 15, 2005 6:52 PM (permalink)
                                        0
                                        No...sorry, I should have specified. It's code I got from the site tnoonan posted earlier in this thread. I posted the vbs code a few posts later.
                                         
                                        #20

                                          Online Bookmarks Sharing: Share/Bookmark
                                          Change Page: 123 > | Showing page 1 of 3, messages 1 to 20 of 46

                                          Jump to:

                                          Current active users

                                          There are 0 members and 4 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-2012 ASPPlayground.NET Forum Version 3.9