You hacker Willy............lol
ServiceController serviceMonitor = new ServiceController("servicename");
if( serviceMonitor == ServiceControllerStatus.Running )
{
serviceMonitor.Stop();
}
However, I have seen this justifiably fail when trying to stop the service
from within itself ..........ideally you should stop the service from a
controlling service by having your service cleanly set an external param
that causes the service to be terminated by the controller. In reality a
service should not die but terminate cleanly by timed or user action which
is why I'm suggesting you should use a controller, your service should
remain active even if the files not there and handle the
exception............Willy's suggestion will undoutably work though.
--
Regards
John Timney
Microsoft Regional Director
Microsoft MVP
"Willy Denoyette [MVP]" <wi*************@pandora.be> wrote in message
news:O8**************@TK2MSFTNGP12.phx.gbl...
Just throw an (unhandled) exception and your service will stop.
Willy.
"Xman" <Xm**@discussions.microsoft.com> wrote in message
news:A9**********************************@microsof t.com... Can anyone tell how to stop a service from within the service,
example:
On starting the service needs a file from the disk if it does not find
the file i need the service stop and end. But I can't find any command or
methods
for stopping the service from running any further.
can anyone help?