Stop a Windows Service

  • Thread starter Thread starter João Santa Bárbara
  • Start date Start date
J

João Santa Bárbara

hi all
how can i stop a service inside it self

i wil explain, when an erros ocurrs inside of a service, i need to stop it
...

thks
JSB
 
Something along the lines of this should stop your service.

ServiceController serviceMonitor = new ServiceController("servicename");
if( serviceMonitor == ServiceControllerStatus.Running )
{
serviceMonitor.Stop();
}

Regards

John Timney
Microsoft Regional Director
Microsoft MVP
 
would it work a quick and dirty solution where you run a system command
called "net stop" ???
if it does...
system("net stop myownname")
 
Back
Top