procedure ExecuteAndWait(FileName, Params, Directory: WideString);
var
SEInfo: TShellExecuteInfoW;
ExitCode: DWORD;
begin
FillChar(SEInfo, SizeOf(SEInfo), 0) ;
SEInfo.cbSize := SizeOf(TShellExecuteInfoW) ;
with SEInfo do
begin
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := Form1.Handle;
lpFile := PWideChar(FileName);
lpParameters := PWideChar(Params);
lpDirectory := PWideChar(Directory);
nShow := SW_HIDE; //SW_SHOW;
end;
if ShellExecuteExW(@SEInfo) then
begin
repeat
Application.ProcessMessages;
GetExitCodeProcess(SEInfo.hProcess, ExitCode) ;
until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
end;
end;