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