SEARCH

How-To Geek

Using SrvStart to Run Any Application as a Windows Service

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.

SrvStart Overview

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:

[Belvedere]
startup=”C:Program FilesBelvedereBelvedere.exe”
shutdown_method=winmessage

image

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.

image 

That’s it. If you check your Task Manager, you will both Belvedere.exe and srvstart.exe running.

image

Important Notes

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:

  1. Stop the service the application is running as.
  2. Open the application through it’s normal user interface.
  3. Make and apply your changes.
  4. Close the application running through the normal interface.
  5. 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.

image

And when running as a service, you will see no tray icon even though it is running in the background.

image

Conclusion

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.

Links

Download SrvStart by Nick Rozanski

Download Belvedere from Lifehacker

Jason Faulkner is a developer and IT professional who never has a hot cup of coffee far away. Interact with him on Google+

  • Published 07/15/10

Comments (3)

  1. Scott VanderPloeg

    The correct URL for SrvStart is:

    http://www.nick.rozanski.org.uk/software

  2. RWM

    I have a looping VBScript that I use to control when my children are allowed to use their computers. It is currently invoked at system startup. Could I use SrvStart to run it instead?

  3. Fred smith

    No! Not directly, SrvStart will only run files with extension .exe .com or .bat
    However to run a vb script for example my_script.vbs create a batch file my_script.bat with the following content:

    start my_script.vbs

    Start the batch file using SrvStart for example
    startup=”C:\full_path_to_script\my_script.bat”

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!