首页 > 解决方案 > ASP.NET 以编程方式启动服务访问被拒绝

问题描述

我正在构建一个 ASP.NET MVC 应用程序,当用户以管理员身份登录(不是 Windows 身份验证,仅限此应用程序的管理员)时,他们需要能够启动和停止服务。每次我以编程方式尝试此操作时,我都会被拒绝访问,该服务作为本地系统运行。是否可以使用ServiceController具有正确权限的特定用户来启动 Windows 服务?关于这个有几个线程,但没有一个回答我的问题。请参见下面的代码:

private static System.ServiceProcess.ServiceController svc = new System.ServiceProcess.ServiceController("CanCam Review Service");

public static void StartService()
{
    string[] args = new string[] { Configuration.databaseConnectionString, Configuration.intervalInSeconds.ToString(), Configuration.packetLimit.ToString(), Configuration.suspectedHackTimeOutInSeconds.ToString(), Configuration.writeToFile.ToString(), Configuration.path, Configuration.maxFileAgeInDays.ToString() };

    if (serviceStatus == ServiceControllerStatus.Stopped)
            svc.Start(args);
}

标签: c#asp.netservice

解决方案


推荐阅读