Simple Python tool for analyzing Windows Event Logs.

The script scans system events and helps find errors, warnings and crashes.
Useful for troubleshooting Windows problems and checking system stability.

  • - Scan Windows Event Logs
  • - Detect errors and warnings
  • - Show event ID and source
  • - Find application crashes
  • - Display detailed event messages
  • - Fast and lightweight

Code:
pip install pywin32
Code:
import win32evtlog
import win32con
from datetime import datetime


LOG_NAME = "System"

LEVELS = {
    1: "CRITICAL",
    2: "ERROR",
    3: "WARNING",
    4: "INFO"
}


def get_events(log_name, limit=50):
    try:
        hand = win32evtlog.OpenEventLog(None, log_name)

        flags = (
            win32evtlog.EVENTLOG_BACKWARDS_READ |
            win32evtlog.EVENTLOG_SEQUENTIAL_READ
        )

        events = []

        while len(events) < limit:
            records = win32evtlog.ReadEventLog(hand, flags, 0)

            if not records:
                break

            for event in records:
                level = event.EventType

                if level in [
                    win32con.EVENTLOG_ERROR_TYPE,
                    win32con.EVENTLOG_WARNING_TYPE
                ]:
                    events.append(event)

                    if len(events) >= limit:
                        break

        win32evtlog.CloseEventLog(hand)

        return events

    except Exception as e:
        print(f"Error reading event log: {e}")
        return []


def show_events(events):

    print("=" * 50)
    print(" Windows Event Log Analyzer")
    print("=" * 50)

    if not events:
        print("\nNo errors found.")
        return

    for event in events:

        timestamp = event.TimeGenerated.strftime(
            "%Y-%m-%d %H:%M:%S"
        )

        source = event.SourceName
        event_id = event.EventID & 0xFFFF

        messages = event.StringInserts

        print("\n[!] Event Found")
        print("-" * 50)

        print(f"Time: {timestamp}")
        print(f"Source: {source}")
        print(f"Event ID: {event_id}")

        if messages:
            print("Message:")
            for msg in messages[:3]:
                print(f"  {msg}")

        print("-" * 50)


def main():

    print("\nScanning Windows Event Logs...\n")

    events = get_events(LOG_NAME, 20)

    show_events(events)


if __name__ == "__main__":
    main()