How to block unauthorized windows service stop?????

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 1
Reputation: awthein is an unknown quantity at this point 
Solved Threads: 0
awthein awthein is offline Offline
Newbie Poster

How to block unauthorized windows service stop?????

 
0
  #1
Nov 24th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 632
Reputation: Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough Murtan is a jewel in the rough 
Solved Threads: 103
Murtan Murtan is offline Offline
Practically a Master Poster

Re: How to block unauthorized windows service stop?????

 
0
  #2
Nov 25th, 2008
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.)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 475 | Replies: 1
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC