NSSM will not pickup executable directory - windows

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.

Related

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: Can't edit a service I created

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

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.

install a jar with a servicename

I have to start, stop a jar in a flow
1. I have to stop it if it is already running and then start
2. All this is being worked in Udeploy.
3. I'm installing the jar using the below command.
java -jar jarname.jar
When I use sc query servicename, it says the service is not installed as a Windows service. So, I can check, stop and start if it is only a windows service.
How can I install this as a windows service with a servicename to identify ?
You can use nssm to install a jar as a Windows service. No installation of nssm is needed. Just place it somewhere on the system (preferably somewhere in your PATH) and run it.
Here is the command to execute as a batch:
nssm.exe install "(service-name)" "{java.exe path from jre}" "-jar
{jar-name-absolute-path}"
nssm.exe set "{service-name}" AppDirectory "{jar-path}"

How to uninstall a Windows Service when there is no executable for it left on the system?

How do I uninstall a Windows Service when there is no executable for it left on the system? I can not run installutil -u since there is not executable left on the system. I can still see an entry for the service in the Services console.
The reason for this state is probably because of a problem in the msi package that does not remove the service correctly, but how do I fix it once the service is in this state?
You should be able to uninstall it using sc.exe (I think it is included in the Windows Resource Kit) by running the following in an "administrator" command prompt:
sc.exe delete <service name>
where <service name> is the name of the service itself as you see it in the service management console, not of the exe.
You can find sc.exe in the System folder and it needs Administrative privileges to run. More information in this Microsoft KB article.
Alternatively, you can directly call the DeleteService() api. That way is a little more complex, since you need to get a handle to the service control manager via OpenSCManager() and so on, but on the other hand it gives you more control over what is happening.
Remove Windows Service via Registry
Its very easy to remove a service from registry if you know the right path. Here is how I did that:
Run Regedit or Regedt32
Go to the registry entry "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services"
Look for the service that you want delete and delete it. You can look at the keys to know what files the service was using and delete them as well (if necessary).
Delete Windows Service via Command Window
Alternatively, you can also use command prompt and delete a service using following command:
sc delete
You can also create service by using following command
sc create "MorganTechService" binpath= "C:\Program Files\MorganTechSPace\myservice.exe"
Note: You may have to reboot the system to get the list updated in service manager.
Here is the powershell script to delete a service foo
$foo= Get-WmiObject -Class Win32_Service -Filter "Name='foo'"
$foo.delete()
found here
I just tried on windows XP, it worked
local computer:
sc \\. delete [service-name]
Deleting services in Windows Server 2003
We can use sc.exe in the Windows Server 2003 to control services, create services and delete services. Since some people thought they must directly modify the registry to delete a service, I would like to share how to use sc.exe to delete a service without directly modifying the registry so that decreased the possibility for system failures.
To delete a service:
Click “start“ - “run“, and then enter “cmd“ to open Microsoft Command Console.
Enter command:
sc servername delete servicename
For instance, sc \\dc delete myservice
(Note: In this example, dc is my Domain Controller Server name, which is not the local machine, myservice is the name of the service I want to delete on the DC server.)
Below is the official help of all sc functions:
DESCRIPTION:
SC is a command line program used for communicating with the
NT Service Controller and services.
USAGE:
sc
My favourite way of doing this is to use Sysinternals Autoruns application. Just select the service and press delete.
I'd use PowerShell for this
Remove-Service -Name "TestService"
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/remove-service
Create a copy of executables of same service and paste it on the same path of the existing service and then uninstall.

Resources