Click here to Skip to main content
11,806,026 members (53,984 online)
Rate this: bad
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 21:09pm

1 solution

Rate this: bad
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 )
Do until objTextIn.AtEndOfStream = True
    strComputer = objTextIn.ReadLine
        if fPingTest( strComputer ) then
             strStatus = "UP"
             strStatus = "DOWN"
        end if
        objTextOut.WriteLine(strComputer & "," & strStatus)
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
                flag = FALSE
        end if
        fPingTest = flag
end function

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!
Member 10706778 at 27-Sep-15 19:42pm
Is it possible to check list of servers at a particular time. For example, if I have a list of 30 different servers that are to be checked at 30 different given time?? if possible then what changes are to be made to the source code?

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

  Print Answers RSS
0 Richard Deeming 225
1 OriginalGriff 215
2 Sergey Alexandrovich Kryukov 170
3 ppolymorphe 125
4 Abhinav S 118
0 OriginalGriff 3,300
1 Maciej Los 1,990
2 KrunalRohit 1,907
3 CPallini 1,855
4 Richard MacCutchan 1,227

Advertise | Privacy | Mobile
Web02 | 2.8.151002.1 | Last Updated 16 Mar 2011
Copyright © CodeProject, 1999-2015
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