I’m trying to make a script that will allow me to copy a specified file to a predefined list of PCs (C:\PCs.txt). I’d like to have this script write to a separate file (C:\MassCopyError.txt) for each PC that fails, then notify me when it’s finished.
So far, I’m able to copy the file without error, and I’m able to write the first PC that fails, but I can’t get it to write more than one error, and I can’t get it to notify me when it’s finished. It just copies, notifies me there’s been one error, logs one error, and closes out. Any ideas what I’m doing wrong? I know this would be easier in pure VB or even C++, but I’m trying to do it in VBS.
On Error Resume Next
Const ForReading = 1
Const ForAppending = 8
Const OverwriteExisting = TRUE
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\PCs.txt", ForReading)
dim currentFileLocation
dim newFileLocation
currentFileLocation=InputBox("What is the file's current location?", "Current File Location")
newFileLocation=InputBox("Where would you like the file to go?", "New File Location")
Do Until objFile.AtEndOfStream
On Error Resume Next
strComputer = objFile.ReadLine
strRemoteFile = "\\" & strComputer & "\" & newFileLocation & "\"
objFSO.CopyFile currentFileLocation, strRemoteFile, OverwriteExisting
Loop
If Err.Number <> 0 Then
wscript.Echo "An error has occurred. Please see C:\MassCopyError.txt for details"
Set objFile = objFSO.CreateTextFile("C:\MassCopyError.txt")
Set objFile = obj.FSO.OpenTextFile ("C:\MassCopyError.txt", ForAppending, True)
objFile.WriteLine(strComputer&vbCrLf)
objFile.Close
Err.Clear
End If
wscipt.Echo "MassCopy has finished copying files."