By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,780 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,780 IT Pros & Developers. It's quick & easy.

Prevent a service from stopping.

P: n/a
How do I programmatically prevent a service from stopping? I want to
be able to keep my service running (started), under certain conditions,
when a user tries to stop it. I have tried throwing an exception

- from OnStop(): the SCM waits for a long time, reports that the
service didn't respond in a timely fashion and then leaves the status
as stopping.
- from Dispose(): the SCM displays an error dialog with the exception
details and prompts me to select a debugger. If I select 'No' the
service is stopped.

..NET Framework 1.1
MSDE 2003
Windows 2000 SP4

Jan 13 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Set the 'CanStop' property of the service to false.

-mdb

ch***********@teleware.co.uk wrote in news:1137170528.586382.30670
@g47g2000cwa.googlegroups.com:
How do I programmatically prevent a service from stopping? I want to
be able to keep my service running (started), under certain conditions,
when a user tries to stop it. I have tried throwing an exception

Jan 13 '06 #2

P: n/a
Michael Bray <mbray@makeDIntoDot_ctiusaDcom> wrote in
news:Xn***************************@207.46.248.16:
Set the 'CanStop' property of the service to false.


Sorry one thing I didn't notice was that you said you only want to prevent
the service from stopping under certain conditions. If that's the case,
setting the CanStop property to false wouldn't quite suffice.

Here's a further suggestion. Set the CanStop property to false, as above.
But then you will need an application that the user can use to request a
stop. This app would then communicate with your service (via remoting,
perhaps) and if the condition is permitted, stop itself. You should be
able to do this by dynamically setting 'CanStop' to true, then connecting
to yourself with the ServiceController class and issuing the 'Stop'
command.

I haven't actually tried it, but I think that would work.

-mdb
Jan 13 '06 #3

P: n/a
Just s quick note - you wouldn't need remoting for controlling the service,
a ServiceController's ExecuteCommand method would suffice if you need just a
parameterless command not returning anything

"Michael Bray" <mbray@makeDIntoDot_ctiusaDcom> wrote in message
news:Xn****************************@207.46.248.16. ..
Michael Bray <mbray@makeDIntoDot_ctiusaDcom> wrote in
news:Xn***************************@207.46.248.16:
Set the 'CanStop' property of the service to false.


Sorry one thing I didn't notice was that you said you only want to prevent
the service from stopping under certain conditions. If that's the case,
setting the CanStop property to false wouldn't quite suffice.

Here's a further suggestion. Set the CanStop property to false, as above.
But then you will need an application that the user can use to request a
stop. This app would then communicate with your service (via remoting,
perhaps) and if the condition is permitted, stop itself. You should be
able to do this by dynamically setting 'CanStop' to true, then connecting
to yourself with the ServiceController class and issuing the 'Stop'
command.

I haven't actually tried it, but I think that would work.

-mdb

Jan 13 '06 #4

P: n/a
"Lebesgue" <no****@spam.jp> wrote in
news:O#*************@TK2MSFTNGP09.phx.gbl:
Just s quick note - you wouldn't need remoting for controlling the
service, a ServiceController's ExecuteCommand method would suffice if
you need just a parameterless command not returning anything


I've tried using the ExecuteCommand before but I couldn't get it to work.
I forget what the specific error was. Any tricks?

-mdb
Jan 13 '06 #5

P: n/a
You will have to specify "the specific error" This can be caused by numerous
reasons, insufficient privileges to control the service would be the first
thing to look at.

"Michael Bray" <mbray@makeDIntoDot_ctiusaDcom> wrote in message
news:Xn***************************@207.46.248.16.. .
"Lebesgue" <no****@spam.jp> wrote in
news:O#*************@TK2MSFTNGP09.phx.gbl:
Just s quick note - you wouldn't need remoting for controlling the
service, a ServiceController's ExecuteCommand method would suffice if
you need just a parameterless command not returning anything


I've tried using the ExecuteCommand before but I couldn't get it to work.
I forget what the specific error was. Any tricks?

-mdb

Jan 13 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.