Επεξεργασία

Κοινή χρήση μέσω


ServiceInstaller.Install(IDictionary) Method

Definition

Installs the service by writing service application information to the registry. This method is meant to be used by installation tools, which process the appropriate methods automatically.

public:
 override void Install(System::Collections::IDictionary ^ stateSaver);
public override void Install (System.Collections.IDictionary stateSaver);
override this.Install : System.Collections.IDictionary -> unit
Public Overrides Sub Install (stateSaver As IDictionary)

Parameters

stateSaver
IDictionary

An IDictionary that contains the context information associated with the installation.

Exceptions

The installation does not contain a ServiceProcessInstaller for the executable.

-or-

The file name for the assembly is null or an empty string.

-or-

The service name is invalid.

-or-

The Service Control Manager could not be opened.

The display name for the service is more than 255 characters in length.

The system could not generate a handle to the service.

-or-

A service with that name is already installed.

Remarks

Normally, you will not call the methods on ServiceInstaller within your code; they are generally called only by the install utility. The install utility automatically calls the Install method during installation. It backs out failures, if necessary, by calling Rollback on the object that generated the exception.

An application's install routine maintains information automatically about the components that were already installed, using the project installer's Installer.Context. This state information, passed into Install as the stateSaver parameter, is continuously updated as the ServiceProcessInstaller instance and each ServiceInstaller instance is installed by the utility. It is usually unnecessary for your code to modify this state information explicitly.

The ServiceProcessInstaller associated with your project installation class installs information common to all ServiceInstaller instances in the project. If this service has anything that separates it from the other services in the installation project, that service-specific information is installed by this method.

To install a service, create a project installer class that inherits from the Installer class, and set the RunInstallerAttribute attribute on the class to true. Within your project, create one ServiceProcessInstaller instance per service application, and one ServiceInstaller instance for each service in the application. Within your project installer class constructor, set the installation properties for the service using the ServiceProcessInstaller and ServiceInstaller instances, and add the instances to the Installers collection.

Note

It is recommended that you use the constructor for adding installer instances; however, if you need to add to the Installers collection in the Install method, be sure to perform the same additions to the collection in the Uninstall method.

For all classes deriving from the Installer class, the state of the Installers collection must be the same in the Install and Uninstall methods. However, you can avoid the maintenance of the collection across the Install and Uninstall methods if you add installer instances to the Installers collection in your custom installer class constructor.

Applies to

See also