Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros temas > Trucos
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Los mejores trucos

 
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 08-06-2006
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Poder: 24
seoane Va por buen camino
Iniciar y parar un servicio

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;

procedure StartSrv(Nombre: String);
var
 ServiceControlManager: SC_HANDLE;
 Service: SC_HANDLE;
 ServiceStatus: SERVICE_STATUS;
 Argv: PChar;
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_RUNNING  then
        begin
          Argv:= nil;
          StartService(Service,0,Argv);
        end;
      end;
      CloseServiceHandle(Service);
    end;
    CloseServiceHandle(ServiceControlManager);
  end;
end;

Ejemplo de uso:
Código Delphi [-]
  StartSrv('NombreDelServicio');
  StopService('NombreDelServicio');
Responder Con Cita
 



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro


La franja horaria es GMT +2. Ahora son las 16:41:04.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi