Ф-я dwExecAndWait запускает процесс и ждет его завершения (из dwUnits).
Используй вместо WinExec.
Код:
procedure dwProcessMessages;
var
Msg: TMsg;
begin
while PeekMessage(Msg, GetCurrentProcess, 0, 0, PM_REMOVE) do
//if not IsDialogMessage(Dlg, Msg) then
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end;
procedure dwExecAndWait(const FileName, Params: String; const CmdShow: Integer);
var
exInfo: TShellExecuteInfo;
Ph: DWORD;
begin
FillChar(exInfo, SizeOf(exInfo), 0);
with exInfo do
begin
cbSize := SizeOf(exInfo);
fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;
Wnd := GetActiveWindow();
ExInfo.lpVerb := 'open';
ExInfo.lpParameters := PChar(Params);
lpFile := PChar(FileName);
nShow := CmdShow;
end;
if ShellExecuteEx(@exInfo) then
Ph := exInfo.HProcess
else
begin
ShowMessage(SysErrorMessage(GetLastError));
Exit;
end;
while WaitForSingleObject(ExInfo.hProcess, 50) <> WAIT_OBJECT_0 do
dwProcessMessages;
CloseHandle(Ph);
end;