Current time: 02-05-2012, 05:26 PM Hello There, Guest! (LoginRegister)


Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script for Pinging multiple servers
06-28-2010, 06:30 AM (This post was last modified: 06-29-2010 12:41 AM by Nilpo.)
Post: #1
Script for Pinging multiple servers
    VBS Programming
  1. '===============================================================================​========================================================
  2. '===============================================================================​========================================================
  3. ' Ping.vbs
  4. '
  5. ' Title................ : Script to Ping Machines
  6. '
  7. '===============================================================================​========================================================
  8. '===============================================================================​========================================================
  9. 'Option Explicit
  10.  
  11.  
  12. dim strMsg
  13. dim DateM,DateD,DateY,DateH,DateMi
  14. dim arrySecurityDescriptor
  15. dim objFSO, objTSL,objTSR,objTSN
  16. dim intTargetCnt
  17. dim strComputer,strResult
  18. dim vErrText
  19. dim strListPath,strResultPath
  20.  
  21. strListPath = ""
  22.  
  23. strResultPath = ""
  24.  
  25.  
  26. On Error Resume Next
  27.  
  28.  
  29. Set objFso = CreateObject("Scripting.FileSystemObject")
  30. Set objTsL = objFso.OpenTextFile(strListPath & "computers.txt",1) ''''File to get the machine list.
  31. Call ErrHandle("Opening List of Computers - " & strListPath & "computers.txt") ''''Error handling if the file is unable to open.
  32. Set objTsR = objFso.CreateTextFile(strResultPath & "Alive.txt",2) '''''File to store the results for later review.
  33. Call ErrHandle("Opening Result File - " & strResultPath & "Alive.txt") '''''Error handling if the file is unable to open.
  34. Set objTsN = objFso.CreateTextFile(strResultPath & "NotAlive.txt",2) '''''File to store the results for later review.
  35. Call ErrHandle("Opening Result File - " & strResultPath & "NotAlive.txt") '''''Error handling if the file is unable to open.
  36.  
  37.  
  38.  
  39. intTargetCnt = 0 '''''To Check the number of machines processed.
  40.  
  41. Do Until objTsL.AtEndOfStream
  42. strComputer = objTsL.ReadLine '''''Getting the computer name.
  43. Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
  44. Set colItems = objWMIService.ExecQuery _
  45. ("Select * from Win32_PingStatus " & _
  46. "Where Address = '" & strComputer & "'")
  47. For Each objItem in colItems
  48. If objItem.StatusCode = 0 Then
  49. 'WScript.Echo "Reply received."
  50. 'objTsR.WriteLine ()
  51. objTsR.WriteLine (strComputer)
  52. 'objTsR.WriteLine ()
  53. Else
  54. 'WScript.Echo "No Reply received."
  55. 'objTsN.WriteLine ()
  56. objTsN.WriteLine (strComputer)
  57. 'objTsN.WriteLine ()
  58. End If
  59. Next
  60.  
  61. Loop
  62.  
  63.  
  64. Sub ErrHandle(vActivity) '''''Subroutine for handling the error in file operations.
  65. If err <> 0 Then
  66. vErrText = "There has been a problem with " & vActivity
  67. wscript.echo vErrText & vbcrlf & string(Len(vErrText),"-") & vbcrlf & "Error Number : " & err.number & vbcrlf & " Error Description : " & err.description
  68. CleanUpAndGo
  69. End If
  70. End Sub



-------------------------------------------------------
Save this script in C:\ping folder.
Copy the computer name for which you need to know the ping results in computers.txt file.
Double click on the script .
You will see 2 txt file created in same folder.
One is Alive.txt - Pinging servers
Other one Not- Alive.txt - Not pinging servers
Find all posts by this user
Quote this message in a reply
06-29-2010, 12:42 AM
Post: #2
RE: Script for Pinging multiple servers
Thank you for your contribution! As a side note, the Win32_PingStatus class is only available on Windows XP and newer.

Scripting problems? Windows questions? Ask the Windows Guru!

Stay up to date with all of my latest content. Follow me on Twitter!
[Image: tsig.php]
Help us help you! Post your exact error message with these easy tips!
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  HELP: Script for checking sp level in Win 2000/2003 Servers Hari Kumar 4 1,496 06-29-2010 06:24 PM
Last Post: Hari Kumar

Forum Jump:


Forum Permissions
You cannot post new threads.
You cannot post replies.
You cannot post attachments.
HTML is turned off.
MyCode is turned on.
Smilies are turned on.
[img] is turned on.