Click here to Skip to main content
11,922,641 members (32,183 online)
Rate this:
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
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 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!
Member 10706778 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151125.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