title: Issue with installing node application as a service using Inno Setup and node-windows script
body: <p>The service installs but will not start, either straight away or after system reboot, when running the following script from Inno Setup:</p>
  <pre><code>#define ....
  #define NODE &quot;node-v12.16.2-x64.msi&quot;
  
  ...
  
  [Files]
  ...
  
  [Run]
  Filename: &quot;{sys}\msiexec.exe&quot;; Parameters: &quot;/passive /i &quot;&quot;{app}\{#NODE}&quot;&quot;&quot;;
  Filename: &quot;{sys}\netsh.exe&quot;; Parameters: &quot;advfirewall firewall add rule name=&quot;&quot;Node In&quot;&quot; program=&quot;&quot;{pf64}\nodejs\node.exe&quot;&quot; dir=in action=allow enable=yes&quot;; Flags: runhidden;
  Filename: &quot;{sys}\netsh.exe&quot;; Parameters: &quot;advfirewall firewall add rule name=&quot;&quot;Node Out&quot;&quot; program=&quot;&quot;{pf64}\nodejs\node.exe&quot;&quot; dir=out action=allow enable=yes&quot;; Flags: runhidden;
  Filename: &quot;{pf64}\nodejs\node.exe&quot;; Parameters: &quot;{app}\validation-installer-node-windows.js&quot;;
  </code></pre>
  <p>validation-installer-node-windows.js:</p>
  <pre class="lang-js prettyprint-override"><code>var Service = require('node-windows').Service;
  // Create a new service object
  var svc = new Service({
       name:'receipt-validation-app1_7',
       description: 'Testing Team Receipt Validation.',
       script: 'C:\\xxxxx-receipt-validation-app1_v2\\app.js'
  });
  
  // Listen for the &quot;install&quot; event, which indicates the
  // process is available as a service.
  
  svc.on('install',function(){
       svc.start();
  });
  
  svc.install();
  </code></pre>
  <p>When the Inno Setup installer runs, it definitely installs the service and it is set to &quot;Automatic&quot; in startup type. However, when I restart my machine it does not auto-start.</p>
  <p>However, when I run</p>
  <blockquote>
  <p>node validation-installer-node-windows.js</p>
  </blockquote>
  <p>the service installs (after I change the name so it doesn't clash) and autostarts straight away without reboot.</p>
  <p>I have also tried running as admin. No special permissions were required when running <code>validation-installer-node-windows.js</code> from the terminal.</p>
  <hr />
  <p>I attempted to trigger .js script using Pascal scripting and <code>AfterInstall</code> keyword as follows:</p>
  <pre><code>Source: &quot;C:\...\validation-installer-node-windows.js&quot;; DestDir: &quot;{app}&quot;; \
      Flags: ignoreversion; AfterInstall: RunNodeInstall()
  
  [Run]
  ; Add Firewall Rules
  Filename: &quot;{sys}\netsh.exe&quot;; Parameters: &quot;advfirewall firewall add rule name=&quot;&quot;Node In&quot;&quot; program=&quot;&quot;{pf64}\nodejs\node.exe&quot;&quot; dir=in action=allow enable=yes&quot;; Flags: runhidden;
  Filename: &quot;{sys}\netsh.exe&quot;; Parameters: &quot;advfirewall firewall add rule name=&quot;&quot;Node Out&quot;&quot; program=&quot;&quot;{pf64}\nodejs\node.exe&quot;&quot; dir=out action=allow enable=yes&quot;; Flags: runhidden;
  </code></pre>
  <pre class="lang-pascal prettyprint-override"><code>[Code]
  procedure RunNodeInstall();
  var
   ErrorCode: Integer;
  begin
    if not Shellexec('', 'node', ExpandConstant('{app}\validation-installer-node-windows.js'),'',SW_HIDE,ewWaitUntilTerminated,ErrorCode) then
    begin
      MsgBox('Issue occured with installing application as a service!', mbInformation, MB_OK);
    end;
  end;
  </code></pre>
  <p>Again, the script runs just fine and installs the service. However, like before it does not automatically set the status to &quot;Running&quot; and when hitting the nodejs endpoint it returns an &quot;unable to connect&quot; error which then sees the service status return to blank.</p>
  <hr />
  <p>There are a series of log msgs, it starts with:</p>
  <blockquote>
  <p>C:\woolworths-receipt-validation-app1_v2\app.js stopped running.</p>
  </blockquote>
  <p>Then:</p>
  <blockquote>
  <p>Restarted 1250 msecs after unexpected exit; attempts = 1</p>
  </blockquote>
  <p>This iterates to 3 attempts and then the last log shows:</p>
  <blockquote>
  <p>Child process [5616 - C:\Program Files\nodejs\node.exe --harmony C:\woolworths-receipt-validation-app1_v2\node_modules\node-windows\lib\wrapper.js --file C:\woolworths-receipt-validation-app1_v2\app.js --scriptoptions= --log &quot;receipt-validation-app1_7 wrapper&quot; --grow 0.25 --wait 1 --maxrestarts 3 --abortonerror n --stopparentfirst undefined] finished with 0</p>
  </blockquote>