hApp: Cardinal;
function StartApp(apchOperation, apchFileName, apchParameters, apchDirectory: PChar;
awrdShowCmd: Word): Cardinal;
var
lseiInfo: TShellExecuteInfo;
begin
Result := 0;
FillChar(lseiInfo, SizeOf(lseiInfo), Chr(0));
lseiInfo.cbSize := SizeOf(lseiInfo);
lseiInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
lseiInfo.lpVerb := apchOperation;
lseiInfo.lpFile := apchFileName;
lseiInfo.lpParameters := apchParameters;
lseiInfo.lpDirectory := apchDirectory;
lseiInfo.nShow := awrdShowCmd;
if Boolean(ShellExecuteEx(@lseiInfo)) then
Result := lseiInfo.hProcess;
end;
procedure DestroyProcess(hProcess: Cardinal);
Var
ovExitCode: LongWord;
begin
try
if hProcess<>0 then
begin
GetExitCodeProcess(hProcess, ovExitCode);
if (ovExitCode = STILL_ACTIVE) or (ovExitCode <> WAIT_OBJECT_0) then
TerminateProcess(hProcess, ovExitCode);
CloseHandle(hProcess);
end;
except
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
hApp := StartApp('open', 'd:\Workers.pdf', '', '', SW_SHOWNORMAL);
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
if hApp > 0 then
DestroyProcess(hApp);
end;