Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Ejecutar una aplicación y, opcionalmente, esperar a su término (https://www.clubdelphi.com/foros/showthread.php?t=80428)

dec 07-06-2006 21:29:00

Ejecutar una aplicación y, opcionalmente, esperar a su término
 
Con el siguiente procedimiento podemos ejecutar una determinada aplicación y, opcionalmente, esperar a que la misma termine para luego retomar el control desde nuestro programa:

Código Delphi [-]
uses
  Forms, ShellApi;

procedure EjecutarExe(const ruta,
  args: string; esperar: boolean);
var
  salida: DWord;
  PSEI: PShellExecuteInfo;
  SEI: TShellExecuteInfo;
begin
  if not FileExists(ruta)
    then Exit;
  with SEI do begin
    hInstApp := 0;
    lpVerb := nil;
    lpDirectory := nil;
    nShow := SW_NORMAL;
    cbSize := SizeOf(SEI);
    lpFile := PChar(ruta);
    wnd := GetDesktopWindow;
    lpParameters := Pchar(args+#0);
    fMask := SEE_MASK_NOCLOSEPROCESS;
  end;
  PSEI:= @SEI;
  ShellExecuteEx(PSEI);
  if not esperar then Exit;
  repeat
    salida := WaitForSingleObject(
      SEI.hProcess, 500);
    Application.ProcessMessages;
  until (salida <> WAIT_TIMEOUT);
end;

alapaco 08-06-2006 22:27:07

No funciona muy bien este truco al menos en mi pc.
Tengo Windows XP y lo que ocurre es que puedo seguir usando mi aplicación a pesar de que el exe que llamé con EjecutarExe esté corriendo.
De mas está decir que pasé True como 3er parámetro de ese procedimiento.

lacovera 09-05-2007 11:01:58

A mi me funciona muy bien, llamo al procedimiento así
ejecutarExe('C:\ejecutable.exe',parametro,true);


La franja horaria es GMT +2. Ahora son las 14:39:57.

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