在 "app.manifest" 中设置管理员权限的情况下无法打开窗口服务错误



我正试图在我的ASP.NET MVC应用程序中启动一个已安装的Windows服务。即使使用<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

在我的app.manifest file中,我不断遇到cannot open window service <Service Name> on computer '.'

HomeController.cs
        ServiceController sc = new ServiceController();
        sc.ServiceName = "TestWindowsService";
          //I can see Service status correctly stored in sc.Status
        Debug.WriteLine(sc.ServiceName+ " service status is {0}",
                           sc.Status.ToString());
        if (sc.Status == ServiceControllerStatus.Stopped)
        {
            // Start the service if the current status is stopped.
            Debug.WriteLine("Starting the " + sc.ServiceName +" service...");
            try
            {
                // Start the service, and wait until its status is "Running".
                sc.Start(); //Error here
            }
            catch (InvalidOperationException)
            {
                Debug.WriteLine("Could not start the " +sc.ServiceName +" service.");
                throw;
            }
          }

如果您在IIS上托管ASP.NET网站,那么它的权限由运行的应用程序池标识决定。我从未听说过网站的app.manifest。也许我错了,但如果你使用的是测试Web服务器,请尝试在具有足够权限的应用程序池中运行网站来启动WindowsService,或者以其他用户身份调试。

最新更新