I'm trying to automatically backup my log files and the script seems to work until it starts the
For Each objLogfile in colLogFiles portion of the script. I get an0x8004107 error and it spits back a null value.
So I'm guessing the evtLog(i) variable in this set method is wrong but after spending the morning trying to figure it out....I'm missing some hair...have broken half a dozen pencils...ya know how it is.
Set colLogFiles = objWMIService.ExecQuery _
("Select * from Win32_NTEventLogFile where LogFileName=' ' & evtLog(i)")
Can anyone help out a noob?
For Each objLogfile in colLogFiles portion of the script. I get an0x8004107 error and it spits back a null value.
So I'm guessing the evtLog(i) variable in this set method is wrong but after spending the morning trying to figure it out....I'm missing some hair...have broken half a dozen pencils...ya know how it is.
Set colLogFiles = objWMIService.ExecQuery _
("Select * from Win32_NTEventLogFile where LogFileName=' ' & evtLog(i)")
Can anyone help out a noob?
Code:
Option Explicit
'On Error Resume Next
'Declared Variables
Dim strComputer
Dim log
Dim objLogfile
Dim dtmThisDay, dtmThisMonth, dtmThisYear
Dim strBackupName
Dim evtLog
Dim colLogFiles
Dim objWMIService
Dim errBackupLog
Dim i
'Setting variables
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Backup)}!\\" & _
strComputer & "\root\cimv2")
dtmThisDay = Day(Date)
dtmThisMonth = Month(Date)
dtmThisYear = Year(Date)
strBackupName = dtmThisYear & "_" & dtmThisMonth & "_" & dtmThisDay
evtLog = Array("Application", "Securtity", "System")
i = 0
'Include event logs in a array to be used later in the script
Set colLogFiles = objWMIService.ExecQuery _
("Select * from Win32_NTEventLogFile where LogFileName=' ' & evtLog(i)")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate,(Backup,security)}!\\" & _
strComputer & "\root\cimv2")
'Begin backup of event logs
For i = 0 To 2
Wscript.Echo("starting 1 " & evtLog(i)) 'troubleshooting process
For Each objLogfile in colLogFiles
Wscript.Echo("starting 2") 'troubleshooting process
errBackupLog = objLogFile.BackupEventLog("C:\Documents and Settings\macneill\My Documents\logs\evtLog(i)" & strBackupName & ".evt")
Wscript.Echo("starting 3") 'troubleshooting process
If errBackupLog <> 0 Then
Wscript.Echo "The evtLog(i) event log could not be backed up."
End If
Next
Wscript.Echo("starting pass 4") 'troubleshooting process
Next