Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should never need to use <code>ExitProcess()</code> to stop a service. In fact, you should never need to use <code>ExitProcess()</code> at all.</p> <p>Services are deeply intertwined with the SCM, and if a service that it thinks should be running just vanishes it will take some action to repair it. In extreme cases, it will force the system to reboot.</p> <p>The correct way to stop a service is to use the documented API to ask the SCM to ask the service to stop. It often takes several seconds for this process to complete as the service itself usually needs to a clean shutdown after asking its worker threads to finish up and halt.</p> <p>The privileges required to interact with the SCM are less dangerous than that required to end an arbitrary process, but neither is usually granted outside of the Administrators group. </p> <p><strong>Edit:</strong> A comment asked about stopping a service from inside itself. </p> <p>That can be a tough call, especially if the service is in some kind of unfortunate state. The service and the SCM absolutely have to agree that the service is stopping, or the SCM will take the recovery action that was configured for the service.</p> <p>I do have a complete implementation of a service that might serve as an alternative point of view for how to handle some of these things. It is <a href="http://luaforge.net/projects/luaservice/" rel="nofollow noreferrer">LuaService</a> and is a framework that allows a (single worker thread) service to be implemented in pure <a href="http://www.lua.org/" rel="nofollow noreferrer">Lua</a> aside from the LuaService executable itself. Its <a href="http://luaforge.net/docman/view.php/326/1640/LuaService.pdf" rel="nofollow noreferrer">reference manual</a> attempts to fully document the internals, as well as document some of the details of a service's lifetime that are otherwise documented through the interaction of various articles on MSDN.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload