At what point does ControlService(SERVICE_CONTROL_STOP) returns
ERROR_INVALID_SERVICE_CONTROL?
pI'm coding a Windows service using C++ and WinAPIs. In some exceptional
situation this service may be stopped (from an outside process) almost
immediately after it is started using the following API:/p
precodeif(!ControlService(hScService, SERVICE_CONTROL_STOP,
(LPSERVICE_STATUS)amp;ssp)) { //Error } /code/pre pThe full code for
stopping the service is taken from a
href=http://msdn.microsoft.com/en-us/library/windows/desktop/ms686335%28v=vs.85%29.aspx
rel=nofollowhere/a./p pThe line above works just fine if the service is
stopped in normal circumstances but it fails with the error code
codeERROR_INVALID_SERVICE_CONTROL/code if it is called almost immediately
after the service is started./p pMoreover, if I do this:/p
precode::Sleep(3 * 1000); if(!ControlService(hScService,
SERVICE_CONTROL_STOP, (LPSERVICE_STATUS)amp;ssp)) { //Error } /code/pre
pThis API does not return an error./p pI can't seem to find any official
documentation as to why I'd get codeERROR_INVALID_SERVICE_CONTROL/code for
codeSERVICE_CONTROL_STOP/code control code. Can somebody shed some light
on this, please?/p
No comments:
Post a Comment