home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_2451 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  3.2 KB  |  106 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import win32evtlog
  5. import traceback
  6. import win32api
  7. import win32con
  8. import win32security
  9. from win32evtlogutil import *
  10.  
  11. def ReadLog(computer, logType = 'Application', dumpEachRecord = 0):
  12.     h = win32evtlog.OpenEventLog(computer, logType)
  13.     numRecords = win32evtlog.GetNumberOfEventLogRecords(h)
  14.     num = 0
  15.     while None:
  16.         objects = win32evtlog.ReadEventLog(h, win32evtlog.EVENTLOG_BACKWARDS_READ | win32evtlog.EVENTLOG_SEQUENTIAL_READ, 0)
  17.         if not objects:
  18.             break
  19.         
  20.         for object in objects:
  21.             msg = SafeFormatMessage(object, logType).encode('mbcs')
  22.             if object.Sid is not None:
  23.                 
  24.                 try:
  25.                     (domain, user, typ) = win32security.LookupAccountSid(computer, object.Sid)
  26.                     sidDesc = '%s/%s' % (domain, user)
  27.                 except win32security.error:
  28.                     sidDesc = str(object.Sid)
  29.  
  30.                 user_desc = 'Event associated with user %s' % (sidDesc,)
  31.             else:
  32.                 user_desc = None
  33.             if dumpEachRecord:
  34.                 if user_desc:
  35.                     print user_desc
  36.                 
  37.                 print msg
  38.                 continue
  39.         
  40.         num = num + len(objects)
  41.         continue
  42.         if numRecords == num:
  43.             print 'Successfully read all', numRecords, 'records'
  44.         else:
  45.             print "Couldn't get all records - reported %d, but found %d" % (numRecords, num)
  46.             print '(Note that some other app may have written records while we were running!)'
  47.     win32evtlog.CloseEventLog(h)
  48.  
  49.  
  50. def Usage():
  51.     print 'Writes an event to the event log.'
  52.     print '-w : Dont write any test records.'
  53.     print '-r : Dont read the event log'
  54.     print '-c : computerName : Process the log on the specified computer'
  55.     print '-v : Verbose'
  56.     print "-t : LogType - Use the specified log - default = 'Application'"
  57.  
  58.  
  59. def test():
  60.     if win32api.GetVersion() & 0x80000000L:
  61.         print 'This sample only runs on NT'
  62.         return None
  63.     import sys
  64.     import getopt
  65.     (opts, args) = getopt.getopt(sys.argv[1:], 'rwh?c:t:v')
  66.     computer = None
  67.     logType = 'Application'
  68.     verbose = 0
  69.     if len(args) > 0:
  70.         print 'Invalid args'
  71.         usage()
  72.         return 1
  73.     for opt, val in opts:
  74.         if opt == '-c':
  75.             computer = val
  76.         
  77.         if opt in ('-h', '-?'):
  78.             Usage()
  79.             return None
  80.         if opt == '-r':
  81.             do_read = 0
  82.         
  83.         if opt == '-w':
  84.             do_write = 0
  85.         
  86.         if opt == '-v':
  87.             verbose = verbose + 1
  88.             continue
  89.     
  90.     if do_write:
  91.         ReportEvent(logType, 2, strings = [
  92.             'The message text for event 2'], data = 'Raw\x00Data')
  93.         ReportEvent(logType, 1, eventType = win32evtlog.EVENTLOG_WARNING_TYPE, strings = [
  94.             'A warning'], data = 'Raw\x00Data')
  95.         ReportEvent(logType, 1, eventType = win32evtlog.EVENTLOG_INFORMATION_TYPE, strings = [
  96.             'An info'], data = 'Raw\x00Data')
  97.         print 'Successfully wrote 3 records to the log'
  98.     
  99.     if do_read:
  100.         ReadLog(computer, logType, verbose > 0)
  101.     
  102.  
  103. if __name__ == '__main__':
  104.     test()
  105.  
  106.