C # starts WinForm as an administrator and then uses the administrator to control Windows Service

Source: Internet
Author: User

Cause of the problem:

1,) The problem automatically analyzes when the Windows service is running normally, there are programs and human causes that cause the service to stop. In order to ensure that the service runs correctly when the application is in use, the topic is discussed.

2,) the general account (although the Administrator group account) uses C # code to start the service, still throws an exception because the current program startup account level is not an administrator level.

To start the application solution and test with an administrator:

  In order for the program to start the application in the Administrator group role, we need to add a "application Manifest file" in the application's project and configure the application to start with the Administrator role account.

You can refer to the article: http://tech.cncms.com/web/aspnet/97244_2.html

1,) added app.manifest, and after modifying the configuration, our application will prompt a popup when it starts:

“”

Click "No", will terminate the program normal operation;

Click "Yes" to run as administrator.

2,) verifies that the current application starts the code as an administrator and verifies the results.

Verification Result: Yes Administrator

3,) Start the service code, and test results.

Validation result: normal start service

4,) Stop the service code, and test the results.

Validation result: normal stop service

C # starts WinForm as an administrator and then uses the administrator to control Windows Service

Related Article

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.