asp.net controls Windows Services __.net

Source: Internet
Author: User

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"/>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.