4

I do not understand. There is a window registry key of firebird server I want to check if it exists. The key exists but the function returns false. What is wrong? I'm using Windows 7 64x with delphi 2010.

Tks. Davis.

procedure x;
  var
    reg:TRegistry;
begin

  reg := TRegistry.Create;
  reg.RootKey := HKEY_LOCAL_MACHINE;

  if reg.OpenKey('\SOFTWARE\Firebird Project\Firebird Server\Instances',false)=true then
  begin
    ShowMessage('Key exists');
  end;

end;
1

4 Answers 4

6

The most likely reason is that you have opened the key requesting write access but on Windows 7 under UAC, users do not, by default, have write access to HKLM. Solve this by passing KEY_READ to the TRegistry constructor, or by using OpenKeyReadOnly rather than OpenKey.

The next most likely explanation is that you have the 64 bit Firebird server installed. But your 32 bit program reads from the 32 bit registry and so does not find the keys from the 64 bit Firebird. See Registry Redirector to learn more about the two different registry views. See Accessing an Alternate Registry View for details on how to read the 64 bit registry from a 32 bit process. Translated into Delphi, you would need to include KEY_WOW64_64KEY in the Access flags. Again, you can pass this flag to the TRegistry constructor which may be more convenient.

So, in summary, if you are looking for a 32 bit server, create the registry object like this

reg := TRegistry.Create(KEY_READ);

and if your Firebird server is 64 bit then use this

reg := TRegistry.Create(KEY_READ or KEY_WOW64_64KEY);
Sign up to request clarification or add additional context in comments.

Comments

2

Try replacing

TRegistry.Create

with

TRegistry.Create(KEY_READ)

2 Comments

+1 but the answer would be much improved with some explanation. Without that the person asking the Q learns nothing.
I didn't bother to mention UAC etc because the OP didn't say he was interested, nor did his code sample indicate, that he wanted to write to the registry. My sample demonstrates that you set whether or not you want to read/write, which should lead him in the right direction. But thank you for the +1 and the advice, much appreciated!
1

I think since you look at the registry from a 32 bit process on a 64 bit operating system, you are indeed looking at the "virtual" registry tree. In fact, an hidden "sub-redirection" is at work here.

See the registry changes in x64-based versions of Windows Server 2003 and in Windows XP Professional x64 Edition at Microsoft.

32-bit programs and 64-bit programs that are running on an x64-based version of Windows operate in different modes and use the following sections in the registry:

Native mode 64-bit programs run in Native mode and access keys and values that are stored in the following registry sub key:

HKEY_LOCAL_MACHINE\Software

32-bit programs run in WOW64 mode and access keys and values that are stored in the following registry sub key:

HKEY_LOCAL_MACHINE\Software\WOW6432node

(quoted from the Microsoft page above)

So if your firebird process installed the keys in 64 bit mode, they won't be visible from a 32 bit process. And you'll need a 32 bit FireBird client to let it work with Delphi (unless you are using Delphi XE2 64 Bit mode).

2 Comments

I don't really see how the last sentence is relevant here. The registry key is a server key. Where does the client enter affairs?
@DavidHeffernan I wanted to emphasizes that a 32 bit client library is needed with Delphi 32 bit applications, whenever the server is installed in 32 or 64 mode. If registry key is a 64 bit server key, the KEY_WOW64_64KEY flag is needed in this case - this is what you stated in your edited answer. I just wanted to explain why and how this virtual "key redirection" is made for 32 bit processes running in 64 bit windows.
0

Try to run your application as administrator. I think this will solve your problem.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.