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")
 

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

Back
Top