Function ExecAndWait(
const Filename, Params:
String; WindowState: Word = SW_SHOWNORMAL): boolean;
var
ShExecInfo: SHELLEXECUTEINFO;
// MSDN: ShellExecuteEx, ShellExecuteInfo
begin
Result := false;
if ( Filename = '
' )
{or not FileExists( FileName )} then
exit;
// Exception wäre hier besser, aber nun
ShExecInfo.Wnd := GetForegroundWindow;
ShExecInfo.cbSize := sizeof( SHELLEXECUTEINFO );
ShExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.lpVerb := '
open';
ShExecInfo.lpFile := PChar( Filename );
ShExecInfo.lpParameters := PChar( Params );
ShExecInfo.lpDirectory := PChar( ExtractFileDir( Filename ) );
ShExecInfo.nShow := WindowState;
Result := ShellExecuteEx( @ShExecInfo );
try
if Result
then WaitForSingleObject( ShExecInfo.hProcess, INFINITE );
finally
CloseHandle( ShExecInfo.hProcess );
end;
end;