Last active
December 9, 2021 06:26
-
-
Save jarroddavis68/cc54ce02dd9dd0b0dcb340604844c959 to your computer and use it in GitHub Desktop.
Execute File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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