Ver Mensaje Individual
  #2  
Antiguo 02-06-2017
Avatar de Soa Pelaez
Soa Pelaez Soa Pelaez is offline
Miembro
 
Registrado: nov 2015
Posts: 133
Reputación: 9
Soa Pelaez Va por buen camino
Como saber el estado de un servicio en una IP REMOTA

Buenas tardes.

Hay alguna manera de saber si un servicio esta iniciado en una IP Remota a la cual debo conectarme pero solo si el servicio está iniciado, algo que sea rápido de comprobar y mi aplicación no demore tanto en abrir
Porque actualmente tengo un código que lo verifica pero se demora 30 segundos en saber si está iniciado y es demasiada espera para un usuario iniciar una aplicación.

Código Delphi [-]
// 26/02/2016 Verifica el estado del servicio, si esta ensendido, apagado, sin instalar, instalado ...
//sMachine --> IP Donde se verifica el servicio
//sService --> Nombre del servicio
//Si lo que retorna es diferente de 4 es porque el servicio no está corriendo
//Posibles resultados.
{******************************************}
{*** Parameters: ***}
{*** sService: specifies the name of the service to open
{*** sMachine: specifies the name of the target computer
{*** ***}
{*** Return Values: ***}
{*** -1 = Error opening service ***}
{*** 1 = SERVICE_STOPPED ***}
{*** 2 = SERVICE_START_PENDING ***}
{*** 3 = SERVICE_STOP_PENDING ***}
{*** 4 = SERVICE_RUNNING ***}
{*** 5 = SERVICE_CONTINUE_PENDING ***}
{*** 6 = SERVICE_PAUSE_PENDING ***}
{*** 7 = SERVICE_PAUSED ***}
{******************************************}
function ServiceGetStatus(sMachine, sService: PChar): DWORD;
var
SCManHandle, SvcHandle: SC_Handle;
SS: TServiceStatus;
dwStat: DWORD;
begin
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;

Gracias.
Responder Con Cita