Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to read win registry - firebird key using delphi

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;
like image 376
Sammy Davis Avatar asked Jan 18 '23 19:01

Sammy Davis


1 Answers

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);
like image 112
David Heffernan Avatar answered Jan 31 '23 21:01

David Heffernan