Query windows event log with python

2013-01-11 Thread robey . lawrence
Hi,

I am looking to write a short program to query the windows event log.

It needs to ask the user for input for The event type (Critical, Error, and 
Information), and the user needs to be able to specify a date since when they 
want to view results.

I understand I will need the pywin32 extension, which i already have installed.

I found this piece of code to start from,


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
print


Thanks for any help.
Robey
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Query windows event log with python

2013-01-12 Thread robey . lawrence
On Saturday, January 12, 2013 8:34:01 PM UTC+11, Tim Golden wrote:
> On 12/01/2013 06:09, email.addr...@gmail.com wrote:
> 
> > I am looking to write a short program to query the windows event
> 
> > log.
> 
> >
> 
> > It needs to ask the user for input for The event type (Critical,
> 
> > Error, and Information), and the user needs to be able to specify a
> 
> > date since when they want to view results.
> 
> >
> 
> > I found this piece of code to start from,
> 
> 
> 
> [... snip ...]
> 
> 
> 
> Well it looks like you have everything you need. Was there a specific 
> 
> question you wanted to ask?
> 
> 
> 
> TJG

yes, I would like to run it in Command prompt and ask the user at the time what 
type and date of Event they would like to view. so i was wondering where in the 
code I could put something like "var=raw_input"

Thanks TJG
-- 
http://mail.python.org/mailman/listinfo/python-list