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
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:
Right-click My Computer, and then
click Manage. The Computer Management window
Under System Tools, expand
Local Users and Groups.
Right-click Users, and then click
New User. The New User dialog box
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
Clear the User must change password at next
logon check box, select the Password never expires
check box, and then click Create.
Click Close to close the New
User dialog box.
Add the user to the Debugger User group:
Under Local Users and Groups, click
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.
Click the Member Of tab, and then
click Add. The Select Groups dialog box
Click Advanced. The Select
Groups dialog box appears.
Click Find Now. The available groups
appear in the Select Groups dialog box.
In the Name (RDN) column, click
Debugger Users, and then click OK.
In the Selected Groups dialog box, click
In the properties dialog box of the new account, click
Log off from the administrator account.
Create a Windows application:
Log on to the computer by using the regular user account
that you created in "Step 1 - Create a regular user account".
Start Visual Studio .NET.
On the File menu, point to
New, and then click Project. The New
Project dialog box appears.
Under Project Types, click
Visual C# Projects.
Under Templates, click Windows
In the Name box, type
the name of a project, and then
click OK. By default, the Form1 form appears.
Right-click the Form1 form, and then click View
Code. The Form1.cs file appears.
Replace the existing code with the following
/// Summary description for Form1.
public class Form1 : System.Windows.Forms.Form
private System.Diagnostics.EventLog eventLog1;
private System.Windows.Forms.Button button1;
/// Required designer variable.
private System.ComponentModel.Container components = null;
// Required for Windows Form Designer support
eventLog1.Source = "Source1";
eventLog1.Log = "MyLog1";
// TODO: Add any constructor code after InitializeComponent call
/// Clean up any resources being used.
protected override void Dispose( bool disposing )
if( disposing )
if (components != null)
base.Dispose( disposing );
#region Windows Form Designer generated code
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
private void InitializeComponent()
this.eventLog1 = new System.Diagnostics.EventLog();
this.button1 = new System.Windows.Forms.Button();
this.eventLog1.SynchronizingObject = this;
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);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Name = "Form1";
this.Text = "Form1";
/// The main entry point for the application.
static void Main()
private void button1_Click(object sender, System.EventArgs e)
eventLog1.WriteEntry("The Button1 Is Clicked");
On the File menu, click Save
Form1.cs to save the file.
Run the project:
On the Build menu, click Build
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