I have the below methods to start and stop a service. I call this method from another Console application to debug since I've used the methods in a Class Library(DLL).
The application is started with administrative rights.
public void ServiceStart()
{
ServiceController service = new ServiceController();
service.ServiceName = "ASP.NET State Service";
service.Start();
}
public void ServiceStop()
{
ServiceController service = new ServiceController();
service.ServiceName = "ASP.NET State Service";
service.Stop();
}
But when I call Start()
or Stop()
an exception with the following message is thrown:
Cannot open ASP.NET State Service service on computer '.'
Can someone help me out?