Original address: 51010962
Refer to Uac:user account Control
Reference IE protection mode: 5336809
Open VS2005, VS2008, VS2010, VS2012, VS2013, VS2015 Engineering, View the Properties folder in the project folder for app.manifest this file; if not, create it as follows: Right-click the project in the menu, select "Properties", click on the "Security" tab of the project properties, and check the " Enable ClickOnce Security settings and select this is a fully trusted application to save the project, at which time the app.manifest file has been automatically generated under properties.
Change the default app.manifest file to
[HTML]View PlainCopy
- <? Xml version= "1.0" Encoding= "utf-8" ?>
- <asmv1:assembly manifestversion=< Span class= "Attribute-value" > "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 Listing options
- If you want to change the Windows user Account Control level, replace it with one of the following nodes
- The requestedExecutionLevel node.
- <requestedexecutionlevel level="AsInvoker" uiaccess="false" />
- <requestedexecutionlevel level="requireadministrator" uiaccess="false" />
- <requestedexecutionlevel level="highestavailable" uiaccess="false" />
- Specifying the requestedExecutionLevel node disables file and registry virtualization.
- If you want to take advantage of 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>
- <!--This application is designed to use a list of all versions of Windows. Windows will automatically select the most compatible environment. -
- <!--If the application design uses Windows 7, uncomment the following Supportedos node--
- <!--<supportedos id= "{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>-->
- </Application>
- </compatibility>
- <!--enable Windows Common Controls and dialog boxes for themes (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>
Modify <requestedexecutionlevel level= "Requireadministrator" uiaccess= "false"/> node.
After the configuration file is modified, we run the application, we will first pop up such a prompt box, click Yes, the program can continue to run.
By the way, there is also a way to find out if the program is running as Administrator right at this point:
[CSharp]View PlainCopy
- Public 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, respectively:
AsInvoker: The application is running with the current permissions.
Highestavailable: This is run with the highest privileges available to the current user.
Requireadministrator: This is only run with system administrator privileges.
By default, it is AsInvoker.
Both the highestavailable and Requireadministrator options can prompt the user for system administrator privileges. So what's the difference between these two options?
The difference is that if we are not logged in as an administrator account, then if the application is set to Requireadministrator, then the application will fail to run directly and cannot start. If set to Highestavailable, the application can run successfully, but runs with the permissions of the current account instead of system administrator privileges. If we want the program to run when a non-admin account is logged in (in which case some functionality should be limited), we recommend that you configure it with highestavailable.
C # Projects introduce app.manifest administrator permissions to run