How to: Creating a Custom Action using windows Service in C#
Visual Studio 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. |
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 How to: Configure 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.
Note |
---|
The
dialog boxes and menu commands you see might differ from those
described in Help depending on your active settings or edition. To
change your settings, choose Import and Export Settings on the Tools menu. For more information, see Visual Studio Settings. |
To add installers to your service application
- In Solution Explorer, access Design view for the service for which you want to add an installation component.
- Click the background of the designer to select the service itself, rather than any of its contents.
- With the designer in focus, right-click, and then click Add Installer.
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.
- 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.
- To determine how your service will be started, click the ServiceInstaller component and set the StartType property to the appropriate value.
Value Result Manual
The service must be manually started after installation. For more information, see How to: Start Services.
Automatic
The service will start by itself whenever the computer reboots.
Disabled
The service cannot be started.
- 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 How to: Specify the Security Context for Services.
- Override any methods for which you need to perform custom processing. For more information, see How to: Override Default Methods on Installation Components.
- Perform steps 1 through 7 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.
- 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
0 comments:
Post a Comment