Ver Mensaje Individual
  #1  
Antiguo 07-03-2014
cmfab cmfab is offline
Miembro
 
Registrado: jun 2010
Posts: 419
Reputación: 14
cmfab Va por buen camino
Detener un servicio Windows

Hola a todos, en encontrado este procedimiento para detener un servicio de Windwes

Código Delphi [-]
uses WinSvc;

procedure StopService(Nombre: String);
var
 ServiceControlManager: SC_HANDLE;
 Service: SC_HANDLE;
 ServiceStatus: SERVICE_STATUS;
begin
  ServiceControlManager:= OpenSCManager(nil, nil, SC_MANAGER_CONNECT);
  if ServiceControlManager <> 0 then
  begin
    Service:= OpenService(ServiceControlManager,PChar(Nombre),SERVICE_ALL_ACCESS);
    if Service <> 0 then
    begin
      if QueryServiceStatus(Service, ServiceStatus) then
      begin
        if ServiceStatus.dwCurrentState <> SERVICE_STOPPED  then
          ControlService(Service, SERVICE_CONTROL_STOP, ServiceStatus);
      end;
      CloseServiceHandle(Service);
    end;
    CloseServiceHandle(ServiceControlManager);
  end;
end;

ejemplo de llamada
Código Delphi [-]
StopService('Themes');
lo he probado en Windows 7 y 2008 Server y no me funciona, el revicio esta iniciado y nunca se detiene
Gracias por sus comentarios
Responder Con Cita