我有几个从 Inno Setup 执行的批处理文件。我ShellExecuteEx()
用来执行批处理文件:
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...
但无论我尝试什么,我都无法从批处理文件中获取退出代码ResultCode
(我总是返回 0)。
在研究这个问题时,我读到该批次不能使用exit /b NN
. 所以我删除了/b
开关,但我仍然总是得到 0。
我必须怎么做才能成功地从批处理文件中获取退出代码?
丹尼斯