110,538
社区成员
发帖
与我相关
我的任务
分享
ServiceController sc = new ServiceController("servicename");
ServiceControllerStatus ls = sc.Status;
switch (sStatus)
{
case "Stopped":
if (ls == ServiceControllerStatus.Running || ls == ServiceControllerStatus.Paused)
{
sc.Stop();
}
break;
case "Paused": if (ls == ServiceControllerStatus.Running)
{
sc.Pause();
}
break;
case "Running": if (ls == ServiceControllerStatus.Stopped)
{
sc.Start();
}
else if (ls == ServiceControllerStatus.Paused)
{
sc.Continue();
}
break;
}