Skip to content

Instantly share code, notes, and snippets.

@luzfcb
Last active July 25, 2021 08:16
Show Gist options
  • Select an option

  • Save luzfcb/c0c995d6fc10a227ee25 to your computer and use it in GitHub Desktop.

Select an option

Save luzfcb/c0c995d6fc10a227ee25 to your computer and use it in GitHub Desktop.
# -*- coding: cp1252 -*-
#
# Windows Event Log Viewer
# FB - 201012116
# from http://code.activestate.com/recipes/577499-windows-event-log-viewer/
import win32evtlog # requires pywin32 pre-installed
server = 'localhost' # name of the target computer to get event logs
logtype = 'System' # 'Application' # 'Security'
hand = win32evtlog.OpenEventLog(server,logtype)
flags = win32evtlog.EVENTLOG_BACKWARDS_READ|win32evtlog.EVENTLOG_SEQUENTIAL_READ
total = win32evtlog.GetNumberOfEventLogRecords(hand)
while True:
events = win32evtlog.ReadEventLog(hand, flags,0)
if events:
for event in events:
print('Event Category:', event.EventCategory)
print('Time Generated:', event.TimeGenerated)
print('Source Name:', event.SourceName)
print('Event ID:', event.EventID)
print('Event Type:', event.EventType)
data = event.StringInserts
if data:
print('Event Data:')
for msg in data:
print(msg.encode('cp1252','ignore'))
print("")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment