How to automatically run as administrator. NET program?

Source: Internet
Author: User

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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.