I created a Windows service and would like to send it a control+B or control+C control value. I know I can use sc control, but I was wondering if there was a location that contained all possible values I can send. There is a sc stop method, but I'm looking to send it a control character.
Asked
Active
Viewed 500 times
1
-
Windows services are managed by the Windows Service Control Manager (SCM), which is accesible using the `sc` command. Why is that command (or `net start/stop`) not sufficient? What is the use case where this is not enough? If you are looking for a documentation of the `sc` tool, just type `sc` at the command prompt and you will see "all possible values" that you can send. – Dirk Vollmar Dec 29 '10 at 00:16
-
I agree that I should be using net stop, or sc stop, but those don't shutdown a service gracefully, I'm looking for a method that will shutdown the service with a control+B. Control+B is similar to a control+C, except B does a more graceful shutdown in windows. – Steve Dec 29 '10 at 00:25
-
1net stop does indeed shut down a service gracefully, as the service gets sent an OnStop event to react to and clean up. Is this a service that is just a regular EXE wrapped in some service wrapper? – Joe Dec 29 '10 at 02:52
1 Answers
2
The "gracefulness" of a service shutdown all depends on how your service responds to the request. If you're writing the service, then you have full control over how your service responds when the SCM sends a "stop" request. After receiving the request, you have a limited amount of time (Windows decides how much) to stop your service and respond to the control request. If you fail to respond in a timely manner, Windows may terminate your service process ungracefully.
A console application can respond to a Ctrl+C request using the SetConsoleCtrlHandler()
function. However, service processes are not run inside a console window, so this handler is completely unapplicable to services.

Greg Hewgill
- 951,095
- 183
- 1,149
- 1,285
-
After some more investigation I found that when I start the service through command line (sc start) I get a state like this: (NOT_STOPPABLE, NOT_PAUSABLE, IGNORES_SHUTDOWN) . The ignores_shutdown is what I believe might be the cause of the problem. – Steve Dec 29 '10 at 15:51