Registriert seit: 30. Nov 2005
Ort: München
5.774 Beiträge
Delphi 10.4 Sydney
|
Re: Programm starten und warten bis es beendet wird
8. Feb 2006, 09:56
Hallo,
ich benutze für solche Sachen immer diese Funktion:
Delphi-Quellcode:
{ WindowState is one of the SW_xxx constants.
Look up ShowWindow in the API help for a list.}
function ExecAndWait( const Filename, Params: string;
WindowState: word): boolean;
{$IFDEF WIN32}
var
SUInfo: TStartupInfo;
ProcInfo: TProcessInformation;
CmdLine: string;
begin
{ Enclose filename in quotes to take care of
long filenames with spaces. }
CmdLine := ' "' + Filename + ' " ' + Params;
FillChar(SUInfo, SizeOf(SUInfo), #0);
with SUInfo do begin
cb := SizeOf(SUInfo);
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow := WindowState;
end;
try
Result := CreateProcess( NIL, PChar(CmdLine), NIL, NIL, FALSE,
CREATE_NEW_CONSOLE or
NORMAL_PRIORITY_CLASS, NIL,
PChar(ExtractFilePath(Filename)),
SUInfo, ProcInfo);
except
on E: Exception do
begin
Result:=false;
end;
end;
{ Wait for it to finish. }
if Result then
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
{$ELSE}
var
InstanceID : THandle;
Buff: array[0..255] of char;
begin
StrPCopy(Buff, Filename + ' ' + Params);
InstanceID := WinExec(Buff, WindowState);
if InstanceID < 32 then
{ a value less than 32 indicates an Exec error }
Result := FALSE
else begin
Result := TRUE;
repeat
Application.ProcessMessages;
until Application.Terminated or
(GetModuleUsage(InstanceID) = 0);
end;
{$ENDIF}
end;
Vielleicht kannst Du sie ja nach Deinen Anforderungen umbauen.
Grüße
Klaus
Klaus
|
|
Zitat
|