Search code examples
c#.netsecurityregistryevent-log

Creating new event log source


My application calls a library (which I do not have control) that creates a new EventLog source and uses EventLog.SourceExists. It throws System.Security.SecurityException: The source was not found, but some or all event logs could not be searched. Inaccessible logs: Security.

The app needs read access to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security. How do I give Network Service permissions to registry (programmatically)?

Thanks for any pointers.


Solution

  • You are getting this error message because your "new Source" is not registered, and for that you need administration privileges. Try run your APP as "Administrator" in Console.

    I once hacked the "registry" as well, by adding in the "Source" myself, but that's probably ill-advised.