Home >Backend Development >C#.Net Tutorial >Analysis of how .NET programs automatically run as administrator

Analysis of how .NET programs automatically run as administrator

黄舟
黄舟Original
2017-03-15 10:23:061935browse

Windows 7 and Vista improve the security of the system. At the same time, you need to explicitly specify "Run as administrator" to give the running software more advanced permissions,

such as access Registry etc. Otherwise, when a program running as a normal identity needs to access higher-level system resources, an exception

will be thrown.

How to make the program automatically require "administrator" permissions when it starts, we only need to modify the configuration items in the app.man

ifest file.

The app.manifest file does not exist by default. We can automatically add the file through the following operations.

(1) Enter the project

Properties page.

(2) Select the "Security" column.

(3) Check "Enable ClickOnce Security Settings".

Now, the app.manifest file is automatically generated in the Properties directory. Open the file and change the level value of requestedExecutionLevel of the trustInfo/security/requestedPrivileges node to

requireAdministrator. . As shown below:

      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">         
      <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />      
      </requestedPrivileges>


Remember, if you do not need ClickOnce, you can go back to the project properties page and change "Enable ClickOnce Security Settings" is unchecked.​

Next, recompile your program and it will be OK.

The above is the detailed content of Analysis of how .NET programs automatically run as administrator. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn