在保护模式下从 IE 扩展内写入 Windows 事件日志 - 失败并拒绝访问
在启用保护模式的 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
谢谢。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您确实需要写入系统日志,我会:
让我们采用选项二。有几种方法可以做到这一点,但我会给你一个想法。将要记录的数据写入文件或注册表的低完整性位置。然后启动一个提升到中等信任度的小应用程序来获取数据并写入数据。这有效率吗?不会。但是,如果写入系统日志是非常罕见的事件,那么随着时间的推移,这将产生最少的开销。
该服务方法对于用户来说不太明显,但会从计算机资源中分走一小部分。
请参阅了解和从保护模式启动进程在保护模式 Internet Explorer 中工作。
If you really need to write to the system log I would either:
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.