How to shutdown IBServer programmattically

Abstract: How to shutdown IBServer programmattically

Sometimes during an embedded installation of InterBase it is neccessary to add licenses. IBServer only reads from the ib_license.dat when IBserver is started. Consequently IBServer needs to be shutdown and restarted after any licenses are added.

If interbase is running as a service the code to stop and start the server would be similiar to this(C Code):


SC_HANDLE service;
if(!(service = OpenService(manager, "InterBaseGuardian",
           SERVICE_START|SERVICE_STOP)))
     return1;
if (!ControlService(service, SERVICE_CONTROL_STOP, NULL))
{
       CLoseServiceHandle(service);
       return 1;

}
if (!StartService(service,0,NULL))
{

     CloseServiceHandle(service);
     return 1;

}
CloseServiceHandle(service);
return 0;

CloseServiceHandle(service);
return 0;
If InterBase is running as an application the code would be more similiar to this(PASCAL):

function ShutdownApp: boolean;
var
hTmpWnd: HWND;
begin
result := false;
hTmpWnd := FindWindow('IB_Guard', 'InterBase Guardian');
if not (hTmpWnd = 0) then
begin
PostMessage(hTmpWnd, WM_COMMAND, WPARAM(IDM_SHUTDOWN), 0);
result := true;
end;
end;