Cannot open log for source . You may not have write access

If you get the error some thing like (while writing to the event log):

Cannot open log for source {0}. You may not have write access

As quick solution is to increase or raise the user permissions temporarily to write the event log and then revert back the elevated permissions.

Below is the code:

System.Security.Principal.WindowsImpersonationContext wic = System.Security.Principal.WindowsIdentity.Impersonate(IntPtr.Zero);
--your Code to write to event log or any to do something which needs elevated permission--
wic.Undo();

About these ads

6 Responses

  1. nã piquei nádâ

  2. thank you very much

  3. Awesome, the only trick that worked, thanks!

  4. svarukala, u rock!

  5. Thank you very much, it has worked for me!

  6. It haven’t worked for me. I m using ur code in Console Application target framework is 4.5 . Im running application has domain user

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: