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

时间:2015-02-12 22:35:11

标签: asp.net

我正在尝试在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;
            }
          }

0 个答案:

没有答案