2

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?

Martin Prikryl
  • 167,268
  • 50
  • 405
  • 846
RBK
  • 528
  • 4
  • 15

1 Answers1

1

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).

You would have to explicitly reload the environment before running the program.

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

Where the RefreshEnvironment implementation is shown in:
Environment variable not recognized [not available] for [Run] programs in Inno Setup


Or you can, of course, use an absolute path to the node. But then you either have to rely on the Node.js installer to install Node.js to a standard location (I'm guessing the path here, I do not know Node.js):

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

(what might not be reliable).

Or you would have to detect the installation location programmaticaly, in which case the RefreshEnvironment solution above would be easier to implement.

Martin Prikryl
  • 167,268
  • 50
  • 405
  • 846