Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VBScript
Please assist with a vbscript to ping a list of computers in a notepad and store the ping results in a notepad.
Posted 15-Mar-11 22:09pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

dim strInputPath, strOutputPath, strStatus
dim objFSO, objTextIn, objTextOut
 
strInputPath = "c:\serverlist.txt" '- location of input
strOutputPath = "c:\output.csv" '- location of output

set objFSO = CreateObject("Scripting.FileSystemObject")
set objTextIn = objFSO.OpenTextFile( strInputPath,1 )
set objTextOut = objFSO.CreateTextFile( strOutputPath )
objTextOut.WriteLine("computer,status")
 
Do until objTextIn.AtEndOfStream = True
    strComputer = objTextIn.ReadLine
        if fPingTest( strComputer ) then
             strStatus = "UP"
        else
             strStatus = "DOWN"
        end if
        objTextOut.WriteLine(strComputer & "," & strStatus)
loop
 
function fPingTest( strComputer )
        dim objShell,objPing
        dim strPingOut, flag
        set objShell = CreateObject("Wscript.Shell")
        set objPing = objShell.Exec("ping " & strComputer)
    strPingOut = objPing.StdOut.ReadAll
    if instr(LCase(strPingOut), "reply") then
        flag = TRUE
        else
                flag = FALSE
        end if
        fPingTest = flag
 
end function
 

Reference: http://www.tek-tips.com/viewthread.cfm?qid=1125863&page=1[^]
  Permalink  
v3
Comments
AskerSwali at 16-Mar-11 3:50am
   
Its generatig a runtime error
Prerak Patel at 16-Mar-11 4:32am
   
Was it that hard to debug?! :doh:
Anyways, updated the answer.
I hope this will work now.
Dalek Dave at 16-Mar-11 4:47am
   
Good answer (eventually!) :)
Prerak Patel at 16-Mar-11 4:48am
   
Thanks DD
AskerSwali at 16-Mar-11 9:30am
   
Thanks all. it worked like Charm!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 280
1 Jochen Arndt 150
2 Kornfeld Eliyahu Peter 120
3 PIEBALDconsult 110
4 Richard MacCutchan 105
0 OriginalGriff 6,055
1 DamithSL 4,621
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,500
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 16 Mar 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100