【发布时间】:2014-01-21 12:09:40
【问题描述】:
我有一个 windows 服务和一个 windows 应用程序。我想通过参数从我的 windows 应用程序启动和停止这个 windows 服务。这是我启动服务所必须的
foreach (ServiceController sc in ServiceController.GetServices())
{
if (sc.ServiceName == "serviceName")
{
//service is found
using (ServiceController serviceController = new ServiceController("serviceName"))
{
string[] args = new string[1];
args[0] = "Myargument";
if (serviceController.Status == ServiceControllerStatus.Running)
{
}
else { serviceController.Start(args); }
}
}
但它给了我无法在计算机上打开服务'.'异常。我尝试使用 app.manifest 强制以管理员身份运行,但仍然出现异常。我也尝试了这篇文章here 但是异常仍然存在。是否有人知道如何在 Windows 7 中授予对非管理员用户管理服务的访问权限?
【问题讨论】:
标签: c# windows windows-services