I have created an MSI installer with WiX.
I am specifically targeting Windows XP SP3+
It runs a custom action on completion of the installation to register the application as a service via NSSM.exe
The batch file when run from a command line does what it is written to do, but when run as part of the installer it completes the installation I see the command prompt open and the script run, but the application is not registered.
<CustomAction Id="installLoft"
Directory="ModulesFolder"
ExeCommand="[ModulesFolder]winInstall.cmd"
Execute="deferred"
Return="check"
HideTarget="no"
Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="installLoft" Before="InstallFinalize"><![CDATA[ (NOT Installed) AND (NOT REMOVE) ]]></Custom>
</InstallExecuteSequence>
The batch script contents is:
@ECHO OFF
SET PATH=%PATH%;%APPDATA%\app1\
IF "%ProgramFiles(x86)%"=="" (
set PATH=%PATH%;%ProgramFiles%\app1\
) ELSE (
set PATH=%PATH%;%ProgramFiles(x86)%\app1\
)
"app1\modules\bin\nssm.exe" install my_service_name_app1 app1.cmd -g
So, app1 is a script that needs to be run as a service, hence the need for NSSM.exe
All the components/files are installed in the right places.
Are there some Win XP caveats that I am missing? Running the batch manually with the same user that ran the installer, the service is registered.
Thanks for your help.
I have figured it out.
What I found is that in Win XP when the service is registered, it is registered under Local System (or SYSTEM) user. But the SYSTEM user does not have an APPDATA environment variable set. What was happening, is that my script would try to start up the service and would silently fail because APPDATA was not defined.
I declared/defined a custom MYAPPDATA system level environment variable and now when the installer completes – after a reboot – the service is up and running.
Hope this helps someone else relying on standard Environment variables.