NSSM - Install service from command line with many arguments

Martin picture Martin · Nov 7, 2018 · Viewed 13.3k times · Source

I am trying to make a batch file that will create my service and struggling with how exactly to list each parameter. I've researched this quite a bit and I can't seem to find the correct syntax. This is what i have right now :

nssm install MDHIS_WebClient "%MDHIS2_HOME%/MDHIS_WebClient.cmd" AppDirectory %MDHIS2_HOME% DisplayName MDHIS_WebClient Start SERVICE_AUTO_START DependOnService MSSQLSERVER AppNoConsole 1 AppStopMethodConsole 30000

This works but the arguments are ignored. Can anyone show me an example of the proper syntax?

Answer

ottomeister picture ottomeister · Nov 8, 2018

The command you are using now will end up passing all of the items after the path to your program (starting with AppDirectory) as arguments to your program when it is executed. Obviously that is not the behaviour that you want.

To establish parameters that are meaningful to nssm you must run a separate nssm set command for each parameter. In this case you would use this command to create the service and define the path to your program:

  nssm install MDHIS_WebClient "%MDHIS2_HOME%/MDHIS_WebClient.cmd"

followed by this series of commands to establish the various parameters:

  nssm set MDHIS_WebClient AppDirectory %MDHIS2_HOME%

  nssm set MDHIS_WebClient DisplayName MDHIS_WebClient 

  nssm set MDHIS_WebClient Start SERVICE_AUTO_START 

  nssm set MDHIS_WebClient DependOnService MSSQLSERVER 

  nssm set MDHIS_WebClient AppNoConsole 1 

  nssm set MDHIS_WebClient AppStopMethodConsole 30000

To be safe, I would move the Start parameter to the end of that series in order to prevent the possibility of nssm launching the service before the remaining parameters (DependOnService, AppNoConsole and AppStopMethodConsole) have been established.