I am working on a program and need ot know how I would read a specific entry to the Windows Event Log based on a Record number, which this script will already have. Below is
No! There are no functions available which allows you to obtain the event based on event id.
Reference: 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 other method of interest is reading the oldest event.
You will have to iterate through the results any way and your approach is correct :)
You can only change the form of your approach like below but this is unnecessary.
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
This is just the same way as you are doing but more succinct