function ExecAndWait(Filename, Params:
String;
WindowState: Word = SW_SHOWNORMAL): boolean;
var
{$IFDEF UNICODE} ShExecInfoW: SHELLEXECUTEINFOW;
{$ENDIF}
ShExecInfoA: SHELLEXECUTEINFOA;
begin
Result := false;
if (Filename = '
')
or not FileExists(FileName)
then
exit;
begin
ShExecInfoA.Wnd := GetForegroundWindow;
ShExecInfoA.cbSize := sizeof(SHELLEXECUTEINFOA);
ShExecInfoA.fMask := [b]SEE_MASK_NOCLOSEPROCESS[/b];
ShExecInfoA.lpVerb := '
open';
ShExecInfoA.lpFile := PAnsiChar(AnsiString(Filename));
ShExecInfoA.lpParameters := PAnsiChar(AnsiString(Params));
ShExecInfoA.lpDirectory := PAnsiChar(AnsiString(ExtractFileDir(Filename)));
ShExecInfoA.nShow := WindowState;
Result := ShellExecuteExA(@ShExecInfoA);
try
if Result
then WaitForSingleObject(ShExecInfoA.hProcess, INFINITE);
finally
CloseHandle(ShExecInfoA.hProcess);
end;
end;
end;