4

I am using NSSM to create a service, however, after creation I need to set some parameters, such as AppDirectory, AppNoConsole, etc.

I am able to create the service using the GUI, but I want to do it via cmd, for which I have a batch file that goes like this:

nssm install MyService "%Java_Exe_Path%" "-Xmx1024M -classpath \bin\start.jar;\lib\*;. com.myapp.class.subclass start"
nssm set MyService AppDirectory "%DIR%"
nssm set MyService AppNoConsole 1

Thing is I am getting errors that read:

Can't open service! OpenService(): Access is denied.

Or

OpenService(): The specified service does not exist as an installed service.

Notes: When I run the cmd file I get asked for admin rights (guessing to run the install), but to edit (set) I am not being requested permissions, neither I get asked permissions if I run the set command directly via commandline (also getting an error of access denied).

Can anyone help? Thanks!

Fede E.
  • 2,118
  • 4
  • 23
  • 39
  • If you have to have the appropriate permissions, I'm not really sure that this is a scripting issue. Perhaps [Super User](https://superuser.com/questions/ask) would have been more appropriate. – Compo Apr 25 '18 at 17:00
  • 2
    I managed to run all the commands in the cmd file is I open cmd with admin privileges. It's weird that nssm does not ask for permissions for each argument. Perhaps its possible to run the install command with all the other parameters already in that line? – Fede E. Apr 25 '18 at 17:06
  • 1
    Well I guess that certain levels of the command requires admin rights. Create a shortcut to the batch and set it to run as admin. – Gerhard Apr 25 '18 at 17:21
  • @GerhardBarnard yeah, not a bad idea, not applicable in my scenario as I also use the same batch to implement other commands aside of the install service (which is the one that requires extra admin rights for the edit). – Fede E. Apr 25 '18 at 21:04

1 Answers1

0

Got the same problem, my solution is always run this script as an administrator:

How to request Administrator access inside a batch file

Fangxing
  • 5,716
  • 2
  • 49
  • 53