Winform: Obtain Windows UAC administrator privileges

Source: Internet
Author: User

1. Create an app. manifest to write the configuration content

<? Xml version = "1.0" encoding = "UTF-8"?> <Asmv1: assembly manifestVersion = "1.0" xmlns = "urn: schemas-microsoft-com: asm. v1 "xmlns: asmv1 =" urn: schemas-microsoft-com: asm. v1 "xmlns: asmv2 =" urn: schemas-microsoft-com: asm. v2 "xmlns: xsi =" http://www.w3.org/2001/XMLSchema-instance "> <assemblyIdentity version =" 1.0.0.0 "name =" MyApplication. app "/> <trustInfo xmlns =" urn: schemas-microsoft-com: asm. v2 "> <security> <requestedPrivileges xmlns =" urn: schemas-micro Soft-com: asm. v3 "> <! -- UAC configuration option if you want to change the Windows User Account Control level, replace the requestedExecutionLevel node with one of the following nodes. <Strong level = "asInvoker" uiAccess = "false"/> <requestedExecutionLevel = "requireAdministrator" uiAccess = "false"/> <requestedExecutionLevel = "highestAvailable" uiAccess = "false" /> specifying the requestedExecutionLevel node will disable file and Registry virtualization. If you want to use file and Registry virtualization for backward compatibility, delete the requestedExecutionLevel node. --> <RequestedExecutionLevel level = "requireAdministrator" uiAccess = "false"/> </requestedPrivileges> </security> </trustInfo> <compatibility xmlns = "urn: schemas-microsoft-com: compatibility. v1 "> <application> <! -- List of all Windows versions designed for this application. Windows automatically selects the most compatible environment. --> <! -- If the application is designed to use Windows 7, uncomment the following supportedOS node --> <! -- <SupportedOS Id = "{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/> --> </application> </compatibility> <! -- Enable the Windows public control and dialog box topic (Windows XP and later) --> <! -- <Dependency> <dependentAssembly> <assemblyIdentity type = "win32" name = "Microsoft. windows. common-Controls "version =" 6.0.0.0 "processorArchitecture =" * "publicKeyToken =" 6595b64144ccf1df "language =" * "/> </dependentAssembly> </dependency> --> </asmv1: assembly>

2. Modify the level in requestedExecutionLevel

3. Select an application item in the project properties, and then select the added file app. manifest in the list.

4. recompile the program

5. Run the program in bin and you will see the icon under it.

Related Article

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.