C # Run the WinForm program as an administrator

Excerpted from: https://www.cnblogs.com/yuluo/p/5718057.html

   The WinForm client developed recently for customers, part of it In the process of use, an error message of “system file not found” will appear.

After    is debugged, it is determined that it is an error caused by the system authority when the program is operating the configuration file. The direct administrator authority will run normally.

   Considering the convenience of user operations, it is set to obtain system administrator permissions by default for each run. The following are the setting steps.

The first step, 1. In Visual Studio-Solution Explorer-right-click the project name-properties, find the “Security” option, check “Enable ClickOnce security settings”:< /h2>

Share a picture

< /p>

share picture

The second step, at this time, in There will be an additional “app.manifest” file under the project,

Share a picture

Select it and find the code snippet ,

Change it to: ,

Share pictures

The third step, after correction, do not rush to recompile and generate, and open the “Properties-Security” interface again ,

Share a picture

Remove the check mark in front of “Enable ClickOnce Security Settings” before compiling and running. Otherwise, the program will report an error and cannot run.

The fourth and final step is to save the changes and recompile the program.

When you open the program again, you will be prompted to “User Account Control” to obtain administrator rights to run, and click “Yes” to obtain administrator rights.

Leave a Comment

Your email address will not be published.