从winform运行windows服务
答
// 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();
}