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