How to Stop a Windows Service from inside

L

LucasC

Hi,
I created a Windows Service. I'd like the service to Stop when some error
happen.
Is there any way to do that without using the Services Controller? The
problem with it is that it seems to require Administrative rights and if I
use it from inside the same service then the Service account have to have
administrative rights.

Is there any way to make the service Stop it self?

Thanks a lot

LucasC
 
M

Metallikanz!

An unhandled exception should surely stop the service.

using (ServiceController sc = new ServiceController(this.ServiceName)){

if (sc.CanStop)
sc.Stop();
}

Are you sure, doing the above doesn;t stop the service.

HTH, Metallikanz!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top