我写了一个安装程序,它安装了需要启动/停止另一个服务(B)的Windows服务(A)。但是,当A尝试启动/停止B时,出现以下异常:如何安装以管理员身份运行的Windows服务?
System.InvalidOperationException:无法在计算机'。'上打开MyService服务。 ---> System.ComponentModel.Win32Exception:访问被拒绝
安装程序将服务安装为本地服务,并且它通过我授予的UAC弹出窗口来请求管理员权限。我还添加了一个app.manifest文件被设置为要求管理员权限的服务:
但我仍然收到这个错误。
这是我如何启动服务(停车是一样的,只不过它调用停止,当然):
using (Mutex mutex = new Mutex(false, "MyServiceLock"))
{
mutex.WaitOne();
if (ServiceExists(serviceName) == true)
{
using (ServiceController serviceController = new ServiceController(serviceName, "."))
{
serviceController.Start(); // this line throws the exception
}
}
mutex.ReleaseMutex();
}
为什么会访问该服务被拒绝?
您能否更新问题以符合接受的答案?就我个人而言,我很想看看如何安装服务以管理员身份运行。 – tishma 2016-04-04 15:08:02