I am trying to write a script that I thought would be simple to copy a single
filr to many pc's. The script fails with a path not found error. If I write
the line out it is a valid path. It is failing on where to copy the file.
The code opens a text file and reads the names of pc's that are that.
Currently just in testing and failing with 2 systems in the file.
Any help is greatly appreciated
Here is my code:
On Error Resume Next
'get main objects/variables
Dim strPath, strFileToRead, strLogFile
strPath = "C:\CopyWinPrint\"
strFileToRead = "computers.txt"
strLogFile = "log.txt"
Dim strComputers
Dim fsoRead, tsRead
Const ForReading = 1
Set fsoRead = CreateObject("Scripting.FileSystemObject")
Set tsRead = fsoRead.OpenTextFile(strPath & strFileToRead, ForReading)
strComputers = tsRead.ReadAll
tsRead.Close
Set fsoRead = Nothing
strComputers = Split(strComputers, vbCrLf)
Set oFso = CreateObject("Scripting.FileSystemObject")
For x = 0 to UBound(strComputers)
strOut = ""
strComputersText = Trim(CStr(strComputers(x)))
'strComputersText = "RIC0000016"
Set oFso_fileName =
oFso.GetFile("\\riclog01\deploy\Assist_Rollout\Winprint\winprint.exe")
oFso_fileName.Copy "\\" & strComputersText &
"\c$\WINDOWS\system32\winprint.exe" , True
'MsgBox("\\" & strComputersText & "\c$\WINDOWS\system32\winprint.exe")
If Err.Number <> 0 Then
strOut = strOut & vbCrLf & strComputersText & vbTab & err.description & "!"
Err.Clear
Else
strOut = strOut & vbCrLf & strComputersText & vbTab & "No error!"
End If
Next
Dim fsoWrite, tsWrite
Const ForWriting = 2
Set fsoWrite = CreateObject("Scripting.FileSystemObject")
Set tsWrite = fsoWrite.CreateTextFile(strPath & strLogFile, True)
tsWrite.WriteLine(strOut)
tsWrite.Close
Set fsoWrite = Nothing