471,306 Members | 1,203 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,306 software developers and data experts.

Service that writes to the application Event Log

Hello. I am writing a service that I would like to have write access to
the Application event log. Since the service is running as a system
account, it would appear that I do not have access. (Security Error).

I am following the MSDN howto and it does not appear to have any
additional requirements in their howto.

If I run this as an application under my credentials (local admin) it
runs just fine.

I have a feeling this is realted to XP SP2 or Perhaps .Net 1.1

Advice?
Thanks in advance!
-Aaron
Dec 20 '05 #1
4 2138
Hi,
"Aaron Hackney" <ah****************@grics.net> wrote in message
news:do*********@enews2.newsguy.com...
Hello. I am writing a service that I would like to have write access to
the Application event log. Since the service is running as a system
account, it would appear that I do not have access. (Security Error).
I do not think so, IIRC everybody can write in the log

Post your code just to be sure it's correct.
I have a feeling this is realted to XP SP2 or Perhaps .Net 1.1


Not at all, the problem should be in something else you are trying to do,
post your code !

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Dec 20 '05 #2
You should only need admin rights to create a new log or log source. If
you are writing to an existing log with an existing log source, it
should work. If you need to create a new log or source, it is best to do
it during deployment by making an Installer class (which you can execute
using InstallUtil.exe). Do not require your application to run as an
admin just to create the event log/source.
Dec 21 '05 #3
Ignacio Machin ( .NET/ C# MVP ) wrote:
Hi,
"Aaron Hackney" <ah****************@grics.net> wrote in message
news:do*********@enews2.newsguy.com...
Hello. I am writing a service that I would like to have write access to
the Application event log. Since the service is running as a system
account, it would appear that I do not have access. (Security Error).

I do not think so, IIRC everybody can write in the log

Post your code just to be sure it's correct.
I have a feeling this is realted to XP SP2 or Perhaps .Net 1.1

Not at all, the problem should be in something else you are trying to do,
post your code !

I've muched with the code a bit but I was following directions from MSDN
here:
http://msdn.microsoft.com/library/de...pplication.asp

Thanks much
-Aaron

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;

namespace MyNewService
{
public class MyNewService : System.ServiceProcess.ServiceBase
{
private System.Diagnostics.EventLog eventLog1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public MyNewService()
{
// This call is required by the Windows.Forms Component Designer.
InitializeComponent();
}

// The main entry point for the process
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;

// More than one user Service may run within the same process. To add
// another service to this process, change the following line to
// create a second service object. For example,
//
// ServicesToRun = new System.ServiceProcess.ServiceBase[] {new
Service1(), new MySecondUserService()};
//
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new
MyNewService() };

System.ServiceProcess.ServiceBase.Run(ServicesToRu n);
}

/// <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();
((System.ComponentModel.ISupportInitialize)(this.e ventLog1)).BeginInit();
//
// eventLog1
//
this.eventLog1.Log = "System";
this.eventLog1.MachineName = "skinner";
((System.ComponentModel.ISupportInitialize)(this.e ventLog1)).EndInit();

}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

/// <summary>
/// Set things in motion so your service can do its work.
/// </summary>
protected override void OnStart(string[] args)
{
eventLog1.WriteEntry("In OnStart");
}

/// <summary>
/// Stop this service.
/// </summary>
protected override void OnStop()
{
eventLog1.WriteEntry("In onStop.");
}

protected override void OnContinue()
{
eventLog1.WriteEntry("In OnContinue.");
}
}
}
Dec 21 '05 #4
I found my problem/answer. By default loggin is turned on and allow
without registering or creating a source.

I just needed to use the static methods provided such as
EventLog.WriteEntry instead of creating an instance of
System.Diagnostics.EventLog()

*DOH*

Dec 30 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Fabio Papa | last post: by
3 posts views Thread by Craig Thompson | last post: by
2 posts views Thread by Mark | last post: by
5 posts views Thread by John | last post: by
3 posts views Thread by bclegg | last post: by
27 posts views Thread by pisquem | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.