The ServiceProcessInstaller does work common to all services in an executable. It is used by the installation utility to write registry values associated with services you want to install.
To install a service, create a project installer class that inherits from Installer, and set the RunInstallerAttribute on the class to true. Within your project, instantiate one ServiceProcessInstaller instance per service application, and one ServiceInstaller instance for each service in the application. Finally, add the ServiceProcessInstaller instance and the ServiceInstaller instances to your project installer class.
When InstallUtil.exe runs, the utility looks for classes in the service assembly with the RunInstallerAttribute set to true. Add classes to the service assembly by adding them to the Installers collection associated with your project installer. If RunInstallerAttribute is false, the install utility ignores the project installer.
For an instance of ServiceProcessInstaller, properties you can modify include specifying that a service application run under an account other than the logged-on user. You can specify a particular Username and Password pair under which the service should run, or you can use Account to specify that the service run under the computer's System account, a local or network service account, or a user account.
Note: |
|---|
The computer's System account is not the same as the Administrator account.
|
Normally, you do not call the methods on ServiceInstaller within your code; they are generally called only by the install utility. The install utility automatically calls the ServiceProcessInstaller..::.Install and ServiceInstaller..::.Install methods during the installation process. It backs out failures, if necessary, by calling Rollback (or ServiceInstaller..::.Rollback) on all previously installed components.
An application's install routine maintains information automatically about the components already installed, using the project installer's Installer..::.Context. This state information 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.
Instantiating a ServiceProcessInstaller causes the base class constructor, ComponentInstaller, to be called.