Solutions for compatibility with the win7 registry in software development
Prepared by: CC Dad
L recently, when developing a winform program, I found that access to the registry in the xp system is normal. At this point, Microsoft reminded everyone. Xp will end in April this year. Therefore, we must consider compatibility with win7.
When Windows 7 is accessed, the returned registry value is inconsistent with the actual one.
After searching for some solutions on the Internet, the solutions provided by the following personnel are the correct solutions.
First, you must grant the user administrator the permission to read the registry. If exe is not run as administrator in Vista or Win7, it will be blocked by UAC (User Account Control) to access certain functions of the system, such as modifying the registry; there are two ways to run an exe with administrator permissions: one is to directly modify the exe attribute, and the other is to add MANIFEST resources to the program, which are described below.
1. directly modify the exe attributes:
1) Right-click "exe" and select "properties" from the pop-up menu. The displayed interface is as follows:
2) Select "compatibility" and select "run this program as administrator.
2. Add MANIFEST resources to the C # program,
1) Open the vs2008 project and check whether the file app. manifest exists in Properties. If not, right-click the project and select "Properties" from the menu. The page is displayed as follows:
2) Select "security" and select "enable ClickOnce Security Settings" on the interface. The app. manifest file is automatically generated under Properties.
3) Open the app. manifest file and add
<RequestedPrivileges>
<RequestedExecutionLevel level = "requireAdministrator" cess = "false"/>
</RequestedPrivileges> View Code
4) re-compile. The Code is as follows:
<? Xml version = "1.0" encoding = "UTF-8"?>
6) <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 ">
7) <assemblyIdentity version = "1.0.0.0" name = "MyApplication. app"/>
8) <trustInfo xmlns = "urn: schemas-microsoft-com: asm. v2">
9) <security>
10) <requestedPrivileges xmlns = "urn: schemas-microsoft-com: asm. v3">
11) <! -- UAC configuration options
12) If you want to change the Windows User Account Control level, replace it with one of the following nodes:
13) requestedExecutionLevel node.
14)
15) <requestedExecutionLevel level = "asInvoker" uiAccess = "false"/>
16) <requestedExecutionLevel = "requireAdministrator" uiAccess = "false"/>
17) <requestedExecutionLevel level = "highestAvailable" uiAccess = "false"/>
18)
19) If you want to use file and Registry virtualization to provide
20) for backward compatibility, delete the requestedExecutionLevel node.
21) -->
22) <! -- <RequestedExecutionLevel level = "asInvoker" uiAccess = "false"/> -->
23) <requestedPrivileges>
24) <requestedExecutionLevel level = "requireAdministrator" cess = "false"/>
25) </requestedPrivileges>
26)
27) </requestedPrivileges>
28) <applicationRequestMinimum>
29) <PermissionSet class = "System. Security. PermissionSet" version = "1" Unrestricted = "true" ID = "Custom" SameSite = "site"/>
30) <defaultAssemblyRequest permissionSetReference = "Custom"/>
31) </applicationRequestMinimum>
32) </security>
33) </trustInfo>
34) </asmv1: assembly> View Code