Listing 2: Code That Performs the Backup and Copy Operations Do Until objRecordset.EOF TransactionLog.WriteLine("") Err.Clear strComputer = "" strComputer = objRecordSet.Fields("CN").Value If Trim(strComputer) <> "" Then Set objWMIService = nothing Set colLogFiles = nothing ' ******* BEGIN CALLOUT A ******* Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate,(Backup,Security)}!\\" & _ strComputer & "\root\cimv2") ' ******* END CALLOUT A ******* If Err.Number <> 0 Then TransactionLog.WriteLine("CONNECTION ERROR on " & _ strComputer & " Error:" & Err.Number & " " & Err.Description) Err.Clear Else ' ******* BEGIN CALLOUT B ******* ' Create the event-log backup folder if it doesn't exist on the local computer. If Not fso.FolderExists("\\" & strComputer & "\" & _ Replace(EventLogBackupDir,":","$")) Then Set Newfolder = fso.CreateFolder("\\" & strComputer & "\" & _ Replace(EventLogBackupDir,":","$")) End If ' ******* END CALLOUT B ******* ' ******* BEGIN CALLOUT C ******* Set colLogFiles = _ objWMIService.ExecQuery("Select * from Win32_NTEventLogFile") For Each objEvtLogFile in colLogFiles OldEvtLog = "" OldEvtLog = "\\" & strComputer & "\" & _ Replace(EventLogBackupDir,":","$") & _ objEvtLogFile.Filename & "." & objEvtLogFile.Extension ' Delete previous backup. Err.Clear If fso.FileExists(OldEvtLog) Then fso.DeleteFile(OldEvtLog) If Err.Number <> 0 Then TransactionLog.WriteLine("DELETE ERROR on " & OldEvtLog & _ " Error " & Err.Number & " " & Err.Description) Err.Clear End If End If ' ******* END CALLOUT C ******* ' ******* BEGIN CALLOUT D ******* ' Back up the event log on the local computer. BackupLog = objEvtLogFile.BackupEventLog(EventLogBackupDir & _ objEvtLogFile.Filename & "." & objEvtLogFile.Extension) ' A value of 0 indicates success. If BackupLog = 0 Then TransactionLog.WriteLine(strComputer & " " & objEvtLogFile.Filename & _ "." & objEvtLogFile.extension & _ " EventLog backed up to \\" & strComputer & "\" & EventLogBackupDir & _ objEvtLogFile.Filename & "." & objEvtLogFile.extension) Else TransactionLog.WriteLine("DID NOT BACKUP " & strComputer & " " & _ objEvtLogFile.Filename & "." & objEvtLogFile.extension & _ " to " & strComputer & "\" & EventLogBackupDir & _ " ...BackupEventLog Return Code: " & BackupLog) End If ' ******* END CALLOUT D ******* ' ******* BEGIN CALLOUT E ******* ' Prepare the backup file for copying. copythis = "" copythis = "\\" & strComputer & "\" & Replace(EventLogBackupDir,":","$") & _ objEvtLogFile.Filename & "." & objEvtLogFile.extension Err.Clear Set sourcefile = fso.GetFile(copythis) If Err.Number <> 0 Then TransactionLog.WriteLine("ERROR GETTING " & copythis & _ " in preparation for copying Backed-up EventLog to remote " & _ destination. Error " & Err.Number & " " & Err.Description) Err.Clear Else ' ALTERNATIVES THAT CAN BE USED WHEN COPYING ' BACKED-UP EVENT LOGS ' ALTERNATIVE 1 ' Include the computer's name in the backup file's name. ' DestMachine = Dest & strComputer & "_" & _ ' objEvtLogFile.Filename & "." & objEvtLogFile.Extension ' sourcefile.Copy(DestMachine) ' Destination = Dest ' ALTERNATIVE 2 ' Include the computer's name and a timestamp in the backup file's name. ' DestStamp = Dest & strComputer & "_" & _ ' objEvtLogFile.Filename & "_" & timestamper & "." & objEvtLogFile.Extension ' sourcefile.Copy(DestStamp) ' Destination = Dest ' ALTERNATIVE 3 ' Copy the backup files into a destination folder named after the computer. ' This is the default action. computerFolder = Dest & strComputer & "\" If Not fso.FolderExists(computerFolder) Then Set Makefolder = fso.CreateFolder(computerFolder) If Err.Number <> 0 Then TransactionLog.WriteLine("ERROR CREATING FOLDER " & _ computerFolder & " Error " & Err.Number & " " & Err.Description) Destination = computerFolder Else sourcefile.Copy(computerFolder) Destination = computerFolder End If Else sourcefile.Copy(computerFolder) Destination = computerFolder End If ' END OF ALTERNATIVES If Err.Number <> 0 Then TransactionLog.WriteLine("ERROR COPYING " & copythis & _ " to " & Destination & " Error " & Err.Number & " " & Err.Description) Err.Clear Else TransactionLog.WriteLine("Successful Copy " & copythis & " to " & Destination) End If End If ' ******* END CALLOUT E ******* Next End If