Dalei hat eigentlich schon alles gesagt.
Ansonsten probiere mal das hier:
Delphi-Quellcode:
function TFrmManage.ServiceGetStatus(sService: String): Boolean;
var
SCManager, SCService: SC_HANDLE;
ServiceStatus: TServiceStatus;
begin
Result:= false;
SCManager := OpenSCManager(nil, nil, SC_MANAGER_CONNECT);
if SCManager = 0 then
begin
ShowMessage('Exit 1');
Exit;
end;
try
SCService := OpenService(SCManager, PChar(sService), SERVICE_START or SERVICE_STOP or SERVICE_QUERY_STATUS);
if SCService = 0 then
begin
ShowMessage('Exit 2 - Endlich, nun weiß ich, warum es scheitert:' +
sLineBreak +
SysErrorMessage(GetLastError));
Exit;
end;
try
ZeroMemory(@ServiceStatus, SizeOf(ServiceStatus));
QueryServiceStatus(SCService, ServiceStatus);
Result:= ServiceStatus.dwCurrentState = SERVICE_RUNNING;
ShowMessage(BoolToStr(Result, True));
finally
CloseServiceHandle(SCService);
end;
finally
CloseServiceHandle(SCManager);
end;
end;
Wenn dir dann ein fröhliches "Zugriff verweigert" entgegenschlägt, dann machst du nur
SCService := OpenService(SCManager, PChar(sService), SERVICE_QUERY_STATUS);