Hack It #2 – Convert any Windows application to a service

I recently had to convert a C++ application to run as a service, so that it could always run in the background. This application was supposed to already be capable of doing this, but instead would crash instantly.

Rather than going into the code and figuring out why that would be, I decided that someone would have written a wrapper to convert any application into a service. It turns out there is such a wrapper, and it’s called srvany.exe.

Here is how to convert any Windows application to run as a service.

By the way, if your application is Java based, there is a specific Java Service Wrapper so you probably should go there instead of reading these instructions. This is for generic executable or batch files.

Download and install the NT Resource Kit

The files you are going to need from this:

  • srvany.exe
  • instsrv.exe

Install the srvany service

  • Run the command: instsrv service_name [path]\srvany.exe, where service_name is the name of your service

Configure the new service

  • Run regedit
  • Browse to HKEY_LOCAL_MACHINE\ SYSTEM\ CurrentControlSet\ Services\ service_name
  • Add key “Parameters”
  • Right click on “Parameters”
  • New string value, “Application”, with the value as the executable you want to run, including any parameters.
  • If your application is not an executable, bat a batch file, set the value to “C:\Windows\system32\cmd.exe /k full_path_to_batch_file.bat”
  • Of course the batch file or executable can’t exit, as this will end the service.

And some more configuration

  • Control Panel, Administration, Services, find your service.
  • The default is “Automatic”, which means as long as nothing goes wrong, your service will always be running. You might want to change this.
  • You might want to set the service to run as something other than “Local Service”, e.g. have it run under your name.

Test It

  • Start the service
  • Your application should appear in task manager


Now you can have something run all the time, behind the scenes, as a service. Hurrah!

5 Responses to “Hack It #2 – Convert any Windows application to a service”

  1. Vidyut says:

    Hi Sir! This was VERY helpful .. but I wanted to enquire – can we have multiple exe files under a single process ?
    It may sound a stupid question, but i am new to the field.

  2. peter says:

    Hi Vidut – you’re probably best to create separate services if you want more than one exe to run simultaneously.

  3. saddam Escap says:

    Hi Sir !
    Thank you for this very helpful toturial
    but I went to create service that accept parameters periodically to do something Can I
    thank in advance

  4. reo says:

    Hi sir,

    Will this work on Windows 7 x64? Because I got this error as I type the command.

    “Unable to find the file at the given path.”

    This is what I typed

    instsrv myprogram C:\Program Files (x86)\Windows Resource Kits\

    I’m pretty sure that I got the correct directory..

    I hope you can help me figure this out. Thank you and have a good one..

  5. peter says:

    Hi Reo – try putting C:\Program Files… in quotes.

    i.e. instsrv myprogram “C:\Program Files…\srvany.exe”

    Hope that helps!

Leave a Reply