Click here to Skip to main content
11,704,509 members (53,353 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!

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 700
1 OriginalGriff 495
2 CPallini 267
3 Andy Lanng 259
4 Maciej Los 235
0 OriginalGriff 8,824
1 Sergey Alexandrovich Kryukov 8,247
2 CPallini 5,189
3 Maciej Los 4,726
4 Mika Wendelius 3,606

Advertise | Privacy | Mobile
Web04 | 2.8.150819.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