Last active
July 25, 2021 08:16
-
-
Save luzfcb/c0c995d6fc10a227ee25 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- 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