If you log on to a computer as a regular user, and if you try to use Microsoft Visual
Studio .NET to create a custom event log to register events, you may receive the following error message:
An
unhandled exception of type 'System.Security.SecurityException' occurred in
mscorlib.dll Additional information: Requested registry access is not
allowed.
This problem occurs because the user account that you used to log on does not have sufficient permissions.
The first time that you call the EventLog.CreateEventSource() method to create a custom event log, the custom event log
entry is created under the following registry subkey:
To create this subkey entry, you must have
permission to write. However, the regular
user account does not have permission to write. Therefore, you receive the error message that is mentioned in the
"Symptoms" section.
Important This section, method, or task contains steps that tell you how to modify the registry. However, serious problems might occur if you modify the registry incorrectly. Therefore, make sure that you follow these steps carefully. For added protection, back up the registry before you modify it. Then, you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click the following article number to view the article in the Microsoft Knowledge Base:
322756 (http://support.microsoft.com/kb/322756/) How to back up and restore the registry in Windows
To
work around this problem, use one of the following methods:
Right-click Eventlog, and then click
Permissions. The Permissions for Eventlog
dialog box appears.
5.
Click Advanced. The Advanced
Security Settings for Eventlog dialog box appears.
6.
In the Name column, double-click
the Users group. The Permission Entry for Eventlog dialog box
appears.
7.
Select the Set Value check box,
select the Create Subkey check box, and then click
OK.
8.
Quit Registry Editor, and then log off from the administrator account.
9.
Log on to the computer as a regular user.
10.
Try to create a custom event log by using Visual Studio .NET, and then try to write to this event log by
using an application that is built on Visual Studio .NET.
Right-click My Computer, and then
click Manage. The Computer Management window
appears.
c.
Under System Tools, expand
Local Users and Groups.
d.
Right-click Users, and then click
New User. The New User dialog box
appears.
e.
Type the name of the new account in the User name box, and then type
a single password in both the
Password box and the Confirm password
box.
f.
Clear the User must change password at next
logon check box, select the Password never expires
check box, and then click Create.
g.
Click Close to close the New
User dialog box.
2.
Add the user to the Debugger User group:
a.
Under Local Users and Groups, click
Users.
b.
In the Name column in the right pane of the Computer
Management window, right-click
the name of the new account, and then click
Properties. The properties dialog box of the new account appears.
c.
Click the Member Of tab, and then
click Add. The Select Groups dialog box
appears.
d.
Click Advanced. The Select
Groups dialog box appears.
e.
Click Find Now. The available groups
appear in the Select Groups dialog box.
f.
In the Name (RDN) column, click
Debugger Users, and then click OK.
g.
In the Selected Groups dialog box, click
OK.
h.
In the properties dialog box of the new account, click
OK.
i.
Log off from the administrator account.
3.
Create a Windows application:
a.
Log on to the computer by using the regular user account
that you created in "Step 1 - Create a regular user account".
b.
Start Visual Studio .NET.
c.
On the File menu, point to
New, and then click Project. The New
Project dialog box appears.
d.
Under Project Types, click
Visual C# Projects.
e.
Under Templates, click Windows
Application.
f.
In the Name box, type
the name of a project, and then
click OK. By default, the Form1 form appears.
g.
Right-click the Form1 form, and then click View
Code. The Form1.cs file appears.
h.
Replace the existing code with the following
code:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Diagnostics;
namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Diagnostics.EventLog eventLog1;
private System.Windows.Forms.Button button1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
if(!EventLog.SourceExists("Source1"))
{
EventLog.CreateEventSource("Source1","MyLog1");
}
eventLog1.Source = "Source1";
eventLog1.Log = "MyLog1";
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.eventLog1 = new System.Diagnostics.EventLog();
this.button1 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).BeginInit();
this.SuspendLayout();
//
// eventLog1
//
this.eventLog1.SynchronizingObject = this;
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 104);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
((System.ComponentModel.ISupportInitialize)(this.eventLog1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
eventLog1.WriteEntry("The Button1 Is Clicked");
}
}
}
i.
On the File menu, click Save
Form1.cs to save the file.
4.
Run the project:
a.
On the Build menu, click Build
Solution.
b.
Run the project. You may receive the error message that
is mentioned in the "Symptoms" section.
Note The security for the permission to write to the event log registry subkey is
enforced at the Event Logging API level in the operating system. By default,
the custom event log permissions are same as the application event log
permissions.
For more information, click the following article number to view the article in the Microsoft Knowledge Base:
329291 (http://support.microsoft.com/kb/329291/)
"Requested registry access is not allowed" error message when ASP.NET application tries to write new EventSource in the EventLog
Need More Help? Contact a Support professional by Email, Online or Phone.
Customer Service For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
Newsgroups Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.