Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Please assist with a vbscript to ping a list of computers in a notepad and store the ping results in a notepad.
Posted
Updated 4-Feb-19 21:00pm

1 solution

VB
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[^]
 
Share this answer
 
v3
Comments
AskerSwali 16-Mar-11 3:50am    
Its generatig a runtime error
Prerak Patel 16-Mar-11 4:32am    
Was it that hard to debug?! :doh:
Anyways, updated the answer.
I hope this will work now.
Dalek Dave 16-Mar-11 4:47am    
Good answer (eventually!) :)
Prerak Patel 16-Mar-11 4:48am    
Thanks DD
AskerSwali 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900