J'ai plusieurs fichiers batch que j'exécute depuis Inno Setup. J'utilise ShellExecuteEx()
pour exécuter des fichiers batch:Récupère le code de sortie du fichier batch dans Inno Setup en utilisant 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...
Mais peu importe ce que j'essaie, je ne peux pas obtenir le code de sortie du fichier de commandes dans ResultCode
(je reçois toujours en arrière 0).
En recherchant ce problème, j'ai lu que le lot ne doit PAS utiliser exit /b NN
. J'ai donc supprimé le commutateur /b
, mais je reçois toujours 0.
Que dois-je faire pour obtenir le code de sortie à partir d'un fichier de commandes?
Dennis
Quelle que soit la raison pour laquelle vous utilisez ShellExecuteEx et non pas ShellExec (http://www.jrsoftware.org/ishelp/index.php?topic=isxfunc_shellexec)? –