如何从Windows应用程序控制(启动,停止)Windows服务?
答案 0 :(得分:3)
// 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();
}
答案 1 :(得分:1)
“跑”是什么意思?如果您想控制(启动,停止和以其他方式操纵)本地(或远程)计算机上安装的服务,ServiceController是可行的方法。