Subject | Re: How to check if Firebird is running ? |
---|---|
Author | ove.bjerregaard |
Post date | 2007-09-03T14:17:36Z |
--- In firebird-support@yahoogroups.com, "mariofb123" <mariofb123@...>
wrote:
wrote:
You can use this Delphi 7 code to check if Firebird is running.
First copy this function to your code (You need to include the unit
WinSvc):
function ServiceGetStatus(sMachine, sService: string ): DWord;
var
schm,
schs : SC_Handle;
ss : TServiceStatus;
dwStat : DWord;
begin
dwStat := 0;
schm := OpenSCManager(PChar(sMachine), nil, SC_MANAGER_CONNECT);
if (schm > 0) then begin
schs := OpenService(schm, PChar(sService), SERVICE_QUERY_STATUS);
if (schs > 0) then begin
if (QueryServiceStatus(schs, ss)) then begin
dwStat := ss.dwCurrentState;
end;
CloseServiceHandle(schs);
end;
CloseServiceHandle(schm);
end;
Result := dwStat;
end;
Then declare a boolean value FirebirdIsRunning and call the function
like this:
FirebirdIsRunning := (ServiceGetStatus('',
'FirebirdServerDefaultInstance') <> SERVICE_RUNNING);
You can also use this function to check any other state of the Firebird
Server besides SERVICE_RUNNING.
In order to stop the Firebird Services from running, you just need to
make a function to call the "..\Firebird_2_0\Bin\InstSvc.exe" somewhat
like this:
function StopFireBirdServer: Boolean;
function GetFireBirdFolder: string;
var
FBReg: TRegistry;
begin
Result := '';
FBReg := TRegistry.Create;
FBReg.RootKey := HKEY_LOCAL_MACHINE;
if FBReg.OpenKey('Software\Firebird Project\Firebird
Server\Instances', False) then
begin
try
Result := FBReg.ReadString('DefaultInstance');
Result := IncludeTrailingPathDelimiter(Result);
except
end;
end;
FBReg.Free;
end;
begin
Result := (WinExec(PChar(GetFireBirdFolder + 'bin\instsvc.exe stop'),
SW_HIDE) > 31);
end;
I have built a small library of functions to control the Firebird
Services, so if you have any further questions, just let me know.
[Non-text portions of this message have been removed]
wrote:
>--- In firebird-support@yahoogroups.com, "mariofb123" <mariofb123@...>
> I am using Firebird 2.0.1 with Delphi 7 application.
> I need to check from within the application code if Firebird server is
> currently running. How to do that ?
>
> Also, a related question:
> How to stop the Firebird running from within the Delphi application
> (programmatically) ? What run commands need to be issued?
>
> Regards,
> Mario
>
wrote:
>Hi Mario
> I am using Firebird 2.0.1 with Delphi 7 application.
> I need to check from within the application code if Firebird server is
> currently running. How to do that ?
>
> Also, a related question:
> How to stop the Firebird running from within the Delphi application
> (programmatically) ? What run commands need to be issued?
>
> Regards,
> Mario
>
You can use this Delphi 7 code to check if Firebird is running.
First copy this function to your code (You need to include the unit
WinSvc):
function ServiceGetStatus(sMachine, sService: string ): DWord;
var
schm,
schs : SC_Handle;
ss : TServiceStatus;
dwStat : DWord;
begin
dwStat := 0;
schm := OpenSCManager(PChar(sMachine), nil, SC_MANAGER_CONNECT);
if (schm > 0) then begin
schs := OpenService(schm, PChar(sService), SERVICE_QUERY_STATUS);
if (schs > 0) then begin
if (QueryServiceStatus(schs, ss)) then begin
dwStat := ss.dwCurrentState;
end;
CloseServiceHandle(schs);
end;
CloseServiceHandle(schm);
end;
Result := dwStat;
end;
Then declare a boolean value FirebirdIsRunning and call the function
like this:
FirebirdIsRunning := (ServiceGetStatus('',
'FirebirdServerDefaultInstance') <> SERVICE_RUNNING);
You can also use this function to check any other state of the Firebird
Server besides SERVICE_RUNNING.
In order to stop the Firebird Services from running, you just need to
make a function to call the "..\Firebird_2_0\Bin\InstSvc.exe" somewhat
like this:
function StopFireBirdServer: Boolean;
function GetFireBirdFolder: string;
var
FBReg: TRegistry;
begin
Result := '';
FBReg := TRegistry.Create;
FBReg.RootKey := HKEY_LOCAL_MACHINE;
if FBReg.OpenKey('Software\Firebird Project\Firebird
Server\Instances', False) then
begin
try
Result := FBReg.ReadString('DefaultInstance');
Result := IncludeTrailingPathDelimiter(Result);
except
end;
end;
FBReg.Free;
end;
begin
Result := (WinExec(PChar(GetFireBirdFolder + 'bin\instsvc.exe stop'),
SW_HIDE) > 31);
end;
I have built a small library of functions to control the Firebird
Services, so if you have any further questions, just let me know.
[Non-text portions of this message have been removed]