2

While researching this problem I came across this question. I'm having the exact same problem accept my program is already running as administrator and is already accessing the registry using TRegistry.Create(KEY_READ).

The key I'm trying to access is HKLM\Software\FireBird Project\Firebird Server\Instances. The way I understand it (and correct me if I'm wrong) is that the registry redirector is enabled by default for any 32 bit process that reads or writes to HKLM\Software unless it is explicitly disabled.

Is there any way to tell if this the case with this key? I've looked through the source for the win32 firebird installer and nothing stuck out.

Update

!@#$%

Turned out it was finding the key all along. I was using this key to locate the isql utility so I could create a firebird database. This was happening in the BeforeConnect event of a db connection. For whatever reason the connection was being attempted and raising an exception before the event was triggered so the database was never getting created. Note to self: Never trust a Before* event to happen before anything.

Community
  • 1
  • 1
Kenneth Cochran
  • 11,954
  • 3
  • 52
  • 117

1 Answers1

2

Most keys under HKLM\Software are subject to redirection and this key falls into that category. It will be redirected when accessed from a 32 bit process running under the WOW64 emulator.

Use KEY_WOW64_32KEY to access the 32-bit view of the registry or KEY_WOW64_64KEY to access the 64-bit view of the registry. Specify neither to access the view of the registry with the same bitness as the calling process.

The full list of keys that are affected by redirection is here: Registry Keys Affected by WOW64.

The table presented there is a little tricky to read. For example, and considering only Windows 7, HKLM\Software is marked a being redirected. However, a number of sub keys are marked as being shared rather than redirected. Shared means that both 32 and 64 bit processes see the same underlying data. So, not all sub-keys of HKLM\Software are redirected. If a sub-key of HKLM\Software is not indicated as being shared, then it is redirected. And that's the case for your key.


In the question title and in the comments you indicate that the key you are looking for is in the 32 bit view of the registry. In that case, since your process is also 32 bit, you have nothing to do. Open the registry with KEY_READ only. You don't need to elevate to admin because you are only reading. You then ask to read HKLM\Software\FireBird Project\Firebird Server\Instances and let the redirector take you to the 32 bit view under Wow6432Node.

One of the golden rules of using the registry is that you should never hard-code Wow6432Node in your app. Let the redirector do the work.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • The app is running as admin for other reasons. As I mentioned above I am already accessing the registry with read only permissions but for some reason it can't find the key. Is is possible registry virtualization is also playing a part it this? – Kenneth Cochran Jan 17 '12 at 21:18
  • 1
    Virtualization could be hurting you. Is your app running virtualized? I'd completely forgotten about that. Please please don't tell me you haven't moved on from running virtualized yet! – David Heffernan Jan 17 '12 at 21:55
  • This app is about 20 years old. It writes configuration and data to the same folder as the executable (which is usually located one level beneath the root). It uses WinAPI functions that require administrative access. It modifies registry settings that don't belong to it. If we attempted windows logo certification it would take years to get it in shape. – Kenneth Cochran Jan 17 '12 at 22:45
  • you don't need to logo it, just add an app manifest – David Heffernan Jan 17 '12 at 22:47