# Ping multiple computer with results



## bparker (Nov 11, 2004)

I am looking to make a script or batch file but I have no idea how to do this.

I need to ping all computers in my domain, which are listed in a text file. I would like the results to be output into two seperate text files in a list form of what computers can be pinged and what computers can't be pinged, no other info, just list the computers.

Any help would be much appreciated.

Thanks


----------



## tomdkat (May 6, 2006)

Wow, you are NOT going to believe this! I believe I found a DOS batch file which does what you want here.

Hope that helps!

Peace...


----------



## Squashman (Apr 4, 2003)

We were also doing something similar in another thread on the forums this past week.


----------



## bparker (Nov 11, 2004)

where is the thread?


----------



## Squashman (Apr 4, 2003)

http://forums.techguy.org/windows-xp/915378-help-making-automated-ping-batch.html


----------



## bparker (Nov 11, 2004)

Thanks for the response but that did not work as planned. I have since found another script which works perfectly as I want it to but it seems to fail half way through and I don't know why.

Basically I am pushing out a file and creating two txt files that tell me whether the file failed to copy or not. The problem is that it gets through half of the computers and fails with the followint.

Script: C:\testing\ping\copy file with output.vbs
Line: 15
Char: 9
Error: 800A004C
Source: Microsoft VBScript runtime error

and here is my script


```
Const ForReading = 1 
Const OverwriteExisting = True 
  
Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objFile=objFSO.OpenTextfile("allcomp.txt") 
Set objOutput = objFSO.CreateTextfile("Succeed.txt") 
Set objOutput2 = objFSO.CreateTextfile("Fail.txt") 

  
Do Until objFile.AtEndOfStream 
        strComputer=objFile.ReadLine 
  
        If Ping(strComputer) = True Then 
        strRemoteFile = "\\" & strComputer & "\C$\program files\lansweeper\" 
        objFSO.CopyFile "c:\program files\lansweeper\client\lsclient.exe", strRemoteFile, OverwriteExisting 
        objOutput.WriteLine (strComputer) 
        Else 
                objOutput2.WriteLine (strComputer) 
        End If 
Loop 
  
msgbox "Done"  
  
Function Ping(strComputer) 
        Dim objShell, boolCode 
        Set objShell = CreateObject("WScript.Shell") 
        boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True) 
        If boolCode = 0 Then 
                Ping = True 
        Else 
                Ping = False 
        End If 
End Function
```


----------



## Squashman (Apr 4, 2003)

When not just do WOL to turn on all the computers, then do what you need to do.


----------



## bparker (Nov 11, 2004)

I also have mobile pcs that are not always connected to the network. I need to know which ones have not been updated. I also need to know which ones have been updated because I need to run further scripts on them.


----------



## Squashman (Apr 4, 2003)

Isn't that what login scripts are for?


----------



## TheOutcaste (Aug 8, 2007)

The error means Path not Found, meaning that one of the PCs doesn't have that folder, *c:\program files\lansweeper*
Could be that PC uses *D:\program files\lansweeper*, the particular program was never installed, or possibly the PC was shutting down; it was able to respond to the Ping, but refused the copy as it is shutting down. Could just be a glitch.

You'd have to look at both the *Succeed.txt* and *Fail.txt* files, see which was the last PC attempted, then look in the *allcomp.txt* file to see which one was being attempted.

Or you can add error checking to the script. This wil output the error number and PC name to the *Fail.txt* file if an error occurs, but will continue untill all the PCs have been tried.
New lines in red:

```
Const ForReading = 1 
Const OverwriteExisting = True 

Set objFSO = CreateObject("Scripting.FileSystemObject") 
Set objFile=objFSO.OpenTextfile("allcomp.txt") 
Set objOutput = objFSO.CreateTextfile("Succeed.txt") 
Set objOutput2 = objFSO.CreateTextfile("Fail.txt") 

[COLOR=Red]On Error Resume Next[/COLOR]
Do Until objFile.AtEndOfStream 
  strComputer=objFile.ReadLine 

  If Ping(strComputer) = True Then 
    strRemoteFile = "\\" & strComputer & "\C$\program files\lansweeper\" 
    objFSO.CopyFile "c:\program files\lansweeper\client\lsclient.exe", strRemoteFile, OverwriteExisting
    [COLOR=Red]If Err.Number = 0 Then[/COLOR]
      objOutput.WriteLine (strComputer)
    [COLOR=Red]Else
      strError = "Error " & Err.Number & " occurred while copying to " & strComputer
      objOutput2.WriteLine (strError)
    End If[/COLOR]
  Else 
          objOutput2.WriteLine (strComputer) 
  End If 
Loop 
  
msgbox "Done"  
  
Function Ping(strComputer) 
        Dim objShell, boolCode 
        Set objShell = CreateObject("WScript.Shell") 
        boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True) 
        If boolCode = 0 Then 
                Ping = True 
        Else 
                Ping = False 
        End If 
End Function
```


----------

