Not! There are no functions available that allow you to retrieve an event based on the event ID.
Link: Event Logging Functions
GetNumberOfEventLogRecords Retrieves the number of records in the specified event log. GetOldestEventLogRecord Retrieves the absolute record number of the oldest record in the specified event log. NotifyChangeEventLog Enables an application to receive notification when an event is written to the specified event log. ReadEventLog Reads a whole number of entries from the specified event log. RegisterEventSource Retrieves a registered handle to the specified event log.
Only another method of interest is the oldest event.
You will have to go through the results in any way, and your approach is correct :)
You can change the form of your approach, as shown below, but this is optional.
events = win32evtlog.ReadEventLog(hand, flags,0) events_list = [event for event in events if event.EventID == "27035"] if event_list: print 'Event Category:', events_list[0].EventCategory
It is the same as you do, but more concise
pyfunc
source share