// Alles was frmProt. etc... ist dient zum Protokollieren (also nicht weiter wichtig)
function ExecAndWait(
const filename, params:
string; windowstate: word;
warten: boolean): boolean;
var
SEInfo: TShellExecuteInfo;
ExitCode: DWORD;
window: Cardinal;
begin
frmProt.AddDo(0000,'
ExecAndWait:'+filename+'
/'+params);
try
FillChar(SEInfo, SizeOf(SEInfo), 0);
SEInfo.cbSize := SizeOf(TShellExecuteInfo);
with SEInfo
do begin
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := Application.Handle;
lpFile := PChar(filename);
lpParameters := PChar(params);
nShow := windowstate;
end;
if ShellExecuteEx(@SEInfo)
then
begin
if warten
then begin
window := GetActiveWindow;
// Enabled := false;
repeat
Sleep(100);
//2004_12_15 to prevent 100% CPU-Usage
Application.ProcessMessages;
GetExitCodeProcess(SEInfo.hProcess, ExitCode);
until (ExitCode <> STILL_ACTIVE)
or Application.Terminated;
//Enabled := true;
SetForegroundWindow(window);
end;
Result:=True;
end
else Result:=False;
except
on e:
Exception do
frmProt.AddEx(true,e.ClassName,e.
Message + #13#10 + filename + #13#10 + params);
end;
end;