Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   vez con ShellExecuteEx (https://www.clubdelphi.com/foros/showthread.php?t=76840)

Anel Hernandez 30-11-2011 13:40:09

vez con ShellExecuteEx
 
Hola,

Estoy mandando a ejecutar un programa con varios parametros de forma consecutiva de esta forma:
Código Delphi [-]
var
  Info:TShellExecuteInfo;
begin
  with Info do begin
   cbSize := SizeOf(ShellExecuteInfo);
   fMask := SEE_MASK_NOCLOSEPROCESS;
   Wnd := Handle;
   lpVerb := 'open';
   lpFile := PChar('C:\Archivos de programa\programa\programa.exe');
   lpParameters := PChar(Listbox1.items.Strings[i-1]);
   lpDirectory := PChar('D:\');
   nShow := SW_SHOW;
  end;
  Mandar a ejecutar varios programas a la(@INFO);

Pero necesito mandar N a la vez y luego cuando termine 1 mandar a ejecutar el siguiente de la lista de modo que siempre tenga en ejecucion N hasta que se termine la lista y vayan quedando N, N-1, N-2,..., 3,2,1. y finaliza.

como pudiera organizar esto?

gracias

Neftali [Germán.Estévez] 30-11-2011 16:23:48

Tal vez utilizando Threads.
En ese caso sólo tienes que controlar en número de threads abiertos.

Anel Hernandez 30-11-2011 17:08:59

Parece ke cometi un error de copiado en el mensaje original. Rectifico:
Código Delphi [-]
var
 i:integer;
 Info:TShellExecuteInfo;
begin
 for i:=1 to stringgrid6.RowCount-1 do begin
   with Info do begin
    cbSize := SizeOf(ShellExecuteInfo);
    fMask := SEE_MASK_NOCLOSEPROCESS;
    Wnd := Handle;
    lpVerb := 'open';
    lpFile := PChar(DirT+'Calmetl.exe');
    lpParameters := PChar(checklistbox1.items.Strings[i-1]);
    lpDirectory := PChar(dirT);
    nShow := SW_SHOW;
   end;
   ShellExecuteEx(@INFO);
   Repeat
    Application.ProcessMessages;
   until WaitForSingleObject( Info.hProcess,500)<> WAIT_TIMEOUT;

end;


no hay manera, por esta via, de controlar/gestionar cuantos programas hay corriendo?

duilioisola 30-11-2011 18:41:37

Mira esto:

Código Delphi [-]
{Execute a program and wait until it has finished. The following example uses the ShellExecuteEx API function.}

 // Execute the Windows Calculator and pop up
 // a message when the Calc is terminated.
 uses ShellApi;
 ...
 var
    SEInfo: TShellExecuteInfo;
    ExitCode: DWORD;
    ExecuteFile, ParamString, StartInString: string;
 begin
    ExecuteFile:='c:\Windows\Calc.exe';
 
    FillChar(SEInfo, SizeOf(SEInfo), 0) ;
    SEInfo.cbSize := SizeOf(TShellExecuteInfo) ;
    with SEInfo do begin
      fMask := SEE_MASK_NOCLOSEPROCESS;
      Wnd := Application.Handle;
      lpFile := PChar(ExecuteFile) ;
 {
 ParamString can contain the
 application parameters.
 }
 // lpParameters := PChar(ParamString) ;
 {
 StartInString specifies the
 name of the working directory.
 If ommited, the current directory is used.
 }
 // lpDirectory := PChar(StartInString) ;
      nShow := SW_SHOWNORMAL;
    end;
    if ShellExecuteEx(@SEInfo) then begin
      repeat
        Application.ProcessMessages;
        GetExitCodeProcess(SEInfo.hProcess, ExitCode) ;
      until (ExitCode <> STILL_ACTIVE) or
    Application.Terminated;
      ShowMessage('Calculator terminated') ;
    end
    else ShowMessage('Error starting Calc!') ;
 end;

Anel Hernandez 17-01-2012 20:00:27

Hola,

resolvi haciendo un ciclo que comprueba todos los procesos lanzadosÑ
Código Delphi [-]
GetExitcodeProcess(h[k],ExitCode);
if exitCode<>STILL_ACTIVE then  begin

pudiera hacerse lo ke kiero con WaitForMultipleObjects()?????

gracias

Delfino 19-01-2012 15:58:43

Lo hago asi
Código Delphi [-]
function ExecWait(ExeFile, Params: string): Boolean;   //  Synchronous ShellExecute
  var SEInfo: TShellExecuteInfo;
      ExitCode: DWORD;
begin
  FillChar(SEInfo, SizeOf(SEInfo), 0) ;
  SEInfo.cbSize := SizeOf(TShellExecuteInfo) ;
  with SEInfo do
  begin
   fMask := SEE_MASK_NOCLOSEPROCESS;
   Wnd := Application.Handle;
   lpFile := PChar(ExeFile) ;
   lpParameters := PChar(Params) ;
   lpDirectory := 'C:\' ;
   nShow := SW_HIDE;
  end;
  if ShellExecuteEx(@SEInfo) then
  begin
   repeat
    Application.ProcessMessages;
    GetExitCodeProcess(SEInfo.hProcess, ExitCode) ;
   until (ExitCode <> STILL_ACTIVE) or (Application.Terminated);
   Result := True;
  end
  else
   Result := False;
end;


La franja horaria es GMT +2. Ahora son las 06:36:00.

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