How to Stop a Windows Service from inside

  • Thread starter Thread starter LucasC
  • Start date Start date
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
 
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!
 
Back
Top