0
Goes below:
function TfPrincipal.ServicoExiste(maquina, servico : PChar) : Boolean;
var
SCManHandle, Svchandle : SC_HANDLE;
{Nome do computador onde esta localizado o serviço}
sComputerNameEx : string;
chrComputerName : array[0..255] of char;
cSize : Cardinal;
begin
{Verifica se nome do computador foi declarado}
if (maquina = '') then
begin
{Caso não tenha sido declarado captura o nome do computador local}
FillChar(chrComputerName, SizeOf(chrComputerName), #0);
GetComputerName(chrComputerName, cSize);
sComputerNameEx:=chrComputerName;
end
else
sComputerNameEx := maquina;
//ShowMessage(sComputerNameEx);
SCManHandle := OpenSCManager(PChar(sComputerNameEx), nil, SC_MANAGER_CONNECT);
if (SCManHandle > 0) then
begin
Svchandle := OpenService(SCManHandle, PChar(trim(servico)), SERVICE_QUERY_STATUS);
//ShowMessage(Svchandle.ToString);
if (Svchandle <> 0) then
begin
result := true;
//ShowMessage('tem');
CloseServiceHandle(Svchandle);
end
else
begin
result := false;
//ShowMessage('n tem');
CloseServiceHandle(SCManHandle);
end;
end;
end;
Either it doesn’t work, or I can’t make it work, the problem is it doesn’t come back true
even if the service name is correct and installed.
gives a Break nos 2 result and rotates the application and where it stops 1º. Apparently this normal!
– Junior Moreira
the problem is that in the second Handle it always returns 0;
– Ramon Ruan
Svchandle := Openservice(Scmanhandle, Pchar(Trim(servico)), SERVICE_QUERY_STATUS); ?
– Junior Moreira
exactly. that’s what returns 0.
– Ramon Ruan
I’ll post a response to how I’m using and running!
– Junior Moreira
òtimo!!! thank you very much!
– Ramon Ruan