node.jsinno-setuppascalscript

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


I have written script to install Node.js, run shell script and Windows service using Inno Setup. I have created a setup. When I install my setup Node.js gets successfully installed.

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

Shell scripts runs successfully.

[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;

But when I try to run Windows service which is a .js file (installservice.js), I get an error like

Unable to run node. Create Process failed code2.

Code used to run the node:

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

And I also found that if the Node JS is already installed in the machine then the Windows service installs and runs perfectly. I don't know where the error is. I even tried to run the Windows service post install but still the problem persist. Can you guide me in this process?


Solution

  • Your [Run] entry relies on the node to be in PATH.

    That won't be the case, if you installed Note.js just now, as the change in PATH by the Node.js installer won't be reflected in already running processes (particularly your Inno Setup installer).

    For details, see:
    Environment variable not recognized [not available] for [Run] programs in Inno Setup


    Instead, specify an absolute path to the node in Filename parameter. Something like:

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

    or set a working directory using WorkingDir parameter:

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