1

I'm trying to start an installed Windows Service inside my ASP .NET MVC application. Even with <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

in my app.manifest file, I keep running into 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;
            }
          }
jerryh91
  • 1,777
  • 10
  • 46
  • 77
  • See if the following post solves your problem http://stackoverflow.com/questions/818512/how-to-start-stop-a-windows-service-from-an-asp-net-app-security-issues?rq=1 – AbdulM Feb 22 '15 at 16:40

1 Answers1

0

If you host ASP.NET Website on IIS, then it's privileges are determined by the application pools identity, it's running on. I've never heard of app.manifest for websites. May be i'm wrong, but try to run website in an Application Pool with enough permissions to start a WindowsService, or Debug as different user, if you're using a test webserver.

Andrey Ershov
  • 1,773
  • 1
  • 16
  • 26