Installs an executable containing classes that extend ServiceBase. This class is called by installation utilities, such as InstallUtil.exe, when installing a service application.
Assembly: System.ServiceProcess (in System.ServiceProcess.dll)
Thetype exposes the following members.
|Account||Gets or sets the type of account under which to run this service application.|
|CanRaiseEvents||Gets a value indicating whether the component can raise an event. (Inherited from Component.)|
|Container||Gets the IContainer that contains the Component. (Inherited from Component.)|
|Context||Gets or sets information about the current installation. (Inherited from Installer.)|
|DesignMode||Gets a value that indicates whether the Component is currently in design mode. (Inherited from Component.)|
|Events||Gets the list of event handlers that are attached to this Component. (Inherited from Component.)|
|HelpText||Gets help text displayed for service installation options. (Overrides Installer.HelpText.)|
|Installers||Gets the collection of installers that this installer contains. (Inherited from Installer.)|
|Parent||Gets or sets the installer containing the collection that this installer belongs to. (Inherited from Installer.)|
|Password||Gets or sets the password associated with the user account under which the service application runs.|
|Site||Gets or sets the ISite of the Component. (Inherited from Component.)|
|Username||Gets or sets the user account under which the service application will run.|
|Commit||When overridden in a derived class, completes the install transaction. (Inherited from Installer.)|
|CopyFromComponent||Implements the base class ComponentInstaller.CopyFromComponent method with no class-specific behavior. (Overrides ComponentInstaller.CopyFromComponent(IComponent).)|
|CreateObjRef||Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)|
|Dispose||Releases all resources used by the Component. (Inherited from Component.)|
|Dispose(Boolean)||Releases the unmanaged resources used by the Component and optionally releases the managed resources. (Inherited from Component.)|
|Equals(Object)||Determines whether the specified object is equal to the current object. (Inherited from Object.)|
|Finalize||Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection. (Inherited from Component.)|
|GetHashCode||Serves as the default hash function. (Inherited from Object.)|
|GetLifetimeService||Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)|
|GetService||Returns an object that represents a service provided by the Component or by its Container. (Inherited from Component.)|
|GetType||Gets the Type of the current instance. (Inherited from Object.)|
|InitializeLifetimeService||Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)|
|Install||Writes service application information to the registry. This method is meant to be used by installation tools, which call the appropriate methods automatically. (Overrides Installer.Install(IDictionary).)|
|IsEquivalentInstaller||Determines if the specified installer installs the same object as this installer. (Inherited from ComponentInstaller.)|
|MemberwiseClone||Creates a shallow copy of the current Object. (Inherited from Object.)|
|MemberwiseClone(Boolean)||Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)|
|OnAfterInstall||Raises the AfterInstall event. (Inherited from Installer.)|
|OnAfterRollback||Raises the AfterRollback event. (Inherited from Installer.)|
|OnAfterUninstall||Raises the AfterUninstall event. (Inherited from Installer.)|
|OnBeforeInstall||Raises the BeforeInstall event. (Inherited from Installer.)|
|OnBeforeRollback||Raises the BeforeRollback event. (Inherited from Installer.)|
|OnBeforeUninstall||Raises the BeforeUninstall event. (Inherited from Installer.)|
|OnCommitted||Raises the Committed event. (Inherited from Installer.)|
|OnCommitting||Raises the Committing event. (Inherited from Installer.)|
|Rollback||Rolls back service application information written to the registry by the installation procedure. This method is meant to be used by installation tools, which process the appropriate methods automatically. (Overrides Installer.Rollback(IDictionary).)|
|ToString||Returns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from Component.)|
|Uninstall||When overridden in a derived class, removes an installation. (Inherited from Installer.)|
|AfterInstall||Occurs after the Install methods of all the installers in the Installers property have run. (Inherited from Installer.)|
|AfterRollback||Occurs after the installations of all the installers in the Installers property are rolled back. (Inherited from Installer.)|
|AfterUninstall||Occurs after all the installers in the Installers property perform their uninstallation operations. (Inherited from Installer.)|
|BeforeInstall||Occurs before the Install method of each installer in the installer collection has run. (Inherited from Installer.)|
|BeforeRollback||Occurs before the installers in the Installers property are rolled back. (Inherited from Installer.)|
|BeforeUninstall||Occurs before the installers in the Installers property perform their uninstall operations. (Inherited from Installer.)|
|Committed||Occurs after all the installers in the Installers property have committed their installations. (Inherited from Installer.)|
|Committing||Occurs before the installers in the Installers property committ their installations. (Inherited from Installer.)|
|Disposed||Occurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)|
The 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 instance per service application, and one ServiceInstaller instance for each service in the application. Finally, add the 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 , 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.
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 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 causes the base class constructor, ComponentInstaller, to be called.
The following example creates a project installer called MyProjectInstaller, which inherits from Installer. It is assumed there is a service executable that contains two services, "Hello-World Service 1" and "Hello-World Service 2". Within the constructor for MyProjectInstaller (which would be called by the install utility), ServiceInstaller objects are created for each service, and a is created for the executable. For the install utility to recognize MyProjectInstaller as a valid installer, the RunInstallerAttribute attribute is set to true.
Optional properties are set on the process installer and the service installers before the installers are added to the Installers collection. When the install utility accesses MyProjectInstaller, the objects added to the Installers collection through a call to InstallerCollection.Add will be installed in turn. During the process, the installer maintains state information indicating which objects have been installed, so each object can be backed out in turn in case of an installation failure.
Normally, you would not instantiate your project installer class explicitly. You would create it and add the RunInstallerAttribute, but the install utility actually calls, and therefore instantiates, the class.
Imports System Imports System.Collections Imports System.Configuration.Install Imports System.ServiceProcess Imports System.ComponentModel <RunInstallerAttribute(True)> _ Public Class MyProjectInstaller Inherits Installer Private serviceInstaller1 As ServiceInstaller Private serviceInstaller2 As ServiceInstaller Private processInstaller As ServiceProcessInstaller Public Sub New() ' Instantiate installers for process and services. processInstaller = New ServiceProcessInstaller() serviceInstaller1 = New ServiceInstaller() serviceInstaller2 = New ServiceInstaller() ' The services will run under the system account. processInstaller.Account = ServiceAccount.LocalSystem ' The services will be started manually. serviceInstaller1.StartType = ServiceStartMode.Manual serviceInstaller2.StartType = ServiceStartMode.Manual ' ServiceName must equal those on ServiceBase derived classes. serviceInstaller1.ServiceName = "Hello-World Service 1" serviceInstaller2.ServiceName = "Hello-World Service 2" ' Add installers to collection. Order is not important. Installers.Add(serviceInstaller1) Installers.Add(serviceInstaller2) Installers.Add(processInstaller) End Sub Public Shared Sub Main() Console.WriteLine("Usage: InstallUtil.exe [<service>.exe]") End Sub End Class
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)