Original: How to automatically run as administrator. NET program?
Windows 7 and Vista improve the security of the system, and need to explicitly specify "Run as administrator" to give the running software more advanced permissions, such as access to the registry and so on. Otherwise, an exception will be thrown when a program running in normal status needs to access higher-level system resources.
How to get the program to automatically ask for "admin" permission when it starts, we just need to modify the configuration item in the App.manifest file.
The app.manifest file does not exist by default, and we can add the file automatically by doing the following.
(1) Enter the project Properties page.
(2) Select the "Security" section.
(3) Tick "Enable ClickOnce security Settings".
Now, the app.manifest file is automatically generated in the properties directory, and the file is opened, and the trustinfo/security/ The value of the requestedexecutionlevel level of the Requestedprivileges node is modified to Requireadministrator. As shown below:
<requestedprivileges xmlns="Urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel Level="
requireadministrator"uiAccess="false" />
</requestedprivileges>
Remember, if you don't need ClickOnce, you can go back to the project Properties page and uncheck "Enable ClickOnce Security Settings."
Next, recompile your program and it's OK.
How to automatically run as administrator. NET program?