Bit of an odd one this. The usual story, I have an c# app that needs to impersonate an admin user to read the security event log. If I run the code without impersonation and my account in the admin group, it works fine. If I remove my account from the local admin group and impersonate the local admin account or the domain admin account (which is a member of local admin) the impersonation works fine, ie: WindowsIdentity.GetCurrent().Name returns the correct ID. However, if I then try to access the event log via:
System.Diagnostics.EventLog EventLog1 = new System.Diagnostics.EventLog("Security");
if (EventLog1.Entries.Count > 0)
foreach (System.Diagnostics.EventLogEntry entry in EventLog1.Entries)
As soon as it gets to check the count, I get and access denied exception. Even if I impersonate myself, I still get the error.
The code used to impersonate is straight from the Microsoft help and does seem to work, but it is as if the impersonated user does not have permissions - which in reality it does.
After much trawling on the web, I am still puzzled
Thanks