How to make Delphi read a specific registry key?

845 views Asked by At

I have Delphi XE4 installed on a machine running Windows 7, 64 bit. I was trying to traverse the following two registry keys:

  1. HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
  2. HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall

I wrote a simple program that traverses all the subkeys within each of the above registry keys. When I set the target system to be 32Bit, XE4 ignores registry key #1 and gives me the information from registry key #2 instead. When I set the target system to be 64Bit, XE4 recognizes both registry keys as separate and distinct and returns two different sets of data.

Why does XE4 ignore registry key #1 and substitute key #2 instead when the target system is set to 32Bit? Is there a way to read key #1 when targeting a 32Bit system?

This makes me think there are other registry keys that XE4-32Bit performs some hidden substitute on.

1

There are 1 answers

1
David Heffernan On BEST ANSWER

This is nothing to do with Delphi. This is all about Windows, and specifically the WOW64 emulator that runs 32 bit processes on 64 bit Windows.

A 32 bit process, running under WOW64 on a 64 bit machine is presented with the 32 bit view of certain registry keys. This is handled transparently by the registry redirector. Do follow that MSDN link to learn more about the redirector, and take special heed of the section that tells you never to access Wow6432Node directly.

You can see into different views of the registry like this:

  • A 32 bit process can access the 64 bit registry view using the KEY_WOW64_64KEY flag.
  • A 64 bit process can access the 32 bit registry view using the KEY_WOW64_32KEY flag.

This is covered in more detail on MSDN: Accessing an Alternate Registry View.

In Delphi, you can specify these flags when creating an instance of TRegistry, or through the Access property.