Turn: UAC Problems

Source: Internet
Author: User

Open the vs2005, vs2008, and vs2010 projects, and check whether there is an app under the properties folder in the project folder. if the file manifest does not exist, create it as follows: Right-click the project and select "properties" from the menu, and click the "Security" tab of the project properties, on the "Security" tab, select "enable clickonce Security Settings", select "this is a fully trusted application", save the project, and an app is automatically generated under properties. manifest file.

Change the default app. manifest file

  1. <? XML version = "1.0" encoding = "UTF-8"?>
  2. <Asmv1: Assembly manifestversion = "1.0" xmlns = "urn: Schemas-Microsoft-com: ASM. V1"
  3. Xmlns: asmv1 = "urn: Schemas-Microsoft-com: ASM. V1" xmlns: asmv2 = "urn: Schemas-Microsoft-com: ASM. V2"
  4. Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance">
  5. <Assemblyidentity version = "1.0.0.0" name = "myapplication. app"/>
  6. <Trustinfo xmlns = "urn: Schemas-Microsoft-com: ASM. V2">
  7. <Security>
  8. <Requestedprivileges xmlns = "urn: Schemas-Microsoft-com: ASM. V3">
  9. <! -- UAC manifest options
  10. If you want to change the Windows User Account Control level Replace
  11. Requestedexecutionlevel node with one of the following.
  12. <Requestedexecutionlevel level = "asinvoker" UIAccess = "false"/>
  13. <Requestedexecutionlevel level = "requireadministrator" UIAccess = "false"/>
  14. <Requestedexecutionlevel level = "highestavailable" UIAccess = "false"/>
  15. If you want to utilize file and Registry virtualization alization for backward
  16. Compatibility then delete the requestedexecutionlevel node.
  17. -->
  18. <Requestedexecutionlevel level = "requireadministrator" UIAccess = "false"/>
  19. </Requestedprivileges>
  20. </Security>
  21. </Trustinfo>
  22. </Asmv1: Assembly>

After the configuration file is modified, we run the application. A prompt box is displayed. Click Yes to continue running the program.

By the way, you can also find out whether the program runs as administrator at this time through a method:

[CSHARP]View plaincopy
  1. Public static bool isadministrator ()
  2. {
  3. Windowsidentity identity = windowsidentity. getcurrent ();
  4. Windowsprincipal principal = new windowsprincipal (identity );
  5. Return principal. isinrole (windowsbuiltinrole. Administrator );
  6. }


The UAC execution permission level referenced in the XML file represents the following meanings:

Asinvoker: The application runs with the current permission.

Highestavailable: this operation is run with the highest permissions available to the current user.

Requireadministrator: this operation only runs as a system administrator.

The default value is asinvoker.

Both highestavailable and requireadministrator prompts you to obtain system administrator privileges. So what are the differences between the two options?

The difference between them is that if we do not log on with an administrator account, if the application is set to requireadministrator, the application will directly run and fail to start. If it is set to highestavailable, the application can run successfully, but it runs with the permissions of the current account rather than the system administrator. If we want the program to run during non-administrator login (some functions should be restricted in this case), we recommend using highestavailable for configuration.

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.