SEARCH

How-To Geek

How to Run Any Program as a Background Service in Windows

aas_top

If you’re like most Windows users, you have lots of great little utilities that run when you start Windows. While this works great for most apps, there are some that would be nice to start even before a user logs in to the PC. To do this, you’ll need to run the app as a Windows service.

RELATED ARTICLES
Understanding and Managing Windows Services
In today’s Geek School lesson, we’re going to teach you about Windows Services and how to manage them using the... [Read Article]
Should You Disable Windows Services to Speed Up Your PC?
Windows comes with a bunch of services running in the background. The Services.msc tool allows you to view these services... [Read Article]

Windows services are a special class of programs that are configured to launch and run in the background, usually without any sort of user interface and without needing a user to log in to the PC. Many gamers and power users know them as those things you used to disable to help speed up your system, though that’s really not necessary any more.

The primary advantage of running an app as a service is that you can have a program start before a user to log in. That can be particularly important with apps that provide important services you want to be available when you’re away from your computer.

A perfect example of this is Plex, a media server app that can stream local content to just about any device you own. Sure, you could let it sit in the system tray like a normal program, but what if the computer restarts due to a power outage or scheduled updates? Until you log back in on the PC, Plex wouldn’t be available. That’s irritating if you have to run to another room to start Plex back up while your popcorn gets cold, and super irritating if you’re out of town and trying to stream your media over the Internet. Setting up Plex as a Service would solve that problem.

Before getting started, you should be aware of a couple of important caveats to running an app as a service:

  • The app will not put an icon in the system tray. If you need the interface available regularly for an app, it may not be best suited to run as a service.
  • When you need to make configuration changes or updates, you’ll need to stop the service, run the program as a regular app, do what you need to do, stop the program, and then start the service again.
  • If the program is already set up to run when Windows starts, you’ll need to disable that so that you don’t end up with two instances running. Most programs have an option in the interface for toggling this setting. Others may add themselves to your Startup folder, so you can remove them there.

Ready to roll? Let’s talk about how to set it up.

Step One: Install SrvStart

To run an app as a service, you’re going to need a small, third-party utility. There are several out there, but our favorite is SrvStart. It was originally designed for Windows NT, and will work with just about any version of Windows from Windows XP on up.

To get started, head over to the SrvStart download page and grab the utility. The download contains just four files (two DLL and two EXE files). There’s no installer; instead, copy these to your computer’s C:\Windows folder these to your main Windows folder to “install” SrvStart.

aas_4

We’re also going to assume that you’ve already installed and set up whatever program you’re going to turn into a service, but if you haven’t, now would be a good time to do that too.

Step Two: Create a Configuration File for the New Service

Next, you’ll want to create a configuration file that SrvStart will read to create the service. There’s a lot you can do with SrvStart, and you can read the full details on all the configuration options on the documentation page. For this example, we are only going to use two commands: startup, which specifies the program to launch, and shutdown_method, which tells SrvStart how to close the program when the respective service is stopped.

Fire up Notepad and create your configuration file using the format below. Here, we’re using Plex, but you can create a file for any program you want to run as a service. The startup command simply specifies the path where the executable file resides. For the shutdown_method command, we’re using the winmessage parameter, which causes SrvStart to send a Windows close message to any windows opened by the service.

[Plex]
startup="C:\Program Files (x86)\Plex\Plex Media Server\Plex Media Server.exe"
shutdown_method=winmessage

Obviously, adjust the path and name according to the program you’re launching.

aas_1_v2

Save the new configuration file wherever you like, and replace the .txt extension with a .ini extension. Make note of the file name, since we’ll need it in the next step. For ease of typing at the Command Prompt, we suggest saving this file temporarily right on your C: drive.

Step Three: Use the Command Prompt to Create the New Service

Your next step is using the Windows Service Controller (SC) command to create the new service based on the criteria in your configuration file. Open Command Prompt by right-clicking the Start menu (or pressing Windows+X), choosing “Command Prompt (Admin)”, and then clicking Yes to allow it to run with administrative privileges.

tl_start

At the Command Prompt, use the following syntax to create the new service:

SC CREATE <servicename> Displayname= "<servicename>" binpath= "srvstart.exe <servicename> -c <path to srvstart config file>" start= <starttype>

There are a couple of things to note in that command. First, each equal sign (=) has a space after it. That’s required. Also, the <servicename> value is entirely up to you. And, finally, for the <starttype> value, you’ll want to use auto so that the service starts automatically with Windows.

So in our Plex example, the command would look like this:

SC CREATE Plex Displayname= "Plex" binpath= "srvstart.exe Plex -c C:PlexService.ini" start= auto

Yes, you read that right: I used C:PlexService.ini instead of C:\PlexService.ini . The command requires you to remove the slash.

When you run the command, you should receive a SUCCESS message if everything goes well.

aas_2

From this point on, your new service will run whenever Windows starts. If you open the Windows Services interface (just click Start and type “Services”), you can find and configure the new service just like you would any other.

aas_3

And that’s all there is to it. If you have apps that start with Windows and you’d rather they start without needing a user to log in, it’s easy enough to turn any app into a service. We’ve only just touched on the basic method for creating and running a new service, but there’s a lot more you can do with SrvStart to fine tune how a service runs. Be sure to check out the documentation if you’d like to learn more.

Walter Glenn is a long time computer geek and tech writer. Though he's mostly a Windows and gadget guy, he has a fondness for anything tech. You can follow him on Facebook and Twitter.

  • Published 05/4/16
  • Andrey

    In modern versions of Windows, above VISTA, if you need have a program start before a user to log in or even if no user is logged in, you can use Task Scheduler too. If you set the task to interact with the desktop, you will not have the caveats you have when running as a service.

  • Tim Malloroy

    Without a description, other users may not understand usage of the service and potentially think it's malware. A clarifying description can be added to the service with the command:

    SC DESCRIPTION "<servicename>" "<description>"

    Example:

    SC DESCRIPTION Plex "Multimedia streaming application installed by Walter Glenn"

  • David White

    I have tried this method w/o success many times using EVGA's Precision tool. All I get is an error 1067. I have tried this on MANY PCs running W7 mostly but also other MS OSs gave same response.DW.

  • DMcCunney

    There are four places where Windows looks for apps to run on startup. There are startup folders for the logged in user, and for all users. Apps can also be run from the HK Local Machine and HK Current User registry hives.

    For stuff that I need active when Windows first boots, I normally put it in the HKLM registry startup list. An example is ext2 Volume Manager, an open source driver that adds access to Linux ext file systems. I dual boot Windows and Ubuntu, and my drive is partitioned with a slice formatted as ext4. Linux can see the Windows NTFS file system through ntfs-3g, and with the ext2 driver, Windows can see the Ubuntu slice.

    I still use an ancient utility from Mike Lin called Startup that displays what is loaded on Windows boot, and where it's loaded from. I can change the location where the startup entry is, like moving it from the user startup folder to the registry, edit the startup properties, create new entries, delete them, or leave an entry in place but disable it from running on startup. There are other utilities that will do this, like Sysinternals Autoruns, but Startup works and I've been using it since the Win2K days.

    I've never needed to make an app a service to do what is intended here. I'd be curious to know about apps that do require this treatment.

    >Dennis

  • Roy Whelan

    Is it possible to tell the config file to supply credentials and automatically login to the app.

    I have a n application that requires a login. I can use this to run it as a service but can I also login to the app with the config file?

  • Walter Glenn

    @Roy_Whelan: You can try opening up the properties of the service (in the Services app) after you create it. There's a log on tab there you can use to let the app log on with your Windows user account.

  • Jacob

    My favorit is nssm, which does not need ini files and nor peculiarities on the cmd line.And it stands for non sucking service manager, I'd say that is correct.