How does Windows service work when Windows shutdown?

Is there a timeout to stop Windows services when shutting down Windows? I know there is a "WaitToKillServiceTimeout" registry key, but does this timeout affect services when Windows shuts down or is there another timeout?

I want to know how long the system is waiting for service during shutdown when it calls the OnStop method for a service.

Can a service prevent Windows from shutting down?

+3


source to share


1 answer


From TechNet :

[WaitToKillServiceTimeout] Determines how long the system waits for services to stop after notifying a service that the system is shutting down.

Then yes, this is the value that is used to wait for services to shutdown, and also notes that it is used for all services:

If all services stop before this value expires, the system shuts down ...

For your question, "Can a service prevent Windows from shutting down?" the answer is "more or less". You cannot prevent Windows from shutting down (this can be very frustrating for users if they cannot shut down because the service decided they shouldn't), but:



When this entry expires, the system notifies the user that the service has not been stopped. The user can force the service to stop or continue to wait. If the user is waiting, this value specifies the interval between repeated notifications to the user that the service is not stopped.

Note that:

Some services increase the value of this entry to allow more time for cleaning tasks.

If your service is slow, you can increase this value (during installation) to give you more time. In theory, using a very high value would delay the shutdown for a very long time (but this is not the same as canceling it and remembering that it is used for all services).

AFAIK the service cannot cancel shutdown, but a GUI application can do it using the ShutdownBlockReasonCreate () function .

+2


source







All Articles