April 19, 2010

Installing Windows Services

A Windows Service is a program that runs in the background of any Windows installation. These are similar to Daemon processes in Unix. The programs are designed not to have any user interaction and be long running.

The project I am working on right now uses a Windows service to broadcast webcam video over the internet, emulating an IP Camera. Using laptops, webcams and a Window service allows a client application to view webcam video from multiple sources at the same time.

Developing the Service Application
This is not the focus of the post, but it is important to recognize where Windows services are built. Windows services are available as a project template in Visual Studio 2008. The screenshot below shows the Window Service project type.

Windows services cannot be run and debugged like any other .NET project. The project did not require extensive testing, but more information would be needed if the Windows service needed to be tested before deployment.

Installing the Service

To install the service, use a command line tool called "installutil.exe." There should be an executable in the "C:\Windows\System32" directory. If it is not there, make a copy of it from another location and paste it into the System32 directory.

Run the command prompt as an administrator and the shell will open in the System32 directory. The following command installs a Windows service from the command line:
installutil "C:\path\to\the\service\executable"
Make sure that the path to the executable is memorable to make things less confusing when uninstalling. To uninstall the service, use the same command but insert a /uninstall between installutil and the path.

To start the service, type the following into the command window:
net start ServiceName
ServiceName is the name of the service in Visual Studio. Do not confuse the path to the executable with the ServiceName. To stop the service, use the same command as above with stop instead of start.

The newly started service should be in the list of locally running services. Navigate to Control Panel\System and Maintenance\Administrative Tools\Services to see the list of running services. Services can also be started and stopped with this interface.


  1. I think services CAN be stopped and started from the GUI. Is that what you meant to say in that last paragraph?

  2. Republished - That is what I meant to say. Thanks for the catch Nate.

  3. That's an essential part of the eval system's deploy process. There's a way to create these ruby-style, but I can't remember. Google it.

  4. I ran into some issues deploying a service with installutil.exe on a Windows XP machine. It turns out that I was using the wrong version of installutil. Be sure to grab the latest version of the executable. You need the latest version to deploy the latests services, so if a service was built in .NET 3.5, the .NET 1.0 installutil (what I was using) will not work. It returns an error:
    Exception occurred while initializing the installation:

    System.BadImageFormatException: The format of the file "Executable.exe" is invalid...