function FComputername:
String;
var
CompName:
Array [0 .. 256]
of char;
size: DWORD;
begin
size := 256;
GetComputerName(Compname, size);
Result := CompName;
end;
{}
function ServiceGetStatus(sMachine, sService: PChar): DWORD;
var
SCManHandle, SvcHandle: SC_Handle;
SS: TServiceStatus;
dwStat: DWORD;
begin
sService := [b]'
SQLANYs_sql'+ FComputername;[/b]
dwStat := 0;
// Open service manager handle.
SCManHandle := OpenSCManager(sMachine,
nil, SC_MANAGER_CONNECT);
if (SCManHandle > 0)
then
begin
SvcHandle := OpenService(SCManHandle, sService, SERVICE_QUERY_STATUS);
// if Service installed
if (SvcHandle > 0)
then
begin
// SS structure holds the service status (TServiceStatus);
if (QueryServiceStatus(SvcHandle, SS))
then
dwStat := ss.dwCurrentState;
CloseServiceHandle(SvcHandle);
end;
CloseServiceHandle(SCManHandle);
end;
Result := dwStat;
end;
function ServiceRunning(sMachine, sService: PChar): Boolean;
begin
Result := SERVICE_RUNNING = ServiceGetStatus(sMachine, sService);
end;