## 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.