在保护模式下从 IE 扩展内写入 Windows 事件日志 - 失败并拒绝访问

发布于 2024-09-13 13:18:00 字数 952 浏览 9 评论 0原文

在启用保护模式的 Windows 7 上的 Internet Explorer 中运行的 BHO 中,我尝试写入 Windows 事件日志。我正在写入一个已经存在的源,并且它位于应用程序日志中,所以我不明白为什么它会被阻止。但是,我对 System.Diagnostics.EventLog.WriteEntry("MySource", "Some message") 的调用失败,并出现 InvalidOperationException,并显示消息“无法打开源 'XXX' 的日志。您可能没有写访问权限。”。堆栈跟踪表明它位于 EventLog.OpenForWrite(String currentMachineName)

关闭保护模式使其可以正常工作。

有什么原因不允许在保护模式下这样做,以及我可以通过什么方式将我的 BHO 注册为允许写入事件日志,或者以其他方式使其工作?

根据 这篇文章 对 OpenForWrite 的调用() 导致调用 UnsafeNativeMethods.RegisterEventSource(this.machineName, this.sourceName);,但相关文档并没有让我进一步了解。

我正在使用 .net 2.0

谢谢。

交叉发布于此处: msdn_microsoft_ieextensiondevelopment

In a BHO running within Internet Explorer on Windows 7 with Protected Mode On, I'm trying to write to the windows event log. I'm writing to a source that already exists, and it's in the Application Log so I don't see why this would be blocked. However, my call to System.Diagnostics.EventLog.WriteEntry("MySource", "Some message") fails with an InvalidOperationException, with message "Cannot open log for source 'XXX'. You may not have write access.". The stack trace indicates it's at EventLog.OpenForWrite(String currentMachineName).

Turning Protected Mode Off makes it work fine.

Any reason this would not be allowed within Protected Mode, and any way I can register my BHO as being allowed to write to the event log, or otherwise make it work?

According to this post the call to OpenForWrite() results in a call to UnsafeNativeMethods.RegisterEventSource(this.machineName, this.sourceName);, but the docs for that didn't get me any further.

I'm using .net 2.0

thanks.

Cross-posted here: msdn_microsoft_ieextensiondevelopment

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰沐子 2024-09-20 13:18:00

如果您确实需要写入系统日志,我会:

  • 创建一个服务并向其发送消息 - 如果您要定期记录某些内容,我会这样做。但是谁将一堆消息写入系统日志呢?
  • 以静默方式启动一个小型应用程序,该应用程序作为代理进程被提升为中等信任度

让我们采用选项二。有几种方法可以做到这一点,但我会给你一个想法。将要记录的数据写入文件或注册表的低完整性位置。然后启动一个提升到中等信任度的小应用程序来获取数据并写入数据。这有效率吗?不会。但是,如果写入系统日志是非常罕见的事件,那么随着时间的推移,这将产生最少的开销。

该服务方法对于用户来说不太明显,但会从计算机资源中分走一小部分。

请参阅了解和从保护模式启动进程在保护模式 Internet Explorer 中工作

If you really need to write to the system log I would either:

  • Create a service and send messages to it - if you will be logging something with any regularity I would do this. But who writes a bunch of messages to the system log?
  • Launch a tiny application silently that is elevated to medium trust as a broker process

Let's go with option two. A few ways to do this but I will give you one idea. Write the data to be logged to a file or the registry in a low integrity location. Then launch a little application elevated to medium trust that picks up the data and writes it. Is this efficient? No. But if writing to the system log is a very rare event then this will yield the least overhead over time.

The service approach will be less obvious to the user but will take a little sliver of pie away from the computer's resources.

See Starting Processes from Protected Mode in Understanding and Working in Protected Mode Internet Explorer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文