| | |
How to block unauthorized windows service stop?????
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Nov 2008
Posts: 1
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: May 2008
Posts: 632
Reputation:
Solved Threads: 103
Not stopping your service is a bit unfriendly, do you properly handle getting stopped if windows is shutting down?
I suspect the reason you don't get called a second time is because something you're doing in the first event causes you to be removed from the handler chain.
Confirm that any value you return is an expected and 'normal' value.
If you are passed any data structures that you modify, make sure you are setting the proper values.
If everything appears correct, it may be that you have to re-add your handler every time it is called. (It doesn't make a lot of sense, but it wouldn't be the first time I've seen something like it.)
I suspect the reason you don't get called a second time is because something you're doing in the first event causes you to be removed from the handler chain.
Confirm that any value you return is an expected and 'normal' value.
If you are passed any data structures that you modify, make sure you are setting the proper values.
If everything appears correct, it may be that you have to re-add your handler every time it is called. (It doesn't make a lot of sense, but it wouldn't be the first time I've seen something like it.)
![]() |
Similar Threads
- Cannot find server or DNS Error - please help! (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: how to convert char to int
- Next Thread: Notify Access to a file
Views: 475 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





