function ExecAndWait(Filename, Params: Widestring;
WindowState: word = SW_SHOWNORMAL): boolean;
var
ShExecInfo : SHELLEXECUTEINFOW;
r : Cardinal;
//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shellexecuteex.asp
//http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/structures/shellexecuteinfo.asp
begin
Result := false;
if Filename = '
'
then exit;
if not WideFileExists(FileName)
then
begin
Log (true,P_ERROR,WideFormat(_('
Kann die angegebene Datei nicht finden: %s'),[FileName]));
exit;
end;
ShExecInfo.cbSize := sizeof(SHELLEXECUTEINFOW);
ShExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.lpVerb := '
open';
ShExecInfo.lpFile := PWideChar(Filename);
ShExecInfo.lpParameters := PWideChar(Params);
ShExecInfo.lpDirectory := PWideChar(WideExtractFileDir(Filename));
ShExecInfo.nShow := WindowState;
Result := ShellExecuteExW(@ShExecInfo);
try
if Result
then
begin
r := WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
if r <> WAIT_OBJECT_0
then
Log(true,P_FATAL,IntToStr(r)+#10+WideFormat(_('
Fehler beim Beenden von "%s".'),[Filename]));
end else
Log(true,P_FATAL,SysErrorMessage(GetLastError)+#10+WideFormat(_('
Fehler beim Starten von "%s".'),[Filename]));
finally
CloseHandle(ShExecInfo.hProcess);
end;
end;