uses
ShellAPI;
procedure TForm1.Button1Click(Sender: TObject);
var
SEEInfo: TShellExecuteInfo;
begin
ZeroMemory(@SEEInfo, SizeOf(TShellExecuteInfo));
with SEEInfo
do
begin
cbSize := SizeOf(TShellExecuteInfo);
fMask := SEE_MASK_DOENVSUBST
or
SEE_MASK_FLAG_NO_UI
or
SEE_MASK_NOCLOSEPROCESS;
Wnd :=
Handle;
lpVerb := '
open';
lpFile := PChar(Trim(Edit1.Text));
nShow := SW_SHOWDEFAULT;
end;
if not ShellExecuteEx(@SEEInfo)
then
ShowMessage(SysErrorMessage(GetLastError()))
else
if SEEInfo.hProcess = 0
then
ShowMessage('
Kein Prozess-Handle!')
else
try
// Warten bis Anwendung initialisiert ist...
WaitForInputIdle(SEEInfo.hProcess, INFINITE);
ShowMessage('
ok');
// Warten bis Anwendung beendet ist...
WaitForSingleObject(SEEInfo.hProcess, INFINITE);
ShowMessage('
done');
finally
CloseHandle(SEEInfo.hProcess);
end;
end;