Run batch file as a Windows service Run batch file as a Windows service windows windows

Run batch file as a Windows service


NSSM is totally free and hyper-easy, running command prompt / terminal as administrator:

nssm install "YourCoolServiceNameLabel"

then a dialog will appear so you can choose where is the file you want to run.

to uninstall

nssm remove "YourCoolServiceNameLabel"


Why not simply set it up as a Scheduled Task that is scheduled to run at start up?


There's a built in windows cmd to do this: sc create. Not as fancy as nssm, but you don't have to download an additional piece of software.

sc create "ServiceName" start= demand displayname= "DisplayName" binpath= [path to .bat file]

Note

  • start=demand means you must start the service yourself
  • whitespace is required after =
  • I did encounter an error on service start that the service did not respond in a timely manner, but it was clear the service had run the .bat successfully. Haven't dug into this yet but this thread experienced the same thing and solved it using nssm to install the service.