Problem: I need to modify aliases.conf in firebird but.. as we know the user can install firebird anywhere he want. So I need to programmatically find out where the firebird was installed. I try to do that by registry but it's not good idea because withe almost every one new version of windows (2000, XP, VISTA, 7, 8 and 32 bit or 64 bit and may be 128 bit) the registry keys get change. I try also find out procedure for searching registry like simple text file but no result. I have try to find the "HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\SharedDLLs\aliases.conf" but it's not simple way. It's possible that the problem is not in registry function just in Lazarus but I do not know that. So, may be some one has any idea how to check if and where is installed firebird. Shortly say: I'm going to install my application with database file and have to have silently modify the aliases.conf.
1 Answer
You can find the installation location of Firebird by checking the registry key HKLM\Software\Firebird Project\Firebird Server\Instances and reading the DefaultInstance value.
The following code should do the trick :-
var
lReg : TRegistry;
lStr : String;
begin
lReg := TRegistry.Create;
Try
lReg.RootKey := HKEY_LOCAL_MACHINE;
If lReg.OpenKey('Software\Firebird Project\Firebird Server\Instances', False) Then
lStr := lReg.ReadString('DefaultInstance');
lReg.CloseKey;
ShowMessage(lStr);
Finally
FreeAndNil(lReg);
End;
9 Comments
Kazmirus
Andy_D I have use this function but is not work. function TfrMain.GetSubKeys(ARegStr: string; var SubKeys: TStringList): boolean; var Reg: TRegistry; begin SubKeys := nil; Reg := TRegistry.create; try if Reg.OpenKey(ARegStr, false) then begin SubKeys := TStringList.Create; Reg.GetKeyNames(SubKeys); Reg.CloseKey; end; finally Reg.free; end; Result := SubKeys <> nil; end;
Andy_D
What result do you get? Is Firebird installed on your PC Have you checked the registry values using RegEdit?
Andy_D
Your registry function doesn't work. I've updated my answer with a function that works perfectly on 3 machines I have at my disposal with Firebird installed on them.
Kazmirus
In regedt I do not have that key. I found just HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\SharedDLLs\aliases.conf but as you know an other computer with other stupid windows this key will not work. If I could search the key by using just part name of key for example just "aliases.conf" then would be great.
Kazmirus
Yes, yes I have installed Firebird. The result was Nil.
|
SharedDLLregistry entry. You shouldn't be "silently modifying" anything that concerns the user's database configuration, as you could break another (possibly critical) application that isn't yours.