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

Re: script to copy file by Pegasus

Pegasus
Thu Mar 06 15:39:08 CST 2008

"Mike" <Mike@discussions.microsoft.com> wrote in message
news:7B4C9D77-4E79-472C-A827-8D4EF5F7CD0A@microsoft.com...
>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

My lazy nature protests when I see VB Script code that spans 50
or so lines to perform a task that can be performed with a standard
command of one single line, e.g. like so:
@echo off
for /F %%a in (C:\CopyWinPrint\computers.txt) do xcopy /d /y /c
\\riclog01\deploy\Assist_Rollout\Winprint\winprint.exe
\\%%a\c$\WINDOWS\system32

Make sure to unwrap line #2 into a single, long line!