I have several batch files which I execute from Inno Setup. I use ShellExecuteEx()
to execute batch files:
function ShellExecuteWait(const Verb, Filename, Params, WorkingDir: string; const ShowCmd: integer; const Timeout: cardinal; var ExitCode: DWORD): boolean;
var
ExecInfo: TShellExecuteInfo;
begin
Result := false;
ExecInfo.cbSize := SizeOf(ExecInfo);
ExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS;
ExecInfo.Wnd := 0;
ExecInfo.lpVerb := Verb;
ExecInfo.lpFile := Filename;
ExecInfo.lpParameters := Params;
ExecInfo.lpDirectory := WorkingDir;
ExecInfo.nShow := ShowCmd;
if ShellExecuteEx(ExecInfo) then
begin
if WaitForSingleObject(ExecInfo.hProcess, Timeout) = WAIT_TIMEOUT then
begin
TerminateProcess(ExecInfo.hProcess, WAIT_TIMEOUT);
end else begin
end;
GetExitCodeProcess(ExecInfo.hProcess, ExitCode);
Result := (ExitCode = ERROR_SUCCESS);
end else begin
ExitCode := GetLastError();
end;
end;
if (not ShellExecuteWait('',
Command,
Params,
ExpandConstant('{tmp}'),
SW_SHOW,
Timeout,
ResultCode)) then...
But no matter what I try, I cannot get the exit code from the batch file in ResultCode
(I always get back 0).
In researching this problem, I have read that the batch must NOT use exit /b NN
. So I removed the /b
switch, but I still always get 0.
What must I do to successfully get the exit code from a batch file?
Dennis
ShellExecuteEx
and not plainShellExec
? – Martin Prikryl