uses
ShellAPI;
procedure ExecAndWait(Filename, Params:
string; AHWnd: HWND; WindowState: word = SW_SHOWNORMAL);
var
ShExecInfo: SHELLEXECUTEINFO;
const
SEE_MASK_NOASYNC= $100;
begin
ZeroMemory(@ShExecInfo, SizeOf(ShExecInfo));
ShExecInfo.Wnd := AHWnd;
ShExecInfo.cbSize := sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS
or SEE_MASK_NOASYNC;
ShExecInfo.lpVerb := '
open';
ShExecInfo.lpFile := PChar(Filename);
ShExecInfo.lpParameters := PChar(Params);
ShExecInfo.lpDirectory := PChar(ExtractFileDir(Filename));
ShExecInfo.nShow := WindowState;
if ShellExecuteExW(@ShExecInfo)
then
begin
WaitForSingleObject(ShExecInfo.hProcess, INFINITE);
CloseHandle(ShExecInfo.hProcess);
end
else
RaiseLastOSError;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
try
ExecAndWait('
C:\Windows\Notepad.exe', '
', Self.Handle);
except
on E:
Exception do
ShowMessage(E.
Message);
end;
ShowMessage('
Fertig');
end;