Main Page | Report this Page
.NET DotNet Forum Index  »  .NET Framework Forum  »  Write event into securit log...
Page 1 of 1    

Write event into securit log...

Author Message
Ondrej Sevecek...
Posted: Sun Oct 11, 2009 9:50 am
Guest
Hello,

I am trying to log an event to the Security event log on Windows 7. I am
running the following code (FX 2.0) in the context of SYSTEM which has both
required privileges and also the CustomSD enables SYSTEM to Full Control
(generic all - GA).

And I am still getting an exception telling me I do not have write access:
System.InvalidOperationException: Cannot open log for source 'MyLog'. You
may not have write access. ---> System.ComponentModel.Win32Exception: Access
is denied
--- End of inner exception stack trace ---
at System.Diagnostics.EventLog.OpenForWrite(String currentMachineName)
at System.Diagnostics.EventLog.InternalWriteEvent(UInt32 eventID, UInt16
category, EventLogEntryType type, String[] strings, Byte[] rawData, String
currentMachineName)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
at System.Diagnostics.EventLog.WriteEntry(String message,
EventLogEntryType type, Int32 eventID)
at FlushSecurityLog.FlushLog.Flush() in
C:\ONDRA\DEV\FlushSecurityLog\FlushLog.cs:line 86


The code in question:

// third party implementation using some native .DLLs
privSec = new Privilege("SeSecurityPrivilege");
privSec.Enable();

privAudit = new Privilege("SeAuditPrivilege");
privAudit.Enable();

// gets created and registered automatically, no problem here
EventLog log = new EventLog("Security", ".", "MyLog");


EventLogPermissionEntry[] entries = new EventLogPermissionEntry[] {
new
EventLogPermissionEntry(EventLogPermissionAccess.Write, ".")
};

EventLogPermission perm = new EventLogPermission(entries);
perm.Demand();

log.WriteEntry("test message", EventLogEntryType.SuccessAudit, 1);
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Wed Dec 02, 2009 8:59 am