我有一个在本地 PC 上运行的 Windows 服务。我的操作系统是 Windows 7。我想通过 C# 代码启动我的服务,而无需通过“计算机管理 > 服务”。
当我运行下面的代码时,它给了我以下信息Exception
:
“在计算机 '.' 上找不到服务 {ServiceName}。”
ServiceController service = new ServiceController(serviceName);
try
{
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
}
catch
{
// ...
}
我看过很多关于这种情况的帖子,都提到这是一个security feature of Windows 7
. 有没有办法在不影响管理员组的情况下运行此服务?