I try to follow http://edn.embarcadero.com/article/28604 for restarting Interbase. Here is some code:
program IBRestart;
{$APPTYPE CONSOLE}
uses
SysUtils, winsvc;
var
vManager, vService: SC_Handle;
vtmp: TServiceStatus;
begin
vManager := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
if vManager > 0 then
begin
vService := OpenService(vManager, 'InterBaseGuardian', SERVICE_START or SERVICE_STOP);
if vService = 0 then // vService is always 0 here, why ?
CloseServiceHandle(vManager)
else
if ControlService(vService, SERVICE_CONTROL_STOP, vTmp) and
QueryServiceStatus(vService, vTmp) and
(vTmp.dwCurrentState = SERVICE_STOPPED) then
begin
WriteLn('Success');
end;
end;
end.
I notice that the service is listed as "InterBase 2009 Guardian gds_db" in the services dialog. I have tried different variants of this as argument to OpenService without success... Any hints ?
EDIT: net start list the service as InterBase 2009 Guardian gds_db and InterBase 2009 Server gds_db
RaiseLastOSError return this in both cases: Project IBRestart.exe raised exception class EOSError with message 'System Error. Code: 1060. The specified service does not exist as an installed service'.
So vService is always 0 in the code above. I even try to stop another service like Themes and it actually works. Can it be the spaces in the string that must be special handled ? I tried to close IIS Admin and it returned the same error message as Interbase do.