C# 中的事件记录器是否需要管理员权限才能将日志写入 Windows 事件查看器?

发布于 2024-09-27 06:14:11 字数 573 浏览 8 评论 0原文

在我的 C# 应用程序中,我使用 EventLog 类来记录消息。它在我的机器上运行得很好,但在客户端机器上却不起作用。

客户端机器配置与我的机器不同。我的机器有 Vista 操作系统,而客户端有 Windows 2003 操作系统。

我在我的计算机上拥有管理员权限,而在客户端计算机上我的应用程序在非管理员用户权限下运行。

在客户端计算机上,我收到错误 Faulting application , version ,错误模块 kernel32.dll

当我注释掉 EventLog.WriteEntry() 方法调用并开始将日志写入简单的文本文件时,我的应用程序在客户端计算机上停止崩溃。

所以我只是想知道事件记录是否需要管理员权限还是什么?

环境详细信息:C#、.net 2.0 框架、Windows Vista、Windows 2003 服务器、Oracle

In my C# application I am using EventLog class to log messages. It works perfectly fine on my machine but doesnt really works on client machine.

Client machine configuration is different than my machine. My machine has Vista OS whereas client has Windows 2003 OS.

I have admin rights on my machine whereas on client machine my application runs under non-admin user previleges.

On client machine I get error as Faulting application , version ,faulting module kernel32.dll

My application stopped crashing on client machine when I commented out EventLog.WriteEntry() method calls and started to write logs into simple text file.

So I was just wondering whether event logging needs administrator privileges or what?

Enviornment details : C#, .net 2.0 framework, Windows Vista, Windows 2003 server, Oracle

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

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

发布评论

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

评论(2

为你拒绝所有暧昧 2024-10-04 06:14:11

System.Diagnostics.EventLog 类在 .NET Framework 3.5 @ MSDN 中:

如果您写入事件日志,则必须
指定或创建事件源。你
必须拥有管理权限
计算机创建新的事件源。

...

如果与 EventLog 实例关联的事件日志的事件源不存在,则会创建新的事件源。要在 Windows Vista 及更高版本或 Windows Server 2003 中创建事件源,您必须具有管理凭据。

此要求是因为必须搜索所有事件日志(包括安全日志)以确定事件源是否唯一。从 Windows Vista 开始,用户无权访问安全日志;因此,会抛出 SecurityException。

System.Diagnostics.EventLog class in .NET Framework 3.5 @ MSDN:

If you write to an event log, you must
specify or create an event Source. You
must have administrative rights on the
computer to create a new event source.

...

If the event source for the event log associated with the EventLog instance doesn't exist, a new event source is created. To create an event source in Windows Vista and later or Windows Server 2003, you must have administrative credentials.

This requirement is because all event logs, including Security logs, must be searched to determine whether the event source is unique. Starting with Windows Vista, users do not have permission to access the Security log; therefore, a SecurityException is thrown.

孤城病女 2024-10-04 06:14:11

一种解决方案是在应用程序安装程序中创建所需的事件源,该安装程序以管理员权限运行。
请参阅 http://support.microsoft.com/default.aspx? scid=kb;EN-US;329291

One solution is to create the required Event Source in your application installer, which runs with admin rights.
See http://support.microsoft.com/default.aspx?scid=kb;EN-US;329291

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