【问题标题】:Creating new event log source创建新的事件日志源
【发布时间】:2012-07-16 19:46:39
【问题描述】:

我的应用程序调用一个库(我没有控制权),它创建一个新的 EventLog 源并使用 EventLog.SourceExists。它抛出System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.

该应用需要对HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security 的读取权限。如何向注册表授予网络服务权限(以编程方式)?

感谢任何指点。

【问题讨论】:

    标签: c# .net security registry event-log


    【解决方案1】:

    您收到此错误消息是因为您的“新源”未注册,因此您需要管理权限。尝试在控制台中以“管理员”身份运行您的 APP。

    我也曾经通过自己添加“源”来入侵“注册表”,但这可能是不明智的。

    【讨论】:

    • 我的应用程序不需要管理员权限,只是安全分支需要读取权限。
    • “设计”的安全分支只允许拥有管理员或域权限的人使用(只读)。以编程方式绕过这一点,您可能需要更改“注册表设置”。附知识库:support.microsoft.com/kb/323076
    【解决方案2】:

    我今天遇到了同样的问题,WinForms 或 ASPX 的答案似乎都不适合我的情况(非安装计划任务 exe)。所以我这样做了:-

        protected void prog_Load(object sender, EventArgs e)
        {
            boolean setupComplete = false;
            try // setting an Event log entry, just to see if we can
            {
                logEvent = "prog started";
                EventLog.WriteEntry(logSource, logEvent, EventLogEntryType.Information, 0);
                setupComplete = true;
            }
            catch (Exception eLog1) // we can't, so try to fix
            {
                try
                {
                    EventLog.CreateEventSource(logSource, logLog);
                    logEvent = "prog registered for Event Logging";
                    EventLog.WriteEntry(logSource, logEvent, EventLogEntryType.Information, 0);
                }
                catch (Exception eLog2) // aha!  we probably lack admin rights to set the registry key
                {
                    MessageBox.Show("prog needs admin rights the first time it runs", "prog Setup", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
    
            // run
            if (setupComplete == true)
            {
                DoTheWork();
            }
    
            // exit
            this.Close();
        }
    

    【讨论】:

      猜你喜欢
      • 2010-09-08
      • 2012-09-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-18
      相关资源
      最近更新 更多