Fórum Como identificar se um serviço esta instalado? #368616
20/02/2009
0
Atenciosamente,
Pestana.
Pestana_
Curtir tópico
+ 0Post mais votado
21/02/2009
Olha a assinatura desta API
function EnumServicesStatus(hSCManager: SC_HANDLE; dwServiceType, dwServiceState: DWORD; var lpServices: TEnumServiceStatus; cbBufSize: DWORD; var pcbBytesNeeded, lpServicesReturned, lpResumeHandle: DWORD): BOOL; stdcall;
esta definida na Unit WinSvc
Declare essa Unit na seccão uses da Interface
e defina a função
function VerificarService( nService,sMachine : string; dwServiceType,dwServiceState : DWord): boolean;
[b:ff36148612]Note que eu mantive o mesmo nome dos parâmetros da Api Original[/b:ff36148612]
function TForm1.VerificarService(nService, sMachine: string; dwServiceType, dwServiceState: DWord): boolean; const cnMaxServices = 4096; type TSvcA = array[0..cnMaxServices] of TEnumServiceStatus; PSvcA = ^TSvcA; var i : integer; hSCManager:SC_Handle; pcbBytesNeeded, lpServicesReturned, lpResumeHandle: DWord; lpServices: PSvcA; begin try Result := false; hSCManager := OpenSCManager( PChar(sMachine), Nil, SC_MANAGER_ALL_ACCESS); if(hSCManager > 0)then begin lpResumeHandle := 0; New(lpServices); EnumServicesStatus( hSCManager, dwServiceType, dwServiceState, lpServices^[0], SizeOf(lpServices^), pcbBytesNeeded, lpServicesReturned, lpResumeHandle); for i := 0 to lpServicesReturned-1 do if Uppercase(StrPas(lpServices^[i].lpServiceName)) = Uppercase(nService) Then begin Result := true; Break; end; end; finally Dispose(lpServices); CloseServiceHandle(hSCManager); end; end;
Para Chamar a função :
procedure TForm1.Button1Click(Sender: TObject); begin if VerificarService(edit1.text, ´´, SERVICE_WIN32, SERVICE_STATE_ALL) then showmessage(´instalado´) end;
[b:ff36148612]cloque no Edit o Nome do Serviço...[/b:ff36148612]
Marco Salles
Gostei + 1
Mais Posts
24/02/2009
Pestana_
Obrigado por responder a minha dúvida, eu não tenho como olhar isso agora, mas assim que eu testar eu vou informar o resultado.
Atenciosamente,
Pestana.
Gostei + 0
27/02/2009
Pestana_
Abraços.
Gostei + 0
28/02/2009
Marco Salles
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)