home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.6)
-
- import win32evtlog
- import traceback
- import win32api
- import win32con
- import win32security
- from win32evtlogutil import *
-
- def ReadLog(computer, logType = 'Application', dumpEachRecord = 0):
- h = win32evtlog.OpenEventLog(computer, logType)
- numRecords = win32evtlog.GetNumberOfEventLogRecords(h)
- num = 0
- while None:
- objects = win32evtlog.ReadEventLog(h, win32evtlog.EVENTLOG_BACKWARDS_READ | win32evtlog.EVENTLOG_SEQUENTIAL_READ, 0)
- if not objects:
- break
-
- for object in objects:
- msg = SafeFormatMessage(object, logType).encode('mbcs')
- if object.Sid is not None:
-
- try:
- (domain, user, typ) = win32security.LookupAccountSid(computer, object.Sid)
- sidDesc = '%s/%s' % (domain, user)
- except win32security.error:
- sidDesc = str(object.Sid)
-
- user_desc = 'Event associated with user %s' % (sidDesc,)
- else:
- user_desc = None
- if dumpEachRecord:
- if user_desc:
- print user_desc
-
- print msg
- continue
-
- num = num + len(objects)
- continue
- if numRecords == num:
- print 'Successfully read all', numRecords, 'records'
- else:
- print "Couldn't get all records - reported %d, but found %d" % (numRecords, num)
- print '(Note that some other app may have written records while we were running!)'
- win32evtlog.CloseEventLog(h)
-
-
- def Usage():
- print 'Writes an event to the event log.'
- print '-w : Dont write any test records.'
- print '-r : Dont read the event log'
- print '-c : computerName : Process the log on the specified computer'
- print '-v : Verbose'
- print "-t : LogType - Use the specified log - default = 'Application'"
-
-
- def test():
- if win32api.GetVersion() & 0x80000000L:
- print 'This sample only runs on NT'
- return None
- import sys
- import getopt
- (opts, args) = getopt.getopt(sys.argv[1:], 'rwh?c:t:v')
- computer = None
- logType = 'Application'
- verbose = 0
- if len(args) > 0:
- print 'Invalid args'
- usage()
- return 1
- for opt, val in opts:
- if opt == '-c':
- computer = val
-
- if opt in ('-h', '-?'):
- Usage()
- return None
- if opt == '-r':
- do_read = 0
-
- if opt == '-w':
- do_write = 0
-
- if opt == '-v':
- verbose = verbose + 1
- continue
-
- if do_write:
- ReportEvent(logType, 2, strings = [
- 'The message text for event 2'], data = 'Raw\x00Data')
- ReportEvent(logType, 1, eventType = win32evtlog.EVENTLOG_WARNING_TYPE, strings = [
- 'A warning'], data = 'Raw\x00Data')
- ReportEvent(logType, 1, eventType = win32evtlog.EVENTLOG_INFORMATION_TYPE, strings = [
- 'An info'], data = 'Raw\x00Data')
- print 'Successfully wrote 3 records to the log'
-
- if do_read:
- ReadLog(computer, logType, verbose > 0)
-
-
- if __name__ == '__main__':
- test()
-
-