How to make the. net program run automatically under the administrator privilege VS2010 c # The compiled WINFORM program runs as administrator in Win7
Windows 7 and vista improve system security. You must specify "Run as administrator" to grant advanced permissions to the running software, such as accessing the registry. Otherwise, an exception is thrown when a program running as a normal user needs to access more advanced system resources.
To enable the program to automatically require the "Administrator" permission during startup, you only need to modify the configuration items in the app. manifest file.
The app. manifest file does not exist by default. You can add the file automatically by performing the following operations.
(1) Go to the project properties page.
(2) Select "security.
(3) Select "enable ClickOnce Security Settings.
Now, the app. manifest file is automatically generated in the Properties directory. open the file and change the value of requestedExecutionLevel of the trustInfo/security/requestedPrivileges node to requireAdministrator. As follows:
<RequestedPrivileges xmlns = "urn: schemas-microsoft-com: asm. v3">
<RequestedExecutionLevel level = "requireAdministrator" uiAccess = "false"/>;
</RequestedPrivileges>
(4) Remember, if you do not need ClickOnce, you can go back to the project properties page and deselect "enable ClickOnce Security Settings.
(5) Next, recompile your program.
This is an excerpt from the event where you want to complain about Dongfeng ~