service and SetConsoleCtrlHandler

  • Thread starter Thread starter Jan Bares
  • Start date Start date
J

Jan Bares

Hi,

on my Win2k I have a service running. Inside the service start code I use
SetConsoleCtrlHandler() (this is because the service can also be started as
console process for debugging). I realized that my service is shutdown in
some random time (~hours) due to call to HandlerRoutine() routine. I would
like to know how this can happen. I don't suspect that Windows is sending
Ctrl-C to my service at random time...which program can do that?

Aha, just now I realized, that Windows is most probably calling Ctrl-C to
the console when I log off. It seems like all consoles will get Ctrl-C
during log off...comments?

Jan
 
Hi Jan,
Aha, just now I realized, that Windows is most probably calling Ctrl-C to
the console when I log off. It seems like all consoles will get Ctrl-C
during log off...comments?

Windows will issue a CTRL_LOGOFF_EVENT signal to all console processes on
logging off, and this signal would be processed by your service's
HandlerRoutine, if your custom HandlerRoutine doesn't process this signal,
it would be passed to the default HandlerRoutine.

However, for a service application, it receives a modified default console
control handler. This modified handler does not call ExitProcess when
processing the CTRL_LOGOFF_EVENT signal...

For more detail information, you can refer to the following MSDN doc:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/bas
e/handlerroutine.asp


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
Hi Jan,

Do you have any more concerns on this topic, please feel free to post here.


Thanks for your understanding!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
Back
Top