![]() |
Warten bis Anwendung/Prozess beendet wurde
Delphi-Quellcode:
Beispielaufruf:
uses
Tl32help; //[...] function GetProcID(const Filename: String): DWORD; var hProcSnap: THandle; pe32: TProcessEntry32; begin result := 0; hProcSnap := CreateToolHelp32SnapShot(TH32CS_SNAPPROCESS, 0); if hProcSnap <> INVALID_HANDLE_VALUE then begin pe32.dwSize := SizeOf(ProcessEntry32); if Process32First(hProcSnap, pe32) then begin while Process32Next(hProcSnap, pe32) do begin if pos(AnsiLowerCase(pe32.szExeFile), AnsiLowerCase(ExtractFilename(Filename))) > 0 then begin result := pe32.th32ProcessID; break; end; end; end; CloseHandle(hProcSnap); end; end; function WaitForApplication(EXEName : String): integer; var ExitCode: longword; PID: DWord; hProcess: THandle; begin result := -1; PID := GetProcID(extractfilename(EXEName)); if PID <> 0 then begin hProcess := OpenProcess(SYNCHRONIZE or PROCESS_QUERY_INFORMATION, False, PID); if hProcess <> 0 then begin while WaitForSingleObject(hProcess, 50) <> WAIT_OBJECT_0 do application.ProcessMessages; GetExitCodeProcess(hProcess, ExitCode); CloseHandle(hProcess); result := ExitCode; end end; end; procedure TForm1.Button1Click(Sender: TObject); var ExitCode: Integer; begin ExitCode := WaitForApplication('C:\Program Files\FreeMat3.6\Contents\bin\FreeMat.exe'); //könnte auch 'C:\1.exe' seien if ExitCode = -1 then showmessage('Prozess konnte nicht gefunden werden') else showmessage('Der Exitcode lautete: ' + inttostr(ExitCode)); end;
Delphi-Quellcode:
mfg smallsmoker
procedure TForm4.Button1Click(Sender: TObject);
var ExitCode: Integer; begin ExitCode := WaitForApplication('1.exe'); //könnte auch 'C:\1.exe' seien if ExitCode = -1 then showmessage('Prozess konnte nicht gefunden werden') else showmessage('Der Exitcode lautete: ' + inttostr(ExitCode)); end; [edit=Daniel G]Code ergänzt. Mfg, Daniel G[/edit] |
Alle Zeitangaben in WEZ +1. Es ist jetzt 14:37 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz