Python WINEVTLOG Open Backup Logs
I am attempting to use the OpenBackupEventLog("",file) to open eventlogs which are saved on a CDrom. I am going through a loop to load each file under the subdirectory. I have two issues at the moment.
1. The script will pull the first file name and output events on screen, however when they reach the end it does not reset. 2. When it goes through the second position of the list it gives an error of file not found.import win32evtlog
e = os.listdir('D:\\SomeDir\\AnotherDir\\')
for item in range(len(e)):
handle = win32evtlog.OpenBackupEventL开发者_运维知识库og("None", e[item])
flags = win32evtlog.EVENTLOG_BACKWARDS_READ|win32evtlog.EVENTLOG_SEQUENTIAL_READ
total = E.GetNumberofEventLogRecords(handle)
print "Total events are: ", total
while True:
event_list = win32evtlog.ReadEventLog(handle, flags, 0)
if event_list:
for event in event_list:
info = (event.EventType,
event.TimeGenerated,
event.SourceName,
event.EventID)
print info
Any help is appreciated; It's like I can't close the connection on with win32evtlog. I have used the win32evtlog.CloseEventLog(handle).
Few items which were causing my issue:
- CDrom or CD was erroring out; I have to copy the files to a temp directory and then process them.
- No break at the end of the loop; if not event: break
精彩评论