Subject | Re: [firebird-support] Re: Get Installed Folder |
---|---|
Author | Josef Kokeš |
Post date | 2012-09-14T05:07:30Z |
On 13.9.2012 12:59, Allan_Fernandes wrote:
var
ServiceManager: SC_Handle;
P, Status: PEnumServiceStatus;
BufSize, BytesNeeded, ServicesReturned: DWORD;
ResumeHandle: {$IFDEF DELPHIXE2_UP} DWORD {$ELSE} THandle {$ENDIF} ;
OK: boolean;
begin
Result := False;
ServiceManager := OpenSCManager(nil, nil, SC_MANAGER_CONNECT or
SC_MANAGER_ENUMERATE_SERVICE);
if ServiceManager <> 0 then
try
ResumeHandle := 0;
BufSize := 65536;
GetMem(Status, BufSize);
repeat
OK := EnumServicesStatus(ServiceManager, SERVICE_WIN32,
SERVICE_ACTIVE or SERVICE_INACTIVE, Status^, BufSize, BytesNeeded,
ServicesReturned, ResumeHandle);
if not OK then
if GetLastError = ERROR_MORE_DATA then
begin
BufSize := BytesNeeded;
ReallocMem(Status, BufSize);
OK := EnumServicesStatus(ServiceManager, SERVICE_WIN32,
SERVICE_ACTIVE or SERVICE_INACTIVE, Status^, BufSize, BytesNeeded,
ServicesReturned, ResumeHandle);
end;
if OK then
begin
P := Status;
while ServicesReturned > 0 do
begin
List.Add(string(P^.lpServiceName));
Inc(P);
Dec(ServicesReturned);
end;
end;
until (not OK) or (ResumeHandle = 0);
Result := True;
finally
CloseServiceHandle(ServiceManager);
end;
end;
You can read more info from P^.
Josef
>function SvcList(List: TStringList): boolean;
> Can we also understand if Firebird is installed via this method.
> I too always install Firebird as Service.
> Could you also give me sample of Service Checking please.
var
ServiceManager: SC_Handle;
P, Status: PEnumServiceStatus;
BufSize, BytesNeeded, ServicesReturned: DWORD;
ResumeHandle: {$IFDEF DELPHIXE2_UP} DWORD {$ELSE} THandle {$ENDIF} ;
OK: boolean;
begin
Result := False;
ServiceManager := OpenSCManager(nil, nil, SC_MANAGER_CONNECT or
SC_MANAGER_ENUMERATE_SERVICE);
if ServiceManager <> 0 then
try
ResumeHandle := 0;
BufSize := 65536;
GetMem(Status, BufSize);
repeat
OK := EnumServicesStatus(ServiceManager, SERVICE_WIN32,
SERVICE_ACTIVE or SERVICE_INACTIVE, Status^, BufSize, BytesNeeded,
ServicesReturned, ResumeHandle);
if not OK then
if GetLastError = ERROR_MORE_DATA then
begin
BufSize := BytesNeeded;
ReallocMem(Status, BufSize);
OK := EnumServicesStatus(ServiceManager, SERVICE_WIN32,
SERVICE_ACTIVE or SERVICE_INACTIVE, Status^, BufSize, BytesNeeded,
ServicesReturned, ResumeHandle);
end;
if OK then
begin
P := Status;
while ServicesReturned > 0 do
begin
List.Add(string(P^.lpServiceName));
Inc(P);
Dec(ServicesReturned);
end;
end;
until (not OK) or (ResumeHandle = 0);
Result := True;
finally
CloseServiceHandle(ServiceManager);
end;
end;
You can read more info from P^.
Josef