Precautions for operating the registry in a 64-bit System

Source: Internet
Author: User

Precautions for operating the registry in a 64-bit System

1. Registry location

The 64-bit registry is divided into 32-bit registry keys and 64-bit registry keys.

In the 64-bit system, we can see from regedit that the registry keys in the specified path are all 64-bit registry keys, and the 32-bit registry keys are relocated to: HKEY_LOCAL_MACHINE \ Software \ WOW6432Node.

When the application operates the registry, it is also divided into the 32bit and 64bit modes. 32-bit applications running on 64-bit systems operate on the 32-bit registry key by default (that is, the sub-item redirected to WOW6432Node), while 64-bit applications are the intuitive sub-item of operations.
// Z 2012-2-9 17:52:04 IS2120 @ CSDN

For example, in a 64-bit system, use the following code to access the registry:

: RegOpenKeyEx (HKEY_LOCAL_MACHINE, _ T ("Software \ Sobey \ MPC"), 0,KEY_ALL_ACCESS, & hKey)

If the application is a 32bit subsystem, the actual accessed registry location is HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Sobey \ MPC;

If the application is a 64-bit subsystem, the actual accessed registry location will be: HKEY_LOCAL_MACHINE \ SOFTWARE \ Sobey \ MPC.

// Z 2012-2-9 17:52:04 IS2120 @ CSDN

2. Programming

During programming, you can use KEY_WOW64_64KEY and KEY_WOW64_32KEY to explicitly specify the 64-bit registry key or 32-bit registry key. For example,

The 32bit application can explicitly specify the access 64-bit registry key in the following way, the program code:

: RegOpenKeyEx (HKEY_LOCAL_MACHINE, _ T ("Software \ Sobey \ MPC"), 0, KEY_ALL_ACCESS| KEY_WOW64_64KEY, & hKey)

Note the keyword KEY_WOW64_64KEY;

The Registry Key written in this way will be exactly located at: HKEY_LOCAL_MACHINE \ SOFTWARE \ Sobey \ nmpc.


64bitYingYou can use the following method to explicitly specify the access to the 32bit registry key, the program code:

: RegOpenKeyEx (HKEY_LOCAL_MACHINE, _ T ("Software \ Sobey \ nm\ \ Test"), 0, KEY_ALL_ACCESS| KEY_WOW64_32KEY, & hKey)

Note the keyword KEY_WOW64_32KEY

The Registry Key written in this way will be exactly located at the location: HKEY_LOCAL_MACHINE \ SOFTWARE \ Wow6432Node \ Sobey \ MPC.

3. Special reminder

The above description only applies to the HKEY_LOCAL_MACHINE primary key, and there is no similar situation under the HKEY_CURRENT_USER primary key. It is meaningless to specify the KEY_WOW64_64KEY and KEY_WOW64_32KEY when accessing the HKEY_CURRENT_USER primary key.

In short, try to use the HKEY_CURRENT_USER primary key to save the user configuration.

4. References

How to view the system registry through the 64-bit Windows Version

Accessing anAlternate Registry View

Registry Redirector in x64/IA64

KEY_WOW64_64KEYand KEY_WOW64_32KEY

// Z 2012-2-9 17:52:04 IS2120 @ CSDN
This is really about Win32 on Win64, or Windows on Windows, or shortfor WOW.

MSDN has keep information about 64 bits Windows here (http://msdn.microsoft.com/library/default.asp? Url =/library/en-us/dnanchor/html/64bitwindows. asp). One particle piece information about registry is too E (http://msdn.microsoft.com/library/default.asp? Url =/library/en-us/win64/win64/registry_redirector.asp ). for the most part, there are two registry hives, 64 bit hive and 32bit hive. applications running under WOW use 32bit hive, and native 64 bitapplications use 64 bit hive.

If an application running under WOW wants to use 64 bit hive, it has tospecify KEY_WOW64_64KEY in RegOpenKeyEx/RegCreateKeyEx. This is already ented here (http://msdn.microsoft.com/library/default.asp? Url =/library/en-us/sysinfo/base/registry_key_security_and_access_rights.asp ).

If a registry handle hKey is opened with KEY_WOW64_64KEY under WOW, and youwant to open its subkey, you still have to pass KEY_WOW64_64KEY toRegOpenKeyEx. the WOW system does not remember hKey is opened withKEY_WOW64_64KEY. if you don't pass KEY_WOW64_64KEY to RegOpenKeyEx, WOW willtry to open the subkey in 32bit hive, and will likely fail to find the subkeyif the subkey does not exist in 32bit hive.

KEY_WOW64_32KEY is about native 64 bit applications use 32bit hive. And ithas to follow the same rule.

// Z 2012-2-9 17:52:04 IS2120 @ CSDN

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.