This documentation is archived and is not being maintained.

Adding Installers to your Service Application

Visual Studio .NET 2003

Visual Studio .NET ships installation components that can install resources associated with your service applications. Installation components register an individual service on the system to which it is being installed and let the Services Control Manager know that the service exists. When you work with a service application, you can select a link in the Properties window to automatically add the appropriate installers to your project. For more information on installation components and how they work, see Introduction to Installation Components.

Note   Property values for your service are copied from the service class to the installer class. If you update the property values on the service class, they are not automatically updated in the installer.

When you add an installer to your project, a new class (which, by default, is named ProjectInstaller) is created in the project, and instances of the appropriate installation components are created within it. This class acts as a central point for all of the installation components your project needs. For example, if you add a second service to your application and click the Add Installer link, a second installer class is not created; instead, the necessary additional installation component for the second service is added to the existing class.

You do not need to do any special coding within the installers to make your services install correctly. However, you may occasionally need to modify the contents of the installers if you need to add special functionality to the installation process. For more information, see Configuring Installation Components.

After you add installers to your application, the next step is to create a setup project that will install the compiled project files and run the installers needed to install your service. To create a complete setup project, you must add the service project's output to the setup project and then add a custom action to have your service installed. For more information on setup projects, see Setup Projects. For more information on custom actions, see Walkthrough: Creating a Custom Action.

To add installers to your service application

  1. In Solution Explorer, access Design view for the service for which you want to add an installation component.
  2. Click anywhere within the designer's surface.
  3. In the Description area of the Properties window, click the Add Installer link.

    A new class, ProjectInstaller, and two installation components, ServiceProcessInstaller and ServiceInstaller, are added to your project, and property values for the service are copied to the components.

  4. Click the ServiceInstaller component and verify that the value of the ServiceName property is set to the same value as the ServiceName property on the service itself.
  5. To determine how your service will be started, click the ServiceInstaller component and set the StartType property to the appropriate value.
    ManualThe service must be manually started after installation. For more information, see Starting Services.
    AutomaticThe service will start by itself whenever the computer reboots.
    DisabledThe service cannot be started.
  6. To determine the security context in which your service will run, click the ServiceProcessInstaller component and set the appropriate property values. For more information, see Specifying the Security Context for Services.
  7. Override any methods for which you need to perform custom processing. For more information, see Overriding Default Methods on Installation Components.
  8. Perform steps 1 through 6 for each additional service in your project.
    Note   For each additional service in your project, you must add an additional ServiceInstaller component to the project's ProjectInstaller class. The ServiceProcessInstaller component added in step three works with all of the individual service installers in the project.
  9. Create your setup project and custom action to deploy and install your service. For more information on setup projects, see Setup Projects. For more information on custom actions, see Walkthrough: Creating a Custom Action.

See Also

Introduction to Windows Service Applications | Installing and Uninstalling Services | Starting Services | Specifying the Security Context for Services | Introduction to Installation Components | Configuring Installation Components | Overriding Default Methods on Installation Components