Inno Setup - 运行 脚本在第一次尝试新机器时不起作用

Inno Setup - Running script does not work in the first attempt for a new machine

我使用 Inno Setup 编译器 6.0.2 创建了一个简单的可执行 (.exe) 文件,用于安装 Windows 应用程序。

.exe 文件调用 vbscript "Setup.vbs" 解压缩 "Application.zip" 文件并更新环境变量。

当我第一次在新机器上 运行 .exe 文件 时,.vbs 文件没有被执行。但是,从第二次尝试开始,它工作正常。这是一个已知问题还是有任何解决方案?

这是我用来调用 运行.vbs 文件的代码片段

[Code]
function PrepareToInstall(var NeedsRestart: Boolean): String;
    var ResultCode: integer;
begin
    ShellExec('',ExpandConstant('{app}\{#MyAppExeName}'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
end;

更新

我希望 .vbs 在安装前执行。所以,我尝试了 ExtractTemporaryFile,但我仍然面临同样的问题。不确定下面的代码有什么问题。

#define MyAppExeName "Setup.vbs"

[Files]
Source: "..\Application\Installation_Setup\Setup.vbs"; DestDir: "{app}"; Flags: ignoreversion

[Code]
function PrepareToInstall(var NeedsRestart: Boolean): String;
var
  ResultCode: integer;
begin
  ExtractTemporaryFile('{#MyAppExeName}');
  ShellExec('',ExpandConstant('{app}\{#MyAppExeName}'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode)
end; 

PrepareToInstall 发生在 安装 之前。当您执行一个已安装的文件时,它在您调用它时尚不存在。

可能的解决方案

  • CurStepChanged(ssPostInstall)安装后执行脚本:

    或者您可以使用 [Run] 部分:

  • 如果您需要在安装前执行脚本(我不认为这是您的情况),请使用 ExtractTemporaryFile.

  • 对于 ZIP 解压,您不需要 VBS 脚本,您可以直接从 Inno Setup 代码执行此操作。
    How to get Inno Setup to unzip a file it installed (all as part of the one installation process)