python甚至可以监听windows日志

2024-09-27 07:32:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我阅读了示例,关于使用pywin32读取windows事件日志:

Python's win32 access for the Eventlog

现在我想知道我是否可以采取下一步:
一旦windows事件日志到达(可能是其他应用程序设置的日志),启动一个python函数(我的代码),这样我就可以实时监视事件。在

我找了一整天,找不到一个好的解决办法。 我的测试是:

import win32evtlog
import win32event

def function_wait():
    #i check the new windows log is set , but this function wasn't fired
    print 'a new event log.' 

file_open_hand = win32evtlog.OpenEventLog('my-pc','Application')
# i thought it's definitly wrong below, but i have no idear about the 4th parameter!
hEvent = win32event.CreateEvent (None, 1, 0, 'function_wait') 

win32evtlog.NotifyChangeEventLog(file_open_hand,hEvent)

inputx = raw_input("wait for event log fire...")

Tags: theimporteventlognewforwindows事件

热门问题