问题描述
我有一个应用程序,可以在2016 Windows Server v1607的事件日志中创建新的事件源。目前尚不清楚源将使用哪个名称。要对此进行存档,该帐户需要对所有事件源具有读取权限,以确保源名称尚不存在(为什么另一个日志中不允许使用双源名称是另一个有趣的问题)。默认情况下,本地帐户被阻止读取安全事件日志,因此,创建新源最终会导致错误,即对该安全日志没有读取权限。
最有前途的方法似乎是该问题的答案:https://stackoverflow.com/a/3138269/2091030
我遵循步骤1-5,通过添加本地帐户的读取权限来更改HKEY_LOCAL_MACHINE \ SYstem \ CurrentControlSet \ Services \ Eventlog \ Security的注册表权限。我检查了“安全性”文件夹中的所有子密钥,它们都显示了对该帐户的正确读取访问权限。但是,当使用简单的C#程序添加带有新源的事件时,我现在又遇到另一个错误:
using System;
using System.Diagnostics;
namespace EventlogTest {
public class Test {
public static void Main() {
var log = new EventLog("SomeLog",".","SomeNewSource");
log.WriteEntry("Test 123",EventLogEntryType.@R_922_4045@ion);
}
}
}
System.Security.SecurityException: Der angeforderte Registrierungszugriff ist unzulässig.
bei System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
bei Microsoft.Win32.RegistryKey.OpenSubKey(String name,Boolean writable)
bei System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData)
bei System.Diagnostics.EventLogInternal.VerifyAndCreateSource(String sourceName,String currentMachineName)
bei System.Diagnostics.EventLogInternal.WriteEntry(String message,EventLogEntryType type,Int32 eventID,Int16 category,Byte[] rawData)
bei System.Diagnostics.EventLog.WriteEntry(String message,EventLogEntryType type)
bei EventlogTest.Test.Main()
我错过了什么吗?
解决方法
本地帐户的以下设置允许我在事件日志“ MyLog”中添加新来源:
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Eventlog:
- 添加具有以下权限的本地帐户:查询值,设置值,创建子项,枚举子项
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Eventlog \ Security:
- 此文件夹不继承其父文件夹的权限。添加具有普通读取访问权限的本地帐户。
HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services \ Eventlog \ MyLog:
- 停用继承并复制值,然后添加具有完全访问权限的本地帐户