How to get a Service to Stop itself!

  • Thread starter Thread starter Nate
  • Start date Start date
N

Nate

Anybody have an idea on how to get a Service to STOP itself?

I have a Service that needs to be able to be stopped, by itself!
I have the "onStop" procedure which basically kills a thread. That works
fine. But when the proc. is finished, the Service still shows as running.

Anybody have any ideas on resolving this?

Thanks,


Nathan.
 
Hi,
This may not be possible as you're actually stopping the service that you're
calling "Stop Service" from, BUT...

Try using a ServiceController component and set all the appropriate
properties in it so that it's pointing to your service running on the local
machine. Then you should be able to instruct the ServiceController to stop
that service.

You may get some security issues with this however, especially if your
service is running as anything other than LocalSystem, I'm not sure that the
NETWORK_SERVICE account has anywhere near the priv's necessary to start
controlling background services.

Cheers,
Alex Clark
 
Hello,

Nate said:
Anybody have an idea on how to get a Service to
STOP itself?

The question is in no way related to Windows Forms programming. Please turn
to an other newsgroup in future.
 
Back
Top