EvtSubscribe_pull.py 675 B

123456789101112131415161718192021
  1. ## Demonstrates how to create a "pull" subscription
  2. import win32evtlog, win32event, win32con
  3. query_text='*[System[Provider[@Name="Microsoft-Windows-Winlogon"]]]'
  4. h=win32event.CreateEvent(None, 0, 0, None)
  5. s=win32evtlog.EvtSubscribe('System', win32evtlog.EvtSubscribeStartAtOldestRecord, SignalEvent=h, Query=query_text)
  6. while 1:
  7. while 1:
  8. events=win32evtlog.EvtNext(s, 10)
  9. if len(events)==0:
  10. break
  11. ##for event in events:
  12. ## print(win32evtlog.EvtRender(event, win32evtlog.EvtRenderEventXml))
  13. print('retrieved %s events' %len(events))
  14. while 1:
  15. print ('waiting...')
  16. w=win32event.WaitForSingleObjectEx(h, 2000, True)
  17. if w==win32con.WAIT_OBJECT_0:
  18. break