WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WMI
plus
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Backup Event Log

 Keywords: Read Backup Event Log Eventlog Application CSV Array WMI 

This code reads the entire Application event log using WMI and it stores the data into an array then ultimately writes the data out to a CSV file.
objSWbemLocator = ObjectGet("winmgmts:")
objEventSet = objSWbemLocator.ExecQuery("select * from Win32_NTLogEvent where Logfile='Application'")
count = objEventSet.Count
If count == 0
   Message("Notice","No Events")
   objEventSet = 0
   objSWbemLocator = 0
   Exit
EndIf

;Create an array to store all the data
;Columns = RecordNumber,Type,SourceName,Message,TimeWritten,EventCode
arrEvents = ArrDimension(count, 6 )
Column = 0
ForEach LogEvent In objEventSet
   arrEvents[column, 0] = LogEvent.RecordNumber
   arrEvents[column, 1] = LogEvent.Type
   arrEvents[column, 2] = LogEvent.SourceName
   arrEvents[column, 3] = LogEvent.Message
   DMTF_date = LogEvent.TimeWritten
   yr =  StrSub(DMTF_date,1,4)
   mnth  = StrSub(DMTF_date,5,2)
   day = StrSub(DMTF_date,7,2)
   hr = StrSub(DMTF_date,9,2)
   mins = StrSub(DMTF_date,11,2)
   secs = StrSub(DMTF_date,13,2)
   YMDHMS_date = StrCat(yr,":",mnth,":",day,":",hr,":",mins,":",secs)
   arrEvents[column, 4] = YMDHMS_date
   arrEvents[column, 5] = LogEvent.EventCode
   Column =  Column + 1
Next
objEventSet = 0
objSWbemLocator = 0

; Write Array out to CSV file
ArrayFilePutCSV('D:\temp\appeventlog.csv', arrEvents, ',' )
Exit

Article ID:   W18465
Filename:   Backup Event Log.txt
File Created: 2009:06:16:14:30:48
Last Updated: 2009:06:16:14:30:48