September 30, 2010

Requested registry access is not allowed

I was trying to write some information from an application to the event viewer, but it gave a security exception.

 
System.Security.SecurityException: Requested registry access is not allowed.
   at System.ThrowHelper.ThrowSecurityException(ExceptionResource resource)
   at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
   at System.Diagnostics.EventLog.CreateEventSource(EventSourceCreationData sourceData)
   at System.Diagnostics.EventLog.VerifyAndCreateSource(String sourceName, String currentMachineName)
   at System.Diagnostics.EventLog.WriteEntry(String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
   at System.Diagnostics.EventLog.WriteEntry(String source, String message, EventLogEntryType type, Int32 eventID, Int16 category, Byte[] rawData)
   at System.Diagnostics.EventLog.WriteEntry(String source, String message)
   at EC.SPNPortal.ToDoList.ToDoList.uxSend_Click(Object sender, EventArgs e)
   at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

 
After playing around, found the solution for this problem.

 
This mainly happens when the logged in user does not have write access to the event log. So for that, please perform below things in 32 bit machine

  • Open the registry entry using regedit command
  • Find the below place, HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Eventlog
  • Right click on that and give full access to everyone.
In a 64 bit machine,
  • Open the registry entry using regedit command
  • Find the below place, HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Security
  • Right click on that and give full access to everyone.

1 comment:

  1. Thanks a lot! I am able to start my windows service

    ReplyDelete