1, add a new reference to the site, add: System.serviceproces.dll
2, in the code file head plus such as: using System.ServiceProcess;
3, the launch of the service using the following code:
ServiceController sc = new ServiceController ("Service1");
if (SC. Status = = servicecontrollerstatus.stopped)
{
Sc. Start ();
}
4, the service shutdown using the following code:
ServiceController sc = new ServiceController ("Service1");
if (SC. Status = = servicecontrollerstatus.running)
{
Sc. Stop ();
}
5, the Service Control Authority solution
Windows2003 and other server systems provide a sound access mechanism, which is why I do not use the previous mentioned in the ASP.net to invoke another program to start and stop the service through the net command. Because the net command is obviously troublesome, and the release program that invokes the new process is still under the user of the ASPNET (the default user accessed through the Web page), when the page closes, the session end time is automatically released and the program that the user runs is freed. The net command also requires appropriate permissions. ASP.net can be added under Web.config
This resolves the user's logon permissions issue.
The above five steps can complete the control of the server service.
<system.web>
<identity impersonate= "true" username= "admin" password= "admin"/>