我的应用程序调用了一个库(我无法控制),它创建了一个新的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
的读取权限。如何向注册表(以编程方式)提供网络服务权限?
感谢您的任何指示。
答案 0 :(得分:0)
您收到此错误消息是因为您的“新来源”未注册,为此您需要管理权限。尝试在控制台中以“管理员”身份运行您的APP。
我曾经通过自己添加“来源”来攻击“注册表”,但这可能是不明智的。
答案 1 :(得分: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();
}