Re: Copy file from one computer to hall the computers in my Lan by Ginolard
Ginolard
Fri May 27 08:56:49 CDT 2005
Try this. It will read in the list of machines, test if the machine is
online (if not, write an error to the log) and then try to copy the
file and log an error if it fails for any reason
On Error Resume Next
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
sPath = "path to your file
sdest="destination"
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set Logfile=objFSO.OpenTextFile("c:\temp\CopyFile.log",ForWriting,True)
fileIn=objFSO.OpenTextFile("path to file containing
machines",ForReading).ReadAll
strComputer = Split(fileIn,VbCrLf)
For i = 0 to UBound(strComputer)
If IsConnectible(strComputer(i)) Then
Call CopyFile(strComputer(i))
Else Logfile.Writeline strComputer(i) & " Not online" & VbCrLf
End If
Next
Private Function CopyFile()
Result=objFso.CopyFile (spath,"\\" & strcomputer(i) & sdest)
If Err.Number >0 Then
Logfile.Writeline "There was an error copying the file to " &
strComputer(i) & VbCrLf
End If
End Function
Function IsConnectible(PCName)
IsConnectible=False
Set objPing = GetObject("winmgmts:{impersonationLevel=impersonate}")._
ExecQuery("select * from Win32_PingStatus where address = '" &
PCName & "'")
For Each objStatus in objPing
If Not IsNull (objStatus.ReplySize) Then
IsConnectible = True
End If
Next
End Function