Hello All How can i control (start, stop) windows service from my windows application?
+1
A:
What do you mean by "run"? If you want to control (start, stop and otherwise manipulate) services installed on your local (or remote) machine, ServiceController is the way to go.
Anton Gogolev
2009-12-22 06:43:02
Thanks Anton...
Pankaj
2009-12-22 06:56:04
+3
A:
// ADD "using System.ServiceProcess;" after you add the
// Reference to the System.ServiceProcess in the solution Explorer
using System.ServiceProcess;
ServiceController myService = new ServiceController();
myService.ServiceName = "ImapiService";
string svcStatus = myService.Status.ToString();
if (svcStatus == "Running")
{
myService.Stop();
}
else if(svcStatus == "Stopped")
{
myService.Start();
}
else
{
myService.Stop();
}
Pankaj
2009-12-22 06:52:57