Search code examples
loggingvbscript

Creating a log with VBS


I currently have the following script copying a certain folder to every computer in computers.txt. Though it skips computers that are turned off obviously, but I would like to know which computers have been skipped or at least which computers succeeded.

InputFile = "c:\scripts\input\computers.Txt"
Const OverWriteFiles = True
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(InputFile)
Do While Not (objFile.AtEndOfStream)
strComputer = objFile.ReadLine
On Error Resume Next
objFSO.CopyFolder "\\baardrob\Software\PACS Beheer Tools\PACS Beheer Tools" , "\\" & strComputer & "\c$\PACS Beheer Tools\Pacs starten" , OverWriteFiles
Err.Clear
Loop

MsgBox "Done" 

Solution

  • Something like this should do:

    Set myLog = objFSO.OpenTextFile("C:\path\to\my.log", 2)
    Do Until objFile.AtEndOfStream
      strComputer = objFile.ReadLine
      On Error Resume Next
      objFSO.CopyFolder ...
      If Err Then myLog.WriteLine strComputer & vbTab & Err.Number & vbTab _
        & Err.Description
      On Error Goto 0
    Loop
    myLog.Close