Einzelnen Beitrag anzeigen

Benutzerbild von Der Jan
Der Jan

Registriert seit: 22. Dez 2005
289 Beiträge
 
Delphi XE7 Ultimate
 
#1

Createprocess und nicht warten

  Alt 7. Mai 2007, 12:06
Hallo,

ich habe ein Problem. Ich möchte aus einem Delphi-Programm ein Dos-Programm starten. Allerdings soll mein Programm nicht warten, tut es aber. Ich habe es zuerst mit der Jedi-Komponente jvCreateProcess versucht und dann mit der Funktion WinExecAndWait_32, die hier im Forum irgendwo vorgestellt wird (ja, ich hab die Suchfunktion benutzt )
Das Problem ist nun, daß mein Programm nach dem Starten des Dos-Programms nicht weiterläuft, sondern wartet, was es aber nicht soll.
Bei jvCreateProcess war WaitForTerminate ausgeschaltet und die Funktion WinExecAndWait_32 hab ich mit WinExecAndWait_32('bla.exe', 1, false) aufgerufen.
Wie kann man das bewerkstelligen? Ist hier CreateProcess vielleicht der falsche Weg?

Achso, der Vollständigkeit halber noch mal die Funktion:
Delphi-Quellcode:
function WinExecAndWait32(FileName: string; Visibility: Integer; bWait: Boolean = False): Longword;
var { by Pat Ritchey } 
  zAppName: array[0..512] of Char;
  zCurDir: array[0..255] of Char;
  WorkDir: string;
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
begin
  StrPCopy(zAppName, FileName);
  GetDir(0, WorkDir);
  StrPCopy(zCurDir, WorkDir);
  FillChar(StartupInfo, SizeOf(StartupInfo), #0);
  StartupInfo.cb := SizeOf(StartupInfo);
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visibility;
  if not CreateProcess(nil,
    zAppName, // pointer to command line string
    nil, // pointer to process security attributes
    nil, // pointer to thread security attributes
    False, // handle inheritance flag
    CREATE_NEW_CONSOLE or // creation flags
    NORMAL_PRIORITY_CLASS,
    nil, //pointer to new environment block
    nil, // pointer to current directory name
    StartupInfo, // pointer to STARTUPINFO
    ProcessInfo) // pointer to PROCESS_INF
    then Result := WAIT_FAILED
  else
  begin
    if bWait then
      WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess, Result);
    CloseHandle(ProcessInfo.hProcess);
    CloseHandle(ProcessInfo.hThread);
  end;
end; { WinExecAndWait32 }
Gruß, Jan
  Mit Zitat antworten Zitat