Windows Service management
To run a batch file or program as a service, you need an intermediate tool.
https://nssm.cc/ does all you need for your services. It’s free and open source. There exists a repository on Github with this name, but it is not managed by the author of the app. So, avoid it.
Install a service
nssm.exe install "service-name"
, which will open a GUI to configure the service.
Later, you can edit the service by using: nssm.exe edit "service-name"
.
To see list of services on a Windows machine, the official tool is services.msc
. Nssm is convenient because you can manage any service from the machine.
Configure a service
Select which file you want to run, from where, and optional arguments.
Service restart
Nssm can automatically restarts a finished (or crashed) service. This is the default setting.
I/O redirection
Nssm can log output of your service in a given file. It’s convenient to debug issues.
User credentials
By default, your service runs on local SYSTEM account. If you need administrator access, simply create a user with those rights, and then use this account to run service: