0

我的应用程序调用了一个库(我无法控制它),它创建一个新的 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. 如何向注册表授予网络服务权限(以编程方式)?

感谢您的任何指示。

4

2 回答 2

0

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

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

于 2012-07-16T19:56:49.140 回答
0

我今天遇到了同样的问题,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();
    }
于 2013-03-19T15:28:27.360 回答