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
- <? 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-Microsoft-com: ASM. V3">
- <! -- UAC manifest options
- If you want to change the Windows User Account Control level Replace
- Requestedexecutionlevel node with one of the following.
- <Requestedexecutionlevel level = "asinvoker" UIAccess = "false"/>
- <Requestedexecutionlevel level = "requireadministrator" UIAccess = "false"/>
- <Requestedexecutionlevel level = "highestavailable" UIAccess = "false"/>
- If you want to utilize file and Registry virtualization alization for backward
- Compatibility then delete the requestedexecutionlevel node.
- -->
- <Requestedexecutionlevel level = "requireadministrator" UIAccess = "false"/>
- </Requestedprivileges>
- </Security>
- </Trustinfo>
- </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
- Public static bool isadministrator ()
- {
- Windowsidentity identity = windowsidentity. getcurrent ();
- Windowsprincipal principal = new windowsprincipal (identity );
- Return principal. isinrole (windowsbuiltinrole. Administrator );
- }
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.