Windows:报告事件函数
据我了解, ReportEvent 函数需要 消息文本文件通过注册表关联以接收格式正确的消息。是否有任何常见的事件 ID 或任何简单的方法来报告没有关联消息文本文件的事件?
或者可能是,是否有我可以在我的应用程序中使用的特殊通用事件源?类似 RegisterEventSource(NULL, "Application") 的东西?
As far as I understood, the ReportEvent function requires Message Text Files associated through the registry to receive properly formatted messages. Is there any common Event Ids or any simple way to report an event with no Message Text Files associated?
Or may be, is there special common Event Source which I can use in my application? Something like RegisterEventSource(NULL, "Application")?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您不必在 HKLM 中注册您的消息。 (这是一件好事,因为如果您不是管理员,则无法注册消息)。
但这并不能阻止您将事件写入 Windows 应用程序事件日志。唯一的缺点是,从 Windows Vista 开始,您只会看到一些难看的文本。
现在您可以将事件记录到应用程序事件日志中:
窃取其他人的注册
不幸的是,从 Windows Vista 开始,Windows 会发出丑陋的抱怨,指出您没有事先注册该事件:
但您不必必须忍受它。仅仅因为您没有在 HKLM 中注册消息源文件,并不意味着其他人也没有这样做。
例如,请注意事件日志中来自 Outlook 源的消息:
Outlook
D:\win32app\Exchange\Outlook2003.pst
商店 D: \win32app\Exchange\Outlook2003.pst 已检测到目录检查点。
您可以在以下位置检查 Outlook 的注册信息:
如果您查看
MAPIR.dll 二进制文件的资源,您将看到它的消息表:
您可以看到 eventid 0x40000020 是与格式化字符串关联:
您可以劫持 Outlook 的注册:
并且您会将事件添加到事件日志中,而不会出现所有丑陋的警告:
You don't have to register your messages in HKLM. (Which is a good thing, because you can't register messages if you're not an administrator).
But that doesn't stop you from writing events to the Windows Application event log. The only downside is that starting with Windows Vista you'll just get some ugly text along with it.
And so now you can log events to the Application event log:
Steal someone else's registration
Unfortunately, starting with Windows Vista, Windows will give ugly complaints that you didn't register the event beforehand:
But you don't have to live with it. Just because you didn't register an message source file in HKLM, doesn't mean nobody else did.
Notice, for example, a message from the Outlook source in the Event log:
Outlook
0x40000020
D:\win32app\Exchange\Outlook2003.pst
The store D:\win32app\Exchange\Outlook2003.pst has detected a catalog checkpoint.
You can check registration information for Outlook in:
And see:
If you peek into the resources of MAPIR.dll binary, you'll see its Message Table:
You can see that eventid 0x40000020 is assocated with a formatting string:
You can hijack Outlook's registration:
and you'll get your event added to the event log without all the ugly warnings:
不,您只需遵循规则并定义消息文本文件,将它们构建到资源中,将它们链接到您的应用程序等。
MSDN 上提供的示例将引导您完成所需执行的所有操作。
No, you just have to follow the rules and define your message text files, build them into resources, link them to your app etc.
The example provided at MSDN leads you through everything you need to do.
试试这个,它之前对我有用..
http://www.codeproject.com/ KB/system/xeventlog.aspx
Try this out, it's worked for me before..
http://www.codeproject.com/KB/system/xeventlog.aspx