Ver Mensaje Individual
  #11  
Antiguo 09-06-2015
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Reputación: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
cipce22,

Cita:
Empezado por cipce22
...necesito el nombre de los alias existentes para las bases de datos (Firebird) en mi servidor, se que se almacenan en el aliases.conf...estoy utilizando Windows 8 x64...


Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Registry;

type
  TForm1 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// Verifica si Windows es de 64 Bits
function CheckWOW64 : Boolean;
type
   TWOW64Process = function(Handle : THandle; var WOW64 : BOOL) : BOOL; Stdcall;

var
   Kernel32 : THandle;
   WOW64Process : TWOW64Process;
   WOW64 : BOOL;

begin

   Kernel32 := LoadLibrary('kernel32.dll');

   if (Kernel32 <> 0) then
   begin
      @WOW64Process := GetProcAddress(Kernel32, 'IsWow64Process');
      if (@WOW64Process <> nil) then
         if (WOW64Process(GetCurrentProcess, WOW64)) then
            Result := WOW64
         else
            Result := False;
   end;

   FreeLibrary(Kernel32);

end;

// Obtiene los Alias de FireBird de 32 y 64 Bits sobre Windows
procedure GetFireBirdAlias(Strings : TStrings);
const
   KEY_WOW64_64KEY = $0100; // Access a 64-bit key from either a 32-bit or 64-bit application
   KEY_WOW64_32KEY = $0200; // Access a 32-bit key from either a 32-bit or 64-bit application
   Instances = '\SOFTWARE\Firebird Project\Firebird Server\Instances';

var
   Path : String;
   i  : Integer;
   SL : TStringList;

begin

   if CheckWOW64 then
   begin

      with TRegistry.Create(KEY_READ or KEY_WOW64_64KEY) do
      try

         RootKey := HKEY_LOCAL_MACHINE;

         if OpenKey(Instances,False) then
         begin

            SL := TStringList.Create;
            Path := ReadString('DefaultInstance') + 'aliases.conf';
            SL.LoadFromFile(Path);

            for i := SL.Count-1 downto 0 do
               if Pos('#', Trim(SL[i])) = 1 then
                  SL.Delete(i);

            Strings.Text := Strings.Text + SL.Text;
            SL.Free;

         end;


      finally

         Free;

      end;

      with TRegistry.Create(KEY_READ or KEY_WOW64_32KEY) do
      try

         RootKey := HKEY_LOCAL_MACHINE;

         if OpenKey(Instances,False) then
         begin

            SL := TStringList.Create;
            Path := ReadString('DefaultInstance') + 'aliases.conf';
            SL.LoadFromFile(Path);

            for i := SL.Count-1 downto 0 do
               if Pos('#', Trim(SL[i])) = 1 then
                  SL.Delete(i);

            Strings.Text := Strings.Text + SL.Text;
            SL.Free;

         end;

      finally

         Free;

      end;

   end
   else
   begin
      with TRegistry.Create do
      try

         RootKey := HKEY_LOCAL_MACHINE;

         if OpenKey(Instances,False) then
         begin
            Path := ReadString('DefaultInstance') + 'aliases.conf';
            Strings.LoadFromFile(Path);
            for i := Strings.Count-1 downto 0 do
               if Pos('#', Trim(Strings[i])) = 1 then
                  Strings.Delete(i);
         end

      finally

         Free;

      end;


   end;

end;

// Carga los alias de Firebird de 32 y 64 bits
procedure TForm1.Button1Click(Sender: TObject);
begin
   with ListBox1 do
   begin
      Items.Clear;
      GetFirebirdAlias(Items);
   end;
end;

end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32 y x64, Permite obtener los Alias de Firebird de 32 y 64 bits en Windows x32 y x64, como se muestra en la siguientes imágenes:

Alias de Ejemplo en FireBird en Windows 7 Professional x32:



Alias de Ejemplo en FireBird en Windows 7 Professional x64:



Notas:

1- El código propuesto es una variación del sugerido en el Msg #9.

2- El código propuesto, permite listar los Alias de una instalación de Firebird de 32 o 64 bits en Windows x64, inclusive ambas en caso de que coexistan por alguna razón particular.

3- El código propuesto, permite listar los Alias de una instalación de Firebird de 32 bits en Windows x32.

Revisa esta información:
Espero sea útil

Nelson.
Responder Con Cita