3

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?

Strider
  • 3,539
  • 5
  • 32
  • 60
Martin
  • 1,977
  • 5
  • 30
  • 67

2 Answers2

11

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.

ottomeister
  • 5,415
  • 2
  • 23
  • 27
  • The nssm website made it seem like the first command would bring up the GUI which I didn't want since this script will be part of an installer but indeed this works just fine thanks! – Martin Nov 08 '18 at 12:27
0

Another aproach.... i set nssm.exe to run as admin. Now it prompt for adminn in each set call from my batch. But at least it does no require shortcut or a different way to open an admin console. It isnt nice i know but its simpler.