如何从 Inno Setup 的代码部分 运行 编写程序或批处理文件?

How to run program or a batch file from Code section of Inno Setup?

如何在 Code 部分而不是 Run 中插入 Rununzip.exe 和一个批处理文件)?我尝试了这里使用的方法 Inno Setup: Install other installer and run it before continuing my install 但无法让它工作所以我恢复使用 Run 部分到 运行 两个脚本。到目前为止,我所做的似乎很草率。 Inno Setup“完成”页面显示 运行 批处理脚本的选项复选框,而我更希望它在到达此阶段之前自动 运行。

[Setup]
PrivilegesRequired=admin

[Files]
Source: "CC.exe"; DestDir: "{pf}\CC"; DestName: "CC.exe"
Source: "bbb.update.zip"; DestDir: "{userdesktop}"; Flags: deleteafterinstall
Source: "unzip.exe"; DestDir: "{userdesktop}"; Flags: deleteafterinstall

[Run]
Filename: "{userdesktop}\unzip.exe"; \
    Parameters: "x {userdesktop}\bbb.update.zip -d {userdesktop}"; \
    Flags: runascurrentuser nowait
Filename: "{userdesktop}\update.bat"; \
    Flags: runascurrentuser nowait postinstall skipifsilent

update.bat 文件安装后清理)

使用Exec function. For example in CurStepChanged event function.

还需要将命令参数中的路径用引号引起来,以防它们包含空格。

[Code]

procedure CurStepChanged(CurStep: TSetupStep);
var
  ErrorCode: Integer;
begin
  if CurStep = ssPostInstall then
  begin
    Exec(
      ExpandConstant('{userdesktop}\unzip.exe'),
      ExpandConstant('x "{userdesktop}\bbb.update.zip" -d "{userdesktop}"'),
      '', SW_HIDE, ewNoWait, ErrorCode);

    Exec(
      ExpandConstant('{userdesktop}\update.bat'), '', '', SW_HIDE, ewNoWait, ErrorCode);
  end;
end;