检测Windows中记录新事件的时间

时间:2011-09-29 17:26:28

标签: event-handling wmi event-log

如何在我的应用程序中检测到在Windows事件日志中记录新事件的时间。目前我正在运行计时器,只需5分钟来检查新事件,但如果我可以使用WMI或.net实时检测新事件会更好。

由于

1 个答案:

答案 0 :(得分:2)

您需要在应用中设置WMI Temporary Event Consumer。注意监视 事件日志您需要在WMI连接中请求SeSecurityPrivilege(因为您可以从安全日志中接收需要此权限的事件)

这些是一些示例WQL查询:

// See all events:
select * from __InstanceCreationEvent where TargetInstance ISA 'Win32_NTLogEvent'

// Catch only specific events: 4202 is a network transport failure
select * from __InstanceCreationEvent where TargetInstance ISA 'Win32_NTLogEvent'
     and TargetInstance.EventCode=4202

// Catch only events from a specific source: in this case WMI itself.
select * from __InstanceCreationEvent where TargetInstance ISA 'Win32_NTLogEvent'
     and TargetInstance.SourceName='WinMgmt'