Question

I want to get all stored event logs of my windows 8 machine using python 3.3 (especially the mouse event logs). I found a way of getting the event log file with win32evtlog module in python. By reading the "System" logtype, I get a total number of 6594.

import win32evtlog

hand  = win32evtlog.OpenEventLog("localhost","System")
flags = win32evtlog.EVENTLOG_BACKWARDS_READ| win32evtlog.EVENTLOG_SEQUENTIAL_READ
total = win32evtlog.GetNumberOfEventLogRecords(hand)
print("Total Number of Events:",total)

>> Total Number of Events: 6594

I suppose the mouse event logs an all other logs of a certain amount of size are in these approx. 6600 event logs. But when i try to loop/iterate over the events to get the information iwant, i just get back 3 event log objects.

import win32evtlog

hand  = win32evtlog.OpenEventLog("localhost","System")
flags = win32evtlog.EVENTLOG_BACKWARDS_READ| win32evtlog.EVENTLOG_SEQUENTIAL_READ

events = win32evtlog.ReadEventLog(hand,flags,0)
print("LEN of event objects stored:",len(events),end="\n"*2)

>> LEN of event objects stored: 3

Am I on a wrong path for the solution ? Or do you see whats wrong here ? Everytime thankful for any help

Was it helpful?

Solution

I got the very same issue while trying to get startup and shutdown events. Apparently the issue is just the way you browse the events list, it should be done like here : http://www.blog.pythonlibrary.org/2010/07/27/pywin32-getting-windows-event-logs/

events = win32evtlog.ReadEventLog(hand,flags,0) while events: events=win32evtlog.ReadEventLog(hand,flags,0) for event in events: #do stuff here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top