C# 操作系统服务(service)代码
2018-07-20 来源:open-open
C# 操作系统服务(service)代码
可以控制启动和停止系统服务
可以控制启动和停止系统服务
private bool StopService(string StopServiceName)
{
ServiceController service = new ServiceController(StopServiceName);
try
{
service.Stop();
service.WaitForStatus(ServiceControllerStatus.Stopped);
}
catch(Exception)
{
return false;
}
return true;
}
/// <summary>
/// 开启服务
/// </summary>
private bool StartService(string StartServiceName)
{
ServiceController service = new ServiceController(StartServiceName);
try
{
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running);
}
catch (Exception)
{
return false;
}
return true;
}
标签: 代码
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:C#修复网络连接代码
下一篇:C#查找字符串的所有排列组合
最新资讯
热门推荐