If there a way to determine if Interbase Server is running or not?

delphi-db@elists.org delphi-db@elists.org
Fri, 12 Oct 2001 07:24:59 -0400


Below is the code that I use to see if IB is running and if it is not how
to start it if it is installed.

Procedure TDO_DM.DataModuleCreate(Sender: TObject);
Var
  lRegistry: TRegistry;
  i: Integer;
  fDB, fHlp, lEXEName: String;
Begin
  //Check to see if InterBase is running and start if not.
  fHlp := ChangeFileExt(Application.EXEName, '.HLP');
  Application.HelpFile := fHlp;
  fDB := ChangeFileExt(Application.EXEName, '.GDB');
  IB_DBDO.Database := fDB;
  IB_DBDO.DatabaseName := fDB;
  IBDatabase.DatabaseName := fDB;
  If Not IsIBRunning Then
    Begin
      StartServer;
    End;
  lRegistry := TRegistry.Create;
  lRegistry.RootKey := HKEY_LOCAL_MACHINE;
  lRegistry.OpenKey('Software\Borland\InterBase\CurrentVersion', False);
  lEXEName := Format('%s%s', [lRegistry.ReadString('RootDirectory'),
'isc4.gdb']);
  IB_DBGDB.Activate;
End;

Function TDO_DM.IsIBRunning(): boolean;
Begin
  If GetWindow(GetDesktopWindow, GW_HWNDNEXT) = FindWindow('IB_Server',
    'InterBase Server') Then
    result := False
  Else
    result := True;
End;

{****************************************************************
*
*  S t a r t S e r v e r ( )
*
****************************************************************
*  Author: The Client Server Factory Inc.
*  Date:   March 1, 1999
*
*  Input:
*
*  Return:
*
*  Description:
*
*****************************************************************
* Revisions:
*
*****************************************************************}

Function TDO_DM.StartServer(): boolean;
Var
  lRegistry: TRegistry;
  lStartUpInfo: STARTUPINFO;
  lSecurityAttr: SECURITY_ATTRIBUTES;
  lProcessInfo: PROCESS_INFORMATION;
  lEXEName: String;
  lArray: Array[0..255] Of char;
Begin
  result := False;
  lRegistry := TRegistry.Create;
  Try
    Screen.Cursor := crHourglass;
    lRegistry.RootKey := HKEY_LOCAL_MACHINE;
    If Not lRegistry.OpenKey('Software\Borland\InterBase\CurrentVersion',
False) Then
      ShowMessage('InterBase server is not installed on your system.')
    Else
      lEXEName := Format('%s%s -a', [lRegistry.ReadString('RootDirectory'),
        'bin\ibserver.exe']);
    ZeroMemory(@lStartUpInfo, SizeOf(lStartUpInfo));
    lStartUpInfo.cb := SizeOf(lStartUpInfo);
    lSecurityAttr.nLength := SizeOf(lSecurityAttr);
    lSecurityAttr.lpSecurityDescriptor := Nil;
    lSecurityAttr.bInheritHandle := True;
    If CreateProcess(Nil, StrPCopy(lArray, lEXEName), @lSecurityAttr, Nil,
      False, 0, Nil,
      Nil, lStartUpInfo, lProcessInfo) <> Null Then
      result := True
    Else
      ShowMessage('The server could not be started.')
  Finally
    lRegistry.Free;
    Screen.Cursor := crDefault;
  End;
End;

HTH;

Gerald S. Brown
Lockheed Martin
contractor to EPA



                                                                                                                      
                    M Tuttle                                                                                          
                    <miket@softtechk        To:     delphi-db@elists.org                                              
                    s.com>                  cc:                                                                       
                    Sent by:                Subject:     If there a way to determine if Interbase Server is running   
                    delphi-db-admin@        or not?                                                                   
                    elists.org                                                                                        
                                                                                                                      
                                                                                                                      
                    10/11/01 10:57                                                                                    
                    AM                                                                                                
                    Please respond                                                                                    
                    to delphi-db                                                                                      
                                                                                                                      
                                                                                                                      




Greetings All,

I need to figure out how to detect if Interbase Server is installed and
running and if not abort execution of my application.  As it is now if
interbase is not running the user receive several bad, very ugly error
messages before they finally get out.

1) How can I determine if Interbase Server is Installed?

2) How can I determine if it is running?

Thanks

Mike


_______________________________________________
Delphi-DB mailing list
Delphi-DB@elists.org
http://www.elists.org/mailman/listinfo/delphi-db