Autor Beitrag
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mi 03.09.03 16:19 
Möchte man ein Programm starten und darauf warten bis dieses Programm beendet ist muss man das Programm mit CreateProcess starten und mit WaitForSingleObject auf das Beenden warten.

Hier eine fertige Funktion:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
Procedure RunProcessAndWait (aFilename: String); 
Var 
  StartupInfo : TStartupInfo; 
  ProcessInfo : TProcessInformation; 
  Result: Boolean; 
Begin 
  FillChar (StartupInfo, SizeOf (TStartupInfo), 0); 
  StartupInfo.cb := Sizeof (TStartupInfo); 

  StartupInfo.dwFlags := STARTF_USESHOWWINDOW OR STARTF_USEPOSITION OR STARTF_USESIZE ; 
  StartupInfo.wShowWindow := SW_SHOWDEFAULT; 

  Result := CreateProcess ( 
      nil
      pChar (aFilename), 
      nil
      nil
      False, 
      NORMAL_PRIORITY_CLASS,  
      nil
      nil
      StartupInfo, 
      ProcessInfo 
    ); 
    
  If Result then 
    WaitForSingleObject (ProcessInfo.hProcess, INFINITE); 

  if ProcessInfo.hProcess <> 0 then  
    CloseHandle (ProcessInfo.hProcess); 
End;

Für diesen Beitrag haben gedankt: hjl