Question: Is it possible to export an event log in a process not "run as administrator"?
I'm following the example code at https://msdn.microsoft.com/en-us/library/bb671203(v=vs.90).aspx
using (var els = new EventLogSession())
{
els.ExportLogAndMessages("Security", PathType.LogName, "*", @"c:\temp\security.evtx");
}
This code runs successfully when I run the process using "run as administrator", but fails when not "run as administrator with the exception
System.UnauthorizedAccessException: "Attempted to perform an unauthorized operation."
Using similar code to access my application's event log
using (var els = new EventLogSession())
{
els.ExportLogAndMessages("MyAppLog", PathType.LogName, "*", @"c:\temp\myapplog.evtx");
}
I get similar results except the exception is different:
System.Diagnostics.Eventing.Reader.EventLogException: "The directory name is invalid"
Am I doing something wrong, or is there a different approach that will allow me to get an event log exported to an .evtx file without requiring admin privileges?
Notes:
- Under the hood, I believe this is calling (and failing) in the native method
EvtArchiveExportedLog
.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa385232(v=vs.85).aspx - As such the following seems related: EvtArchiveExportedLog fails with ERROR_DIRECTORY , but I don't understand what I would need to do in order to make my situation work correctly.