// Das Beispiel
zeigt eine mögliche Anwendung von CreateProcess. var Form1: TForm1; implementation {$R *.DFM} var StartupInfo: TStartupInfo; ProcessInfo: TProcessInformation; prog, doc: string; procedure TForm1.FormCreate(Sender: TObject); begin Timer1.interval := 0; end; function start: boolean; begin StartupInfo.cb := Sizeof(StartupInfo); FillChar(StartupInfo, Sizeof(StartupInfo), #0); StartupInfo.dwFlags := STARTF_USESHOWWINDOW; StartupInfo.wShowWindow := SW_MAXIMIZE; result := CreateProcess(nil, pchar(prog + #32 + doc), nil, nil, false, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo); end; procedure TForm1.Button1Click(Sender: TObject); begin prog := 'NOTEPAD.EXE'; doc := 'C:\TEST.TXT'; if not fileexists(doc) then begin application.messagebox(pchar('Datei "' + doc + '" nicht gefunden !'), 'FEHLER', 16); exit; end; if not start then showmessage(SysErrorMessage(getlasterror)) else begin showWindow(application.handle, sw_hide); visible := false; Timer1.interval := 10000; repeat Application.ProcessMessages; // hier können bei Bedarf weitere Dinge // passieren, während der andere Prozess läuft until (WaitforSingleObject(ProcessInfo.hProcess, 0) <> WAIT_TIMEOUT) or (application.terminated); CloseHandle(ProcessInfo.hThread); CloseHandle(ProcessInfo.hProcess); Timer1.interval := 0; if application.terminated then exit; visible := true; showWindow(application.handle, sw_shownormal); end; end; procedure TForm1.Timer1Timer(Sender: TObject); begin Timer1.interval := 0; if ProcessInfo.hProcess > 0 then terminateprocess(ProcessInfo.hProcess, 0); end; |