Hi,
I have a windows service running in my own service framework. Currently, the service can be stopped by using SCM API by sending SERVICE_CONTROL_STOP control code. What I want to do is that the service will ignore the control code unless there is a registry key set (that will be used as a flag showing authorized stop) so that the service won't stop for an authorized stops.
In prototyping, I found that only the first stop attempt (from sc stop) was ignored in HandlerEx function that I registered with (RegisterServiceCtrlHandlerEx API), but the second attempt went through because the service HandlerEx function didn't even get SERVICE_CONTROL_STOP control code on second attempt, and the win32 API (StartServiceCtrlDispatcher) returned although my service hasn't set the service status to SERVICE_STOPPED.
So, basically, the design works only for the first time. I wonder why the service didn't even get the stop control code on second attempt, and the API StartServiceCtrlDispatcher returned. I don't understand why it happened, and why the behaviors are different in first attempt and second attempt. Any explaination is highly appreciated. Any better approaches are also appreciated.
Thanks in advance.