无法打开计算机“.”上的服务控制管理器。此操作可能需要其他特权。
无法打开计算机“.”上的服务控制管理器。此操作可能需要其他特权。
出错的代码段
该服务主要监视另一个服务的服务状态
定时获取GprsService的服务状态,如果超过指定时间没有获取到数据,重启GprsService服务.
try
{
ServiceController serviceGprs = new ServiceController("GprsService");
string serviceState = serviceGprs.Status.ToString();
//最近一条数据与当前时间的时间差
int timeDiff = Helper.GetLastData();
if (serviceState.Equals("Stopped"))
{
timer.Enabled = false;
serviceGprs.Start();
//等待
Helper.AddLog("GprsService异常终止,正在重新启动!");
serviceGprs.WaitForStatus(ServiceControllerStatus.Running);
Helper.AddLog("GprsService异常终止,启动完毕!");
timer.Interval = outTime * 60 * 1000;
timer.Enabled = true;
}
else if (timeDiff > outTime)
{
timer.Enabled = false;
//等待
Helper.AddLog("GprsService没有响应,正在停止服务!");
serviceGprs.Stop();
serviceGprs.WaitForStatus(ServiceControllerStatus.Stopped);
Helper.AddLog("服务已经停止,正在重新启动服务!");
serviceGprs.Start();
serviceGprs.WaitForStatus(ServiceControllerStatus.Running);