procedure TRunProcess.ExecAndWait;
var
{$IFDEF UNICODE} ShExecInfoW: SHELLEXECUTEINFOW;
{$ENDIF}
ShExecInfoA: SHELLEXECUTEINFOA;
// MSDN: ShellExecuteEx, ShellExecuteInfo
begin
if (fApp = '
')
or not FileExists(fApp)
then
exit;
{$IFDEF UNICODE}
if Win32IsUnicode = VER_PLATFORM_WIN32_NT
then
begin
ZeroMemory(@ShExecInfoW, SizeOf(ShExecInfoW));
ShExecInfoW.Wnd := GetForegroundWindow;
ShExecInfoW.cbSize := SizeOf(SHELLEXECUTEINFOW);
ShExecInfoW.fMask := 0;
//SEE_MASK_NOCLOSEPROCESS;
ShExecInfoW.lpVerb := '
open';
ShExecInfoW.lpFile := PWideChar(WideString(fApp));
ShExecInfoW.lpParameters := PWideChar(WideString(fParam));
ShExecInfoW.lpDirectory := PWideChar(WideString(ExtractFileDir(fApp)));
ShExecInfoW.nShow := fWindowState;
try
ShellAPI.ShellExecuteExW(@ShExecInfoW);
if fWait
then WaitForSingleObject(ShExecInfoW.hProcess, INFINITE);
finally
fStarted := ShExecInfoW.hProcess <> 0;
end;
end
else
{$ENDIF}
begin
ZeroMemory(@ShExecInfoA, SizeOf(ShExecInfoA));
ShExecInfoA.Wnd := GetForegroundWindow;
ShExecInfoA.cbSize := sizeof(SHELLEXECUTEINFOA);
ShExecInfoA.fMask := 0;
//SEE_MASK_NOCLOSEPROCESS;
ShExecInfoA.lpVerb := '
open';
ShExecInfoA.lpFile := PAnsiChar(AnsiString(fApp));
ShExecInfoA.lpParameters := PAnsiChar(AnsiString(fParam));
ShExecInfoA.lpDirectory := PAnsiChar(AnsiString(ExtractFileDir(fApp)));
ShExecInfoA.nShow := fWindowState;
try
ShellExecuteExA(@ShExecInfoA);
if fWait
then WaitForSingleObject(ShExecInfoA.hProcess, INFINITE);
finally
fStarted := ShExecInfoA.hProcess <> 0;
end;
end;
end;