There are lots of great utilities out there which do essential tasks such as monitoring and reporting that once you have configured them, they just sit in your system tray and do their job without you ever knowing. While this works great for desktop machines, this model is not ideal for server use which, typically, does not have anyone actively logged into it.
The solution is to run the application as a Windows Service which runs in the background regardless of whether or not a user is logged in. This article will show you how to run any application as a background service using the free tool, SrvStart.
Simply put, SrvStart allows you to run any application as a Windows Service. While the vast majority of applications are not suited for this type of deployment (i.e. Notepad, Microsoft Word, etc.), there are lots of utilities which can run seamlessly as a background service. By interfacing with the Windows Service Manager, SrvStart “interprets” the Operating System commands, such as start (open) and stop (close), and sends them to the target application which doesn’t know the difference.
Much like the Microsoft tool, SrvAny, SrvStart was developed for Windows NT but still works on the newest operating systems (we are using Server 2008 for our walkthrough). The different between Microsoft’s SrvAny and SrvStart is that SrvStart is much more configurable. For example, stopping a service controlled by SrvAny is essentially the same as killing (think Ctrl+Alt+Del) the respective application where SrvStart can send a close message to the application so it can shut down gracefully.
Configuring an Application to Run as a Windows Service
For our example we are going to use the Lifehacker utility, Belvedere which is a file system watchdog which automates file actions such as moving and renaming when certain events or time limits occur. So when this program is configured as needed, it can run completely in the background as a Windows Service and function exactly the same as if it was running in your system tray. Again, for servers this is ideal because the vast majority of the time, users are not logged in.
Before configuring the service, you must first install the target program (obviously) and then configure it as needed. For the purposes of this article, we are not going to discuss the configuration of Belvedere (it is covered well on their download page). Next we need to copy the three SrvStart required files (srvstart.exe, srvstart.dll, logger.dll) to the Windows directory so they can be referenced without issue.
Finally, we need to create the configuration file which SrvStart will read to launch the application. You can read the full details on all the configuration options on SrvStart’s page, however we are only going to use the ‘startup’ (the only option truly required) command which specifies the program to launch and ‘shutdown_method’ which tells SrvStart how to close the program when the respective service is stopped.
Our configuration file is saved as “C:BelvedereService.ini” and looks like this:
So with the application configuration completed, we use the built in Windows “SC” command to add a new Windows Service. Run the following from the command prompt (note – there is a space after each equal sign, this is required):
SC CREATE Belvedere DisplayName= “Belvedere” binPath= “srvstart.exe Belvedere -c C:BelvedereService.ini” start= auto
SC DESCRIPTION Belvedere “Automated file manager.”
With the service created, it will now appear in the Windows Services list and can be configured like any other Windows Service. Before starting the service, close Belvedere if you have it open.
That’s it. If you check your Task Manager, you will both Belvedere.exe and srvstart.exe running.
One thing to keep in mind is that when the application is running as a service, it has no interface. This means you cannot see or respond to message boxes and prompts raised by the program. Additionally, you cannot make configuration changes on the fly. When you need to make changes, you have to do the following:
- Stop the service the application is running as.
- Open the application through it’s normal user interface.
- Make and apply your changes.
- Close the application running through the normal interface.
- Start the service.
It is important to keep “gotcha” type of things in mind as you are essentially running an interface application without using the interface. For Belvedere, when the typical interface mode is running, you will see the icon available in the system tray.
And when running as a service, you will see no tray icon even though it is running in the background.
While we have demonstrated turning an application into a service with a file monitoring utility, this same procedure can be applied to anything from hardware monitors to report generators. Be creative as this has lots of uses.
As mentioned previously, we are using SrvStart with only the most basic configuration. Although this is probably all you need the majority of the time, it is good to keep in mind that SrvStart has many other settings you can use to fine tune how the program runs in service mode.
- Published 07/15/10