windows-serviceswindows-installerinno-setupinno-setup-v6

unable to start windows service after registering for start node server using inno setup script


Hello Stack Overflow community,

I'm facing an issue with an Inno Setup script and need some assistance. During the installation of an executable (Exe), I have to register one windows service for start my node server to run my angular ssr build. but after creating windows service it shows pause status, when i manually start/pause the windows service then I am getting error.

actual command for start node server for run my angular ssr.

"C:\Program Files\nodejs\node" "C:\Program Files (x86)\envVarIssue\ecom\angular\server\main.js"

when I run above command in cmd then it run perfectly.

but I have to start server using windows services. so for that I install windows service, node.msi during installing my exe app.

when I installing exe, windows service create, but it doesn't starting. it show pause status.

see below attachment of error

GETTING ERROR DURING START THE WINDOWS SERVICE

snapshot of windows service

for register windows service I used, nssm.

Can anyone help me understand why this issue is occurring and how I can resolve it? Thank you for your assistance.

I provided my code please check it.

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "envVarIssue"
#define MyAppVersion "1.5"
#define MyAppPublisher "My Company, Inc."
#define MyAppURL "https://www.example.com/"
#define MyAppExeName "MyProg.exe"
#define MyAppAssocName MyAppName + " File"
#define MyAppAssocExt ".myp"
#define MyAppAssocKey StringChange(MyAppAssocName, " ", "") + MyAppAssocExt

#define MyAppParentPath "."

#define MyAppShortName "ecomNodeServer"

#define NODE64 "node-v21.6.2-x64.msi"
#define NSSM64 "nssm.exe"

[Setup]
SetupLogging=yes
ChangesEnvironment=yes

; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{D2C055CB-72E7-4DB9-83EE-34D399939D0C}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={autopf}\{#MyAppName}
ChangesAssociations=yes
DisableProgramGroupPage=yes
; Uncomment the following line to run in non administrative install mode (install for current user only.)
PrivilegesRequired=admin
OutputBaseFilename=envVarIssue App
Compression=lzma
SolidCompression=yes
WizardStyle=modern

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "C:\Program Files (x86)\Inno Setup 6\Examples\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignoreversion;
Source: "{#MyAppParentPath}\ecom\angular\*"; DestDir: "{app}\ecom\angular"; Flags: ignoreversion recursesubdirs createallsubdirs;
;Source: "{#MyAppParentPath}\ecom\node-v20.11.1-win-x64\*"; DestDir: "{app}\ecom\node-v20.11.1-win-x64"; Flags: ignoreversion recursesubdirs createallsubdirs;

; uncomment for you want to install node via .msi 
Source: "{#MyAppParentPath}\winstaller\{#NODE64}"; DestDir: "{app}"; Flags: ignoreversion;
Source: "{#MyAppParentPath}\ecom\nssm-2.24\win64\{#NSSM64}"; DestDir: "{app}"; Flags: ignoreversion

; NOTE: Don't use "Flags: ignoreversion" on any shared system files


[Icons]
Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"
Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon

[Run]
; Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent
; install service without installation node
;Filename: "{app}\{#NSSM64}"; \
    Parameters: "install {#MyAppShortName} ""{app}\ecom\node-v20.11.1-win-x64\node.exe"" ""{app}\ecom\angular\server\main.js"""; \
    Description: "Installing Node Server service"; \
    StatusMsg: "Installing Node Server service..."; \
    Flags: runascurrentuser runhidden;

;Filename: "{cmd}"; \
    Parameters: "/c nssm set {#MyAppShortName} description ""test"" && nssm set {#MyAppShortName} DisplayName ""ECOM NODE SERVER"" && nssm set {#MyAppShortName} start SERVICE_DELAYED_AUTO_START"; \
    WorkingDir: "{app}"; \
    Description: "Configure Node Server service"; \
    StatusMsg: "Configure Node Server service..."; \
    Flags: runascurrentuser runhidden;

;Filename: "{app}\{#NSSM64}"; \
    Parameters: "start {#MyAppShortName}"; \
    Description: "Configure Node Server service"; \
    StatusMsg: "Configure Node Server service..."; \
    Flags: runascurrentuser runhidden;


Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: postinstall skipifsilent;

; Install Node
Filename: "{sys}\msiexec.exe"; Parameters: "/passive /i ""{app}\{#NODE64}""";

; Add Firewall Rules
Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall add rule name=""Node In"" program=""{pf64}\nodejs\node.exe"" dir=in action=allow enable=yes"; Flags: runhidden;
Filename: "{sys}\netsh.exe"; Parameters: "advfirewall firewall add rule name=""Node Out"" program=""{pf64}\nodejs\node.exe"" dir=out action=allow enable=yes"; Flags: runhidden;

; Add System Service
Filename: "{app}\{#NSSM64}"; Parameters: "install {#MyAppShortName} ""{pf64}\nodejs\node.exe"" ""{app}\ecom\angular\server\main.js"""; Flags: runhidden;
Filename: "{sys}\net.exe"; Parameters: "start {#MyAppShortName}"; Flags: runhidden;

;Filename: "{cmd}"; Parameters: "/C set PATH=%PATH%;{app}\mongodb\bin"; Flags: runascurrentuser waituntilterminated;
; Run MongoDB mongod command
;Filename: "{cmd}"; Parameters: "/K mongod >> ""{app}\mongo_logfile.txt"" 2>&1"; Flags: postinstall waituntilterminated runascurrentuser;


[UninstallRun]
Filename: "{app}\{#NSSM64}"; Parameters: "remove {#MyAppShortName} confirm"; Flags: runhidden;
Filename: "{app}\{#NSSM64}"; Parameters: "stop {#MyAppShortName}"; Flags: runhidden;

; Removes System Service
;Filename: "{sys}\net.exe"; Parameters: "stop {#MyAppShortName}"; Flags: runhidden;
;Filename: "{app}\{#NSSM64}"; Parameters: "remove {#MyAppShortName} confirm"; Flags: runhidden;
;Filename: "{sys}\net.exe"; Parameters: "stop {#MyAppLCShortName}"; Flags: runhidden;
;Filename: "{pf64}\nodejs\node.exe"; Parameters: "{app}\bin\windows-service-installer.js remove"; Flags: runhidden;


[Code]
procedure DebugOutput(Msg: string);
begin
  Log('Debug: ' + Msg);
end;

[Code]


Solution

  • The problem was the combination of Inno Setup and nssm, which both are escaping double quotes with double quotes. That makes multiple double quotes necessary.

    Solution:

    ; Add System Service
    Filename: "{app}\{#NSSM64}"; Parameters: "install {#MyAppShortName} ""{pf64}\nodejs\node.exe"" """"""{app}\ecom\angular\server\main.js"""""""; Flags: runascurrentuser runhidden;
    

    Reference: this StackoverFlow Question


    For Log error and std res you can set addition options of nssm

    Filename: "{cmd}"; WorkingDir: "{app}"; Parameters: "/c nssm set {#MyAppShortName} AppStdout ""{app}\myServiceLog-stdOut-log.txt"""; Flags: runascurrentuser runhidden;
    Filename: "{cmd}"; WorkingDir: "{app}"; Parameters: "/c nssm set {#MyAppShortName} AppStderr ""{app}\myServiceLog-stdErr-log.txt"""; Flags: runascurrentuser runhidden;
    Filename: "{cmd}"; WorkingDir: "{app}"; Parameters: "/c nssm set {#MyAppShortName} AppNoConsole 1"; Flags: runascurrentuser runhidden;