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;
}
}