473,837 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows Service - Event Log

I am building an windows service that is to be deployed on a windows
server 2003 and I want to have activity written to the event log, I
want its own log called ('CustomLog')

Below is what I have so far...its builds fine but when I go to start
the service i get the following error.

---------------------------
Services
---------------------------
The CWindowService service on Local Computer started and then stopped.
Some services stop automatically if they have no work to do, for
example, the Performance Logs and Alerts service.
---------------------------
OK
---------------------------
What am I doing wrong? Right after this code I have this line....and it
never had an issue.
EventLog.WriteE ntry("Refresh started successfully.") ;

//1. Create the source, if it does not already exist.
if (!EventLog.Sour ceExists("Custo mLog"))
{
EventLog.Create EventSource("Cu stomLog", "MyNewLog") ;
}
//2. Create an EventLog instance and assign its source.
EventLog myLog = new EventLog();
myLog.Source = "CustomLog" ;
//3. Write an informational entry to the event log.
myLog.WriteEntr y("Writing to event log.");

Jun 27 '06 #1
27 4729
Without seeing more of the start code i couldn't say for sure,
however, when I was working with this recently I found that by having
evaluating code in my OnStart event I had a tendancy of recieving the
same error. What I would recommend you do is add a component timer to
the service(not a form timer) and put your code in the Elapsed event of
the timer. Then in your OnStart method you just activate the timer.

-Bill

Jun 27 '06 #2
Hi,

You need to post more code, or more details at least.

Where are you running this?
What your onStart looks like?

Are you creating a new thread in the onStart ?

Usually what I do is in the onStart just create and Start a thread that is
the one who does the real thing. in this way the onStart returns
inmediately.
--
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

<pi*****@hotmai l.com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.com.. .
I am building an windows service that is to be deployed on a windows
server 2003 and I want to have activity written to the event log, I
want its own log called ('CustomLog')

Below is what I have so far...its builds fine but when I go to start
the service i get the following error.

---------------------------
Services
---------------------------
The CWindowService service on Local Computer started and then stopped.
Some services stop automatically if they have no work to do, for
example, the Performance Logs and Alerts service.
---------------------------
OK
---------------------------
What am I doing wrong? Right after this code I have this line....and it
never had an issue.
EventLog.WriteE ntry("Refresh started successfully.") ;

//1. Create the source, if it does not already exist.
if (!EventLog.Sour ceExists("Custo mLog"))
{
EventLog.Create EventSource("Cu stomLog", "MyNewLog") ;
}
//2. Create an EventLog instance and assign its source.
EventLog myLog = new EventLog();
myLog.Source = "CustomLog" ;
//3. Write an informational entry to the event log.
myLog.WriteEntr y("Writing to event log.");

Jun 27 '06 #3
What credentials is the Service running under? It is possible that the
Service's account does not have the necessary permission to write to the
Event Log.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
<pi*****@hotmai l.com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.com.. .
I am building an windows service that is to be deployed on a windows
server 2003 and I want to have activity written to the event log, I
want its own log called ('CustomLog')

Below is what I have so far...its builds fine but when I go to start
the service i get the following error.

---------------------------
Services
---------------------------
The CWindowService service on Local Computer started and then stopped.
Some services stop automatically if they have no work to do, for
example, the Performance Logs and Alerts service.
---------------------------
OK
---------------------------
What am I doing wrong? Right after this code I have this line....and it
never had an issue.
EventLog.WriteE ntry("Refresh started successfully.") ;

//1. Create the source, if it does not already exist.
if (!EventLog.Sour ceExists("Custo mLog"))
{
EventLog.Create EventSource("Cu stomLog", "MyNewLog") ;
}
//2. Create an EventLog instance and assign its source.
EventLog myLog = new EventLog();
myLog.Source = "CustomLog" ;
//3. Write an informational entry to the event log.
myLog.WriteEntr y("Writing to event log.");

Jun 27 '06 #4
On 2006-06-27, pi*****@hotmail .com <pi*****@hotmai l.com> wrote:
I am building an windows service that is to be deployed on a windows
server 2003 and I want to have activity written to the event log, I
want its own log called ('CustomLog')

Below is what I have so far...its builds fine but when I go to start
the service i get the following error.


When i tried that (on a default windows 2003 installation) i experienced
a problem with access rights. If i remember well, i had to give the
'network' user access rights to the registry keys..

--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be >
Jun 28 '06 #5
Check your service account, only admin accounts have the right to "create"
private logs. If your service run with restricted privileges (which is
good), you'll need to create the log from another program, not from within
your service.

Willy.
<pi*****@hotmai l.com> wrote in message
news:11******** **************@ u72g2000cwu.goo glegroups.com.. .
|I am building an windows service that is to be deployed on a windows
| server 2003 and I want to have activity written to the event log, I
| want its own log called ('CustomLog')
|
| Below is what I have so far...its builds fine but when I go to start
| the service i get the following error.
|
| ---------------------------
| Services
| ---------------------------
| The CWindowService service on Local Computer started and then stopped.
| Some services stop automatically if they have no work to do, for
| example, the Performance Logs and Alerts service.
| ---------------------------
| OK
| ---------------------------
|
|
| What am I doing wrong? Right after this code I have this line....and it
| never had an issue.
| EventLog.WriteE ntry("Refresh started successfully.") ;
|
| //1. Create the source, if it does not already exist.
| if (!EventLog.Sour ceExists("Custo mLog"))
| {
| EventLog.Create EventSource("Cu stomLog", "MyNewLog") ;
| }
|
|
| //2. Create an EventLog instance and assign its source.
| EventLog myLog = new EventLog();
| myLog.Source = "CustomLog" ;
|
|
| //3. Write an informational entry to the event log.
| myLog.WriteEntr y("Writing to event log.");
|
Jun 28 '06 #6

"Tim Van Wassenhove" <ti***@users.so urceforge.net> wrote in message
news:e8******** ******@TK2MSFTN GP03.phx.gbl...
| On 2006-06-27, pi*****@hotmail .com <pi*****@hotmai l.com> wrote:
| > I am building an windows service that is to be deployed on a windows
| > server 2003 and I want to have activity written to the event log, I
| > want its own log called ('CustomLog')
| >
| > Below is what I have so far...its builds fine but when I go to start
| > the service i get the following error.
|
| When i tried that (on a default windows 2003 installation) i experienced
| a problem with access rights. If i remember well, i had to give the
| 'network' user access rights to the registry keys..
|

What registry key's?
The "Network Service" account is a restricted service account with
sufficient privileges to write/read to/from the eventlog, if you elevate
it's privileges, you break what it was designed for.

Willy.
Jun 28 '06 #7
On 2006-06-28, Willy Denoyette [MVP] <wi************ *@telenet.be> wrote:

"Tim Van Wassenhove" <ti***@users.so urceforge.net> wrote in message
news:e8******** ******@TK2MSFTN GP03.phx.gbl...
| On 2006-06-27, pi*****@hotmail .com <pi*****@hotmai l.com> wrote:
| > I am building an windows service that is to be deployed on a windows
| > server 2003 and I want to have activity written to the event log, I
| > want its own log called ('CustomLog')
| >
| > Below is what I have so far...its builds fine but when I go to start
| > the service i get the following error.
|
| When i tried that (on a default windows 2003 installation) i experienced
| a problem with access rights. If i remember well, i had to give the
| 'network' user access rights to the registry keys..
|

What registry key's?


HKLM/System/CurrentControlS et/Services/Eventlog (or one of it's
children).
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be >
Jun 28 '06 #8
Yes, but why do you want your service to write to this key?
Only Administrators (and localsystem) are allowed to write to HKLM and
descendants, Service accounts are not supposed to write to HKLM. If you
really need your service to write to HKLM, you need to run as "localsyste m".
Again if you grant a non privileged account write access to HKLM, you
severely compromise your system's security.

Willy.

"Tim Van Wassenhove" <ti***@users.so urceforge.net> wrote in message
news:uu******** ******@TK2MSFTN GP03.phx.gbl...
| On 2006-06-28, Willy Denoyette [MVP] <wi************ *@telenet.be> wrote:
| >
| > "Tim Van Wassenhove" <ti***@users.so urceforge.net> wrote in message
| > news:e8******** ******@TK2MSFTN GP03.phx.gbl...
| >| On 2006-06-27, pi*****@hotmail .com <pi*****@hotmai l.com> wrote:
| >| > I am building an windows service that is to be deployed on a windows
| >| > server 2003 and I want to have activity written to the event log, I
| >| > want its own log called ('CustomLog')
| >| >
| >| > Below is what I have so far...its builds fine but when I go to start
| >| > the service i get the following error.
| >|
| >| When i tried that (on a default windows 2003 installation) i
experienced
| >| a problem with access rights. If i remember well, i had to give the
| >| 'network' user access rights to the registry keys..
| >|
| >
| > What registry key's?
|
| HKLM/System/CurrentControlS et/Services/Eventlog (or one of it's
| children).
|
|
| --
| Met vriendelijke groeten,
| Tim Van Wassenhove <http://timvw.madoka.be >
Jun 28 '06 #9
Every Windows Service runs under a specific user account, which is assigned
to it, either by the developer when creating the installation for the
service, or by an administrator/authorized user via the Services snap-in.
So, there is no single user account under which all Windows Services run.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Salad Alchemist

Big thicks are made up of lots of little thins.
"Willy Denoyette [MVP]" <wi************ *@telenet.be> wrote in message
news:uk******** ******@TK2MSFTN GP02.phx.gbl...

"Tim Van Wassenhove" <ti***@users.so urceforge.net> wrote in message
news:e8******** ******@TK2MSFTN GP03.phx.gbl...
| On 2006-06-27, pi*****@hotmail .com <pi*****@hotmai l.com> wrote:
| > I am building an windows service that is to be deployed on a windows
| > server 2003 and I want to have activity written to the event log, I
| > want its own log called ('CustomLog')
| >
| > Below is what I have so far...its builds fine but when I go to start
| > the service i get the following error.
|
| When i tried that (on a default windows 2003 installation) i experienced
| a problem with access rights. If i remember well, i had to give the
| 'network' user access rights to the registry keys..
|

What registry key's?
The "Network Service" account is a restricted service account with
sufficient privileges to write/read to/from the eventlog, if you elevate
it's privileges, you break what it was designed for.

Willy.

Jun 28 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3693
by: sidd | last post by:
Hi All, i have some doubts on .net windows services.. please see if some one could help me understand this.. 1)is it possible to install a windows service which does not have a installer added to it, using installutil.exe OR is it must to have an installer to the service project to be able to
8
4196
by: Bill Sonia | last post by:
I've written a Windows Service to send e-mails on events like OnStart, OnStop, OnShutDown using System.Web.Mail. It works for everything but OnShutdown. My guess is that for OnShutDown, once my send mail code is executed, other necessary Windows Services have been terminated before it can actually send the mail. I've updated my HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services registry DependOnService value including SMPTSVC and...
4
15901
by: Keith | last post by:
I'm in the same boat as the fellow who posted this message back in August: Title : Windows Service, How does one make a service "fail" properly? Author : Ross Bennett Group : microsoft.public.dotnet.languages.csharp URL :...
2
21920
by: Mark | last post by:
I created an extremely simple windows service that only writes to the EventLogs on Stop and Pause. I installed it using the InstallUtil.exe program, the output of which is below. It appears to be successful. I'm now ready to start my service (I think) but the NET START command does not appear to indicate that the service is available to be run. The output for NET START is below as well. The Services list in the W2K administrator...
2
7991
by: Fan Wang | last post by:
Hi All, I wrote a windows service with C# as below. But I can't install it with installutil.exe. I got an error message " Exception occurred while initializing the installation: System.IO.FileNotFoundException: File or assembly name windowsservice1, or one of its dependencies, was not found.. " I am new to C# environment. Any idea any clue will be appreciated. Thanks using System;
2
6545
by: Chris Dunaway | last post by:
I am attempting to use the AppDomain.UnhandledException event in a Windows Forms app and also in a Windows Service. But the event doesn't seem to be called. In a Windows Forms app, the event IS called but only if I run the app through the IDE. If run standalone (release or debug build, it doesn't matter), the event handler is never called. In the Windows Forms app, I changed it to use the Application.ThreadException event and that...
0
1135
by: Jason | last post by:
Ok, for the life of me, I just don't understand what's going on. I want to use remoting to send messages from a windows service to a windows form app, but I just can't get it to work. So, here's what I have so far. I created a small, remotable object that inherits from MarshalByRefObject. It has a public subroutine that raises an event with a message attached: Public Delegate Sub TestServiceEventHandler(ByVal Message As String) ...
3
2599
by: Mika M | last post by:
I'm programming quite simple Windows Service using C# 2005. I also made setup for it into same solution. When I run setup to install service, it's going fine into C:\Program Files\MyCompany\My Service, and Event Log tells... Event Type: Information Event Source: MsiInstaller Event Category: None Event ID: 11707
5
3315
by: dm3281 | last post by:
I'm really starting to hate writing services -- or trying to, anyway. Why do I need to rename my project to the service name? Why do I need to set the "ServiceName" property to my service name? Why do I need to set a property within my code to the service name? Are all these required or am I just doing this for consistency purposes?
0
9683
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10883
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10631
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10276
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7813
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7006
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5670
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4049
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3126
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.