Installing a .NET Windows Service

You’ve written your service and now you want to install it but you’re having problems. Well have no fear, because I wasted valuable hours of my life re-figuring this out last night and will tell you everything you need to know.

Most instructions on the web simply tell you to run installutil against your executable. This sounds easy enough but has a couple of problems:

  1. Running installutil from a cmd window doesn’t work. 
  2. Once you run it, your windows service may or may not be properly configured for installutil.

To solve the first problem, run the Visual Studio 2008 Command Prompt which is located under Visual Studio 2008 in Start->All Programs.  To solve the second, you have to add an installer class to your service. (This is different from creating a deployment package.)  To add an installer class, follow these steps:

  1. Go to the designer view of your main class. (Probably service1.cs if you didn’t rename it.)
    Designer View 
  2. Right click in the gray area of the designer and click Add Installer.
    Add Installer 
  3. This will create a file called ProjectInstaller.cs and take you to the designer view of this file where you should see:
  4. Click on serviceProcessInstaller1 and in the properties pane, change Account to LocalSystem.
  5. Click on serviceInstaller1 and change Description, DisplayName and ServiceName to something descriptive. 
  6. Change StartType to whatever you service needs. (Manual, Disabled, or Automatic)

Now, simply install the service. From the Visual Studio 2008 Command Prompt run:

installutil "Whatever Your Executable Is Named.exe"

If it is successful you should see a message like:

The transacted install has completed.

That’s all there is to it.

  • Ali

    great work!!. Thanks for your efforts

  • Hanzdolo

    Oh you’re using 2008 that’s why the timer didn’t for without augmentation you might want to post my version for 2010 users