Skip to content

Instantly share code, notes, and snippets.

@jarroddavis68
Last active December 9, 2021 06:26
Show Gist options
  • Save jarroddavis68/cc54ce02dd9dd0b0dcb340604844c959 to your computer and use it in GitHub Desktop.
Save jarroddavis68/cc54ce02dd9dd0b0dcb340604844c959 to your computer and use it in GitHub Desktop.
Execute File
function ExecuteFile(ahWnd: Cardinal; const aFilename, aParams, aStartDir: string; aShowCmd: Integer; aWait: Boolean): Integer;
var
Info: TShellExecuteInfo;
ExitCode: DWORD;
begin
Result := -1;
FillChar(Info, SizeOf(Info), 0);
Info.cbSize := SizeOf(TShellExecuteInfo);
with Info do
begin
fMask := SEE_MASK_NOCLOSEPROCESS;
Wnd := ahWnd;
lpFile := PChar(aFilename);
lpParameters := PChar(aParams);
lpDirectory := PChar(aStartDir);
nShow := aShowCmd;
end;
if ShellExecuteEx(@Info) then
begin
if aWait then
begin
repeat
Sleep(1);
Application.ProcessMessages;
GetExitCodeProcess(Info.hProcess, ExitCode);
until (ExitCode <> STILL_ACTIVE) or Application.Terminated;
Result := ExitCode;
end;
end
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment