Subject Re: [IBO] Start Interbase when my IBO App runs?
Author Gordon Hamm
Here is a code snippet to check for the existance of a service and start it
if nessary..

------8<------- Initialization of some needed vars --------8<--------

schSCManager := OpenSCManager(nil,nil,SC_MANAGER_ALL_ACCESS);
if schSCManager<=0 then
begin
MessageDlg('''' + SERVICEDISPLAYNAME + ''' is not
installed.',mtError,[mbOk],0);
Application.Terminate;
end;

schService := OpenService(schSCManager, SERVICENAME, SERVICE_ALL_ACCESS);
if schService<=0 then
begin
MessageDlg('''' + SERVICEDISPLAYNAME + ''' can not
open.',mtError,[mbOk],0);
Application.Terminate;
end;
------8<---------------------------------------------------8<--------

------8<-------- The way to get service status ------------8<--------
procedure TForm1234.GetServiceInfo;
begin
if QueryServiceStatus(schService, ssStatus) then
begin
case ssStatus.dwCurrentState of
SERVICE_STOPPED:
lblStatus.Caption := 'The service is not running.';
SERVICE_START_PENDING:
lblStatus.Caption := 'The service is starting.';
SERVICE_STOP_PENDING:
lblStatus.Caption := 'The service is stopping.';
SERVICE_RUNNING:
lblStatus.Caption := 'The service is running.';
SERVICE_CONTINUE_PENDING:
lblStatus.Caption := 'The service continue is pending.';
SERVICE_PAUSE_PENDING:
lblStatus.Caption := 'The service pause is pending.';
SERVICE_PAUSED:
lblStatus.Caption := 'The service is paused.';
else
lblStatus.Caption := '---';
end;
end else
lblStatus.Caption := '---';
end;

------8<---------------------------------------------------8<--------

------8<----------- Starting the service... ---------------8<--------

procedure TForm1234.btnStartServiceClick(Sender: TObject);
var
argv: PChar;
begin
if StartService(schService, 0, argv) then
begin
lblStatus.Caption := 'Starting service ';
lblStatus.Update;
Screen.Cursor := crHourglass;
try
repeat
Sleep(500);
QueryServiceStatus(schService,ssStatus);
lblStatus.Caption := lblStatus.Caption + '.';
lblStatus.Update;
until ssStatus.dwCurrentState<>SERVICE_START_PENDING;
finally
Screen.Cursor := crDefault;
end;

if ssStatus.dwCurrentState<>SERVICE_RUNNING then
MessageDlg('Could not start service.', mtError, [mbOk], 0);
end else
MessageDlg('Could not start service.', mtError, [mbOk], 0);
end;

------8<---------------------------------------------------8<--------

------8<----------- Stopping the service... ---------------8<--------

procedure TForm1234.btnStopServiceClick(Sender: TObject);
begin
if ControlService(schService, SERVICE_CONTROL_STOP, ssStatus) then
begin
lblStatus.Caption := 'Stopping service ';
lblStatus.Update;
Screen.Cursor := crHourglass;
try
repeat
Sleep(500);
QueryServiceStatus(schService,ssStatus);
lblStatus.Caption := lblStatus.Caption + '.';
lblStatus.Update;
until ssStatus.dwCurrentState<>SERVICE_STOP_PENDING;
finally
Screen.Cursor := crDefault;
end;

if ssStatus.dwCurrentState<>SERVICE_STOPPED then
MessageDlg('Could not stop service.', mtError, [mbOk], 0);
end else
MessageDlg('Could not start service.', mtError, [mbOk], 0);
end;
------8<---------------------------------------------------8<--------


----------------------------------------------------------------------------
----


Gordon Hamm
Voice Data Systems Inc.
435-635-7464



----- Original Message -----
From: "delphiman" <delphiman@...>
To: <IBObjects@yahoogroups.com>
Sent: Thursday, September 13, 2001 4:42 PM
Subject: [IBO] Start Interbase when my IBO App runs?


> I didn't know this either!!
>
> For Heaven's sake - this is surely a pretty obvious requirement - so
let's have it!!
> I have in excess of 1200 users who will need it. (See other e-mail,)
>
> delphiman@...
> Mobile: (Australia) 0407-007-159
> Phone: ( Australia (02) 6041-1036)
> ICQ 63345769
>
>
> ----- Original Message -----
> From: Jason Wharton
> To: IBObjects@yahoogroups.com
> Sent: Friday, September 14, 2001 3:34 AM
> Subject: Re: [IBO] How can I automatically start Interbase when my IBO
App runs?
>
>
> > How can I get Interbase, if not already running, to start
automatically,
> > when my IBO application starts up.
> > (Currently using IBO 3.6)
>
> Not sure, I've never dealt with this issue.
>
> Jason Wharton
> CPS - Mesa AZ
> http://www.ibobjects.com
>
>
>
>
>
> Your use of Yahoo! Groups is subject to
http://docs.yahoo.com/info/terms/
>
>
>
>
> [Non-text portions of this message have been removed]
>
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>