NSSM: Can't edit a service I created - windows

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!

Got the same problem, my solution is always run this script as an administrator:
How to request Administrator access inside a batch file

Related

NSSM service not executing batch script but was created and starts successfully

I want to automatically start my node server on the VM's reboot using the following batch script
#echo off
cd /D c:/Application Services/servers/dashboard/server
echo Starting Dashboard Server In Production: port 8446
npm run prod
the "prod" script is defined as
"prod": "set PORT=8446&&set NODE_ENV=production&&node --no-warnings ./bin/www"
When run on it's own, the batch script works and localhost:8446 gives a response
When I start the service I created with NSSM the script doesn't seem to run here's how I created the service
nssm install DashboardService
The GUI popped up and I selected the path to the batch file
The service installed and started successfully but localhost:8446 didn't give back a response indicating to me that the service didn't execute the batch script
There's another service that is just like this one already on my system and I checked to make sure my service was set up the exact same way. I changed my service to execute the batch script the working service was executing and my service successfully ran that batch script so it's not a problem with nssm or the service manager but with the batch script.
I based my batch script off the working:
#echo off
cd /D c:/IOEServices/node-servers
echo Starting GraphQL Server
node src/index.js
So my question is, why isn't the batch script executing when prompted by services and starting the node server?

How to run a bat script on multiple windows servers at once?

I am trying to run a .bat script that uninstall 32/64 bit agents and re-install 64-bit agents on almost 100 window servers.
Can you please guide me how this can be done?
I already tried running for one server to test
psexec \\<windows server> -u <username> -p <password> <command>
But fails with error
COULD NOT START PSEXESVC service on <windows server>
Do we need such service on all machines? Please suggest any other way?
PSEXEC is not a standard windows feature /service.
If you wish to use PS Exec you will need to install it on all of the relevant systems first.
Otherwise, your options are:
CMD:
A) Does the "Agent" Installer you are using allow you to install / uninstall to a given server in it's command line syntax?
If so utilize that.
B) Put the Installer in central location (the Active Directory Netlogon Folder is great for this) along with a CMD script to run the uninstall and install processes.
Then Use SCHTasks to connect to each server and create a Scheduled task that runs using an administrative Username and password for that server, and set it to run with the highest privileges, set the action to be the path to the CMD script in netlogon that you have previously tested and nwo is working, set the task to run 1 minute in the future, or on demand (If on demand you then run schtasks again to execute the task).
Powershell:
Work on getting a working CMD Script to run and use Invoke Command to run that command script on the remote systems. As in Option B from CMD options you can keep the CMD script and Agent installer in the netlogon folder.

nssm - Not installing the application path and its parameters

I tried running the below command in administrator mode to install nginx as service
nssm install ztestservice "C:\Stack\nginx\nginx.exe"
nssm is installing the service but there is no reference to the application path in the registry. i.e. no parameters are set. When I try to start the service shows error "cant start service".
Please help.
I have been using nssm to run a php script. I find if you run just:
nssm install ztestservice
nssm will pop up a window that lets you set all the other parameters. Otherwise, you can set the parameters separately using the set command:
nssm set <servicename> <parameter> [<subparameter>] <value>
so:
nssm set ztestservice AppParameters "C:\Stack\nginx\nginx.exe"
However, watch out. On windows 2012r2 i'm experiencing an issue where it now hangs on the stop command so i'd watch out for that!
EDIT: You can also run nssm dump ztestservice' will also give you a list of the available parameters
EDIT2: (Will i ever stop editing this?)nssm edit ztestservice' to edit the service you just created, changing all params and having them set in the registry.

NSSM will not pickup executable directory

I'm trying to use the Non-Sucking Service Manager (NSSM) to create a service. Unfortunately, for whatever reason, NSSM won't play ball.
I'm trying to install the service using the following command:
nssm install "My Service" "C:\Program Files\Vendor\bin\windows\service-start.bat"
The service is successfully created. However, when I go to Services and Right-Click on "My Service" and view the properties the "Path to executable" field is set to the path of NSSM itself. In this case, 'C:\Program Files\nssm-2.24\win64\nssm.exe'.
I've attempted to change this using the following command:
nssm set "My Service" AppDirectory "C:\Program Files\Vendor\bin\windows\service-start.bat"
This doesn't make any difference and the executable path remains the same.
I'm trying to do this on Windows Server 2012 R2.
As CodeCaster mentioned, the 'Path to Executable' is correctly referring to nssm. Since nssm is a wrapper, you technically tell nssm to manage your service.
If you want to verify if your installed service actually refers to your service, you will need to check that in nssm instead. You can do so with below command:
nssm edit <servicename>
Here you can see what is configured for your service and you can do some extra configuration here as well.
I hope that clarifies things a bit.
NSSM is a wrapper which responds to SCM commands... which a batch file won't.
When registering the service, ...service-start.bat is configured as a commandline arguments to the NSSM executable.

Windows service using nssm is working but not working with windows SC

I was supposed to convert a GoLang compiled file .exe as a service in windows but as the service was executed with 9 parameters from outside so I decided to use SC to make the .exe as a service and my syntax was ,
sc create myservice binPath= "\"PATH\file.exe\" -param1=value -param2=value -param3=value...-param9=value" displayname= "MyServer" start= auto
the service created successfully but when I try to start it, it fails with
"service did not respond in a timely fashion" ..
But When I created the same service with nssm syntax ,
nssm install myservice "PATH\file.exe" -param1=value -param2=value -param3=value...-param9=value
It was working and I was getting response from my service , I don't know whether the problem is with the syntax in SC or my service...
I even tried many possible ways like removing \" and giving parameters directly like binPath= "PATH/file.exe -param1=value -param2=value...param9=value"
but it didn't work and I also tried to pass the parameters inside quotes , It didn't work either :( Any help would be appreciated.
While SC will happily install any executable as a windows service, it should only be used to install executables that are already Windows Services. If you use SC to install a regular exe, your service will fail with Error 1053 when you try to start it. Your Go exe, which does not implement the Windows Service interface, falls victim to this situation.

Resources