VBscript to output the results of a ping to XML file

I am looking to ping several servers and return a value depending on whether there is any response. I am wondering the most efficient way to do this...

1. Ping serverA
2. If there is ANY reply, write "serverA, 0" to a XML file
3. If there is no reply, write "serverA, 1" to a XML file
4. When all ten servers have been "pinged", set future updates to overwrite existing entries and repeat the pinging once the end of serverlist is reached. (overwrite since this file will be queried by a web app concerning server responsiveness)

Thank you!
John DarbyPMAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

How about something like this?

Dim Servers(9)
Servers(0) = ""
Servers(1) = ""
Servers(2) = ""
Servers(3) = ""
Servers(4) = ""
Servers(5) = ""
Servers(6) = ""
Servers(7) = ""
Servers(8) = ""
Servers(9) = ""

Dim wShell,x,r,Tmp,fso,fil,xml
Set wShell = CreateObject("Wscript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")

Set xml = fso.CreateTextFile("C:\test.xml")

xml.WriteLine "<?xml version=" & chr(34) & "1.0" & chr(34) & _
    " encoding=" & chr(34) & "UTF-8" & chr(34) & " ?>"

xml.writeline "<Servers>"

Tmp = "C:\tmp.txt"
For x = LBound(Servers) to UBound(Servers)
     wShell.Run "%COMSPEC% /c ping -n 1 " & Servers(x) & " > " &  Tmp,0,True
     set fil = fso.OpenTextFile("C:\tmp.txt",1,True)
     if Instr(fil.ReadAll,"Received = 1") Then
      xml.writeline vbTab & "<ServerInf>"
      xml.writeline vbTab & vbTab & "<ServerRsp>" &  Servers(x) & ",0" & "</ServerRsp>"
      xml.writeline vbTab & "</ServerInf>"
      xml.writeline vbTab & "<ServerInf>"
      xml.writeline vbTab & vbTab &  "<ServerRsp>" &  Servers(x) & ",0" & "</ServerRsp>"
      xml.writeline vbTab & "</ServerInf>"
     end if


xml.writeline "</Servers>"

set xml = Nothing
set fil = Nothing
Set fso = Nothing
Set wShell = Nothing

MsgBox "done"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
John DarbyPMAuthor Commented:
In your experience, would it take longer for the script to run if the list of servers was an separate text file? I have about 192 of them and may be adding more, later. Otherwise, I am sure the splendid example you've created is a great tool.

Thank you!
It shouldn't take longer reading the server names from a text file.Instead of the array just use the fso object to open the text file and then use ReadLine to read the names from the file.
John DarbyPMAuthor Commented:
I did just that...it runs through 192 servers in 26 seconds, or so.

Do you think this would run faster as a complied VB app? I think the bottleneck is waiting for ICMP response?
I agree that the bottleneck is waiting for the icmp reply.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.