Use. NET 4.0 + to operate the Registry in a 64-bit system. net4.0

Source: Internet
Author: User

Use. NET 4.0 + to operate the Registry in a 64-bit system. net4.0
I. 64-bit Registry

Take the startup Item in LocalMachine as an example:

The Registry of the 64-bit application is still located at: SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run

The 32-bit Application Registry is located at: SOFTWARE \ Wow6432Node \ Microsoft \ Windows \ CurrentVersion \ Run

 

2. How to operate the registry before. NET4.0 (excluding 4.0)
RegistryKey hklm = Registry. LocalMachine; RegistryKey run = hklm. OpenSubKey (@ "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run", true); // other operations

In the above Code, although "SOFTWARE \ Microsoft \ Windows \ CurrentVersion \ Run" is opened, it points to the location of the registry of the 32 application, namely:

"SOFTWARE \ Wow6432Node \ Microsoft \ Windows \ CurrentVersion \ Run", that is, the registry of a 64-bit application cannot be operated in a 64-bit system using the above method.

 

3. Use. NET4.0 + (including 4.0) to operate the registry of a 64-bit Application
            RegistryKey hklm = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);            RegistryKey run = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);

 

Iv. RegistryView Enumeration

Specifies the Registry view to be targeted on a 64-bit operating system.

Default Default view.
Registry64 64-bit view.
Registry32 32-bit view.

 

 

 

Note: If you request a 64-bit view on a 32-bit operating system, the keys returned are all in the 32-bit view.

 

5. MSDN related information

Https://msdn.microsoft.com/zh-cn/library/microsoft.win32.registrykey.openbasekey (v = vs.100). aspx

Https://msdn.microsoft.com/zh-cn/library/microsoft.win32.registryview (v = vs.100). aspx

 

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.