Read the windows event log

A

Austin

My codes are below:

***********************************
import win32evtlog

def check_records(records):
for i in range(0,len(records)):
print records.SourceName

h = win32evtlog.OpenEventLog(None,"System")
flags =
win32evtlog.EVENTLOG_BACKWARD_READ|win32evtlog.EVENTLOG_SEQUENTIAL_READ
records = win32evtlog.ReadEventLog(h,flags,0)

print "Total " + str(len(records))
check_records(records)

************************************

The result from my codes are total 2.
But the event log in windows event viewer are 24.
How could I get all events?
 
R

Roger Upole

You'll need to read in a loop until no records are returned.

Roger

Austin said:
My codes are below:

***********************************
import win32evtlog

def check_records(records):
for i in range(0,len(records)):
print records.SourceName

h = win32evtlog.OpenEventLog(None,"System")
flags =
win32evtlog.EVENTLOG_BACKWARD_READ|win32evtlog.EVENTLOG_SEQUENTIAL_READ
records = win32evtlog.ReadEventLog(h,flags,0)

print "Total " + str(len(records))
check_records(records)

************************************

The result from my codes are total 2.
But the event log in windows event viewer are 24.
How could I get all events?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,573
Members
45,046
Latest member
Gavizuho

Latest Threads

Top