Subject | Re: How can I automatically start Interbase when my IBO App runs? |
---|---|
Author | gsbrown@GerBreOwn.com |
Post date | 2001-09-13T19:52:44Z |
--- In IBObjects@y..., "Warren Postma" <warren-postma@h...> wrote:
Below is the code that I use to start IB if it is not running:
Procedure TDO_DM.DataModuleCreate(Sender: TObject);
Var
lRegistry: TRegistry;
i: Integer;
fDB, fHlp, lEXEName: String;
Begin
If Not IsIBRunning Then
Begin
StartServer;
End;
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;
I found this code somewhere awhile ago so I can't take credit for it.
Hope you find it useful. I also have the code somewhere to start the
IBGuardian if you would like to see that also.
Gerald S. Brown
> How can I get Interbase, if not already running, to startautomatically, when
> my IBO application starts up.Warren,
> (Currently using IBO 3.6)
>
Below is the code that I use to start IB if it is not running:
Procedure TDO_DM.DataModuleCreate(Sender: TObject);
Var
lRegistry: TRegistry;
i: Integer;
fDB, fHlp, lEXEName: String;
Begin
If Not IsIBRunning Then
Begin
StartServer;
End;
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;
I found this code somewhere awhile ago so I can't take credit for it.
Hope you find it useful. I also have the code somewhere to start the
IBGuardian if you would like to see that also.
Gerald S. Brown