Inno Setup 安装程序无法 运行 刚刚由子安装程序安装的应用程序(无法 运行 节点。创建过程失败)

Inno Setup installer cannot run application just installed by child installer (Unable to run Node. Create process failed)

我已经编写了脚本来使用 Inno Setup 安装 Node.js、运行 shell 脚本和 Windows 服务。我已经创建了一个设置。当我安装我的设置时 Node.js 成功安装。

[Run]    
Filename: "msiexec.exe"; Parameters: "/i ""{app}\nodejs\node-v8.11.1-x64.msi""";

Shell 脚本 运行 成功。

[Code]
procedure CurStepChanged(CurStep: TSetupStep);
var
  ErrorCode: Integer;
  ReturnCode: Boolean;
begin
  ExtractTemporaryFile('Add-AppDevPackage.ps1');
  ReturnCode :=
    ShellExec('open', '"PowerShell"',
    ExpandConstant(' -ExecutionPolicy Bypass -NoLogo -NonInteractive -NoProfile -WindowStyle Hidden  -File "{app}\setup\Add-AppDevPackage.ps1"'),
    '', SW_SHOWNORMAL, ewWaitUntilTerminated, ErrorCode);

    if (ReturnCode = False) then
        MsgBox('Message about problem. Error code: ' + IntToStr(ErrorCode) + ' ' + SysErrorMessage(ErrorCode),
          mbInformation, MB_OK);
end;

但是当我尝试 运行 Windows 服务时,它是一个 .js 文件 (installservice.js),我收到类似

的错误

Unable to run node. Create Process failed code2.

用于运行节点的代码:

[Run]
Filename: "node"; Parameters: "installservice.js"; WorkingDir: "{app}\nodepath"; \
    Flags: nowait postinstall skipifsilent runascurrentuser; AfterInstall: MsbShow;

而且我还发现如果机器中已经安装了 Node JS,那么 Windows 服务会安装并且 运行完美。我不知道错误在哪里。我什至尝试 运行 Windows 服务 post 安装,但问题仍然存在。你能在这个过程中指导我吗?

您的 [Run] 条目依赖于 nodePATH.

如果您刚才安装了 Note.js,情况就不同了,因为 Node.js 安装程序对 PATH 的更改不会反映在 运行 进程(特别是您的 Inno Setup 安装程序)。

您必须在 运行 程序之前显式重新加载环境。

[Run]
Filename: "node"; BeforeInstall: RefreshEnvironment; ...

其中 RefreshEnvironment 实现显示在:
Environment variable not recognized [not available] for [Run] programs in Inno Setup


当然,您也可以使用 node 的绝对路径。但是你要么必须依赖 Node.js 安装程序将 Node.js 安装到标准位置(我猜这里的路径,我不知道 Node.js):

[Run]
Filename: "{pf}\Node.js\node"; ...

(可能不可靠)。

或者您必须以编程方式检测安装位置,在这种情况下,上面的 RefreshEnvironment 解决方案会更容易实施。