# How do I run a Windows command as a service?

I'm using Windows 7. I run this command in a command prompt to start a memcached server:

memcached.exe -d start


However, I would like to set things up to run this command automatically when my computer restarts. How do I set that up?

If the application does not access the interface, you can do it via task scheduler. Set the application to run at boot from a user account that has enough access to run the program.

Outside of that, search for the Windows 2003 Resource Kit, and within that are two programs srvany.exe and instsrv.exe that can be used for making an app a service. The should run fine on Windows 7 machines.

• If you really want it to run from the Windows service framework and are considering srvany.exe - nssm.cc - NSSM does what srvany.exe does but a bit better. Sep 29, 2020 at 17:01

There are a few approaches.

I recommend using the "Service Control" application, because it fully integrates with the services.msc control panel, so it can be run under an arbitrary user, and autostarted with the system. It can cause load-time issues though, so perhaps the starting as "Automatic (delayed)" is a good idea, to ensure that required services have already loaded.

sc \\localhost create <newservicename> binpath= c:\path\to\service.exe


The task Scheduler is another good option, - as @DavidPostill suggested - if you don't need the system to recognize the exe as a service. Task scheduler has a lot of good configuration options.

Some folks recommend alternative service managers like NSSM: http://nssm.cc/