Windows Service AutoStart Problem (C#)

G

Guest

Hi,
I have a problem on some machines to AutoStart a very simple windows service.
It just logs a line in the event log when the OnStart and OnStop occurs.
The service is setup as "Automatic" / Localsystem Accoutn.

The machines where the service does not autmatic start are member of a
domain (and have restricted policies).

When I start or stop the service via SCM it works perfectly..
BUT it does NOT start after a reboot !!
(When it does not start after a reboot, I can still start it manualy via the
SCM without a problem)

I tried to "automatic" start it with my own (administrator) account also,
but it gives the same errors in the eventlog !.

Does anyone have an idea ?
I am searching for almost four days now to solve it.

Plz help me !.


I get the following errors in the event log:
-------------------------------------------------

Event Type: Error
Event Source: Service Control Manager
Event Category: None
Event ID: 7000
Date: 4/5/2005
Time: 6:16:31 PM
User: N/A
Computer: N956076C
Description:
The MyNewService service failed to start due to the following error:
The service did not respond to the start or control request in a timely
fashion.


Event Type: Error
Event Source: Service Control Manager
Event Category: None
Event ID: 7009
Date: 4/5/2005
Time: 6:16:31 PM
User: N/A
Computer: N956076C
Description:
Timeout (30000 milliseconds) waiting for the MyNewService service to connect.

Thanks in advance for the replies on this subject.
 
C

Claudio Grazioli

On Mon, 11 Apr 2005 23:58:01 -0700, VinSand wrote:

Hi
I have a problem on some machines to AutoStart a very simple windows service.
It just logs a line in the event log when the OnStart and OnStop occurs.
The service is setup as "Automatic" / Localsystem Accoutn.

The machines where the service does not autmatic start are member of a
domain (and have restricted policies).

When I start or stop the service via SCM it works perfectly..
BUT it does NOT start after a reboot !!
(When it does not start after a reboot, I can still start it manualy via the
SCM without a problem)

I tried to "automatic" start it with my own (administrator) account also,
but it gives the same errors in the eventlog !.

Does anyone have an idea ?
I am searching for almost four days now to solve it.

Plz help me !.

I get the following errors in the event log:
-------------------------------------------------

Event Type: Error
Event Source: Service Control Manager
Event Category: None
Event ID: 7000
Date: 4/5/2005
Time: 6:16:31 PM
User: N/A
Computer: N956076C
Description:
The MyNewService service failed to start due to the following error:
The service did not respond to the start or control request in a timely
fashion.

Event Type: Error
Event Source: Service Control Manager
Event Category: None
Event ID: 7009
Date: 4/5/2005
Time: 6:16:31 PM
User: N/A
Computer: N956076C
Description:
Timeout (30000 milliseconds) waiting for the MyNewService service to connect.

Thanks in advance for the replies on this subject.

I think the problem may be that you try to write to the EventLog but the
EventLog service it self is not started yet.

You have to make sure, your service is not started before the EventLog
service started successfully. Thus you have to make your service dependent
on the EventLog service. See this article on MSDN on how to do that:
http://support.microsoft.com/default.aspx?scid=kb;en-us;193888&Product=win2000

hth
 
J

Jeffrey Tan[MSFT]

Hi VinSand,

Thanks for your post!!

Based on my understanding, you implemented an autostart windows service
application in .Net, which works well, but it sometimes can not auto start
on certain machines.

Based on my experience, the problem is probably due to that the Application
event log is full and it does not allow overwriting old entries. Under such
circumstances, the call to the EventLog.WriteEntry in our code cannot
succeed and the service fails to start eventually.

Therefore, I would like to suggest you try clearing the event log and
changing its settings first. Please follow the steps below to do these:
1. Open the Control Panel->Administrative Tools window;
2. Double click the Event Viewer icon;
3. In the log files tree shown in the left pane of the Event Viewer window,
we will see three or more log files;
4. Right click on the Application Log node, and choose the Clear all Events
command from the popup menu;
5. A message box will pop up prompting us to save the old entries of the
log, click No; the Application Log will be cleared;
6. Right click the Application Log node again, and choose the Properties
command from the popup menu; the Application Properties dialog box will
show up;
7. In the General tab of the dialog box, ensure the "Overwrite events as
needed" radio button is selected; this radio button is located in the Log
size group box shown in the lower part of the dialog box;
8. Click OK to apply the changes.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Guest

Claudio,
first of all thanks for your response.

I do not think that services have to depend on the Eventlog service (since
this is a system service and will probobly start before any of the user
services).

If I check the EventLog service itself, none of the (almost 80) services
depend on this service while many services do make eventlog entries.

If anyone knows more about this subject, then please let us know.

-Vincent.
 
G

Guest

Jeffrey,
thanks for your exelent answer.

I used a custom log in the eventlog (not the applicaiton log) and the
default setting was: "cleared after 7 day". I cleared this eventlog and
changed this setting to "Overwrite events as needed".

In my service I changed the Autolog property to "true" (so that start/stop
events are logged into the application log).
Besides that I only started a timer in the start event, and when timer was
expired I initialized and used my custom eventlog.

This all solved my problem.

Thanks for pointing me into the direction of the eventlog itself.
Cheers...

Vincent.
 
C

Claudio Grazioli

Besides that I only started a timer in the start event, and when timer was
expired I initialized and used my custom eventlog.

Why exactly do you start a timer? To wait a certain amount of time before
accessing the EventLog? Because it does not work without waiting some time
first?

If that is the case, well, what you are doing is quite problematic. How do
you know that the time your timer waits is long enough on different
machines? Depending on what is installed on your machine quite different
times may be required to wait.

Thus: If what I have written above is correct, I come back with my advice
to make your service dependent on the EventLog service and throw your timer
away. Because then you can be sure that your service works in all
situations.

But maybe I missunderstood you.
 
G

Guest

Claudio:
Why exactly do you start a timer? To wait a certain amount of time before
accessing the EventLog? Because it does not work without waiting some time
first?
I started a timer because I suspected that creating and using the custom
eventlog took to much time (after an automatic start).
The registration of "Start" and "Stop" will still be done in the application
eventlog.
(Since I changed "AutoLog" to "true" in the service property)
So, using the eventlog itself (in the OnStart method) is not the problem in
my oppinion.

The creation (new System.Diagnostics.EventLog()) and usage of the custom
eventlog just took (after automatic startup) sometimes to much time in my
oppinion.
(To be sure of this I will give it a try to measure the time (of this
eventlog creation and fist time usage) it takes after startup.)

The first timer-elapsed event is used for custom eventlog creation and other
initialization for my service. (The "other" initialization was already done
overhere).
The timer callback is blocked as long as this takes.

The other timer-elapsed events does my regular service tasks.
So I need the timer anyway for my service tasks (it is not a waisted
resource).

Regards,
Vincent.
 
J

Jeffrey Tan[MSFT]

Cool!! I am glad my reply can help you. If you need further help, please
feel free to tell me. I will work with you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
R

radosch

Hi,

We had the very same problem - .NET service failed to start
automatically during machine reboot (timeout) but started without
problems when started later manually.
This seems to be a potential problem for any .NET service on a slower
machine (or heavy loaded one) - it just takes some time for CLR to
translate from MSIL to native code and after restart many other
services are being started simultaneously, so sometimes the default
timeout of 30 seconds is not enough :(

The solution was quite simple: we increased the timeout in registry
(HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\ServicesPipeTimeout)
and since then our service starts without problems :)

Jeffrey Tan said:
Hi VinSand,

Thanks for your post!!

Based on my understanding, you implemented an autostart windows service
application in .Net, which works well, but it sometimes can not auto start
on certain machines.

Based on my experience, the problem is probably due to that the Application
event log is full and it does not allow overwriting old entries. Under such
circumstances, the call to the EventLog.WriteEntry in our code cannot
succeed and the service fails to start eventually.

Therefore, I would like to suggest you try clearing the event log and
changing its settings first. Please follow the steps below to do these:
1. Open the Control Panel->Administrative Tools window;
2. Double click the Event Viewer icon;
3. In the log files tree shown in the left pane of the Event Viewer window,
we will see three or more log files;
4. Right click on the Application Log node, and choose the Clear all Events
command from the popup menu;
5. A message box will pop up prompting us to save the old entries of the
log, click No; the Application Log will be cleared;
6. Right click the Application Log node again, and choose the Properties
command from the popup menu; the Application Properties dialog box will
show up;
7. In the General tab of the dialog box, ensure the "Overwrite events as
needed" radio button is selected; this radio button is located in the Log
size group box shown in the lower part of the dialog box;
8. Click OK to apply the changes.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top