How To Add A Custom Windows Service

Sometimes you’ll run across an instance where a particular program you need to run as a service, instead of launching every time someone logs in (server applications are a good example).

These are the files that you’ll need for Windows 2000-2003:

  1. Instrsrv.exe  – This installs and removes system services.
  2. Srvany.exe – This allows any Windows application to run as a service.

You can download both files here: srvany.zip

First you’ll need to goto the path within the command prompt (Start > Run > cmd.exe) to where you unzipped the attached files, and then run:


instsrv.exe "My Service Name" c:\FULL_PATH\TO\srvany.exe

This function creates the appropriate windows registry entries.

 

Next you’ll want to start the registry editor and enter the appropriate values (Start > Run > regedit.exe).  WARNING: Editing the registry runs the risk of disaster.  Continue at your own risk.

  1. Navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\My Service Name
  2. Add a Key, and call it Parameters, and then navigate to it.
  3. Add a String Value, and call it Application.  Enter the full path to your application’s executable file, and surround it with quotation marks (ie, “c:\Program Files\Cool Program\Cool Program.exe”)
  4. Add a String Value, and call it AppDirectory.  Enter the full path to your application’s folder, and surround it with quotation marks (ie, “c:\Program Files\Cool Program”)
  5. Add a String Value, and call it AppParameters.  Add any optional parameters your program requires.
  6. Close the registry editor

Now you must goto the Windows Services Manager to start the service.

  1. Goto Start > Control Panel > Administrative Tools > Services
  2. Locate your custom service, and start the service

This entry was posted in Windows and tagged , , . Bookmark the permalink.

Comments are closed.