Installer Class

Provides the foundation for custom installations.

Namespace:  System.Configuration.Install
Assembly:  System.Configuration.Install (in System.Configuration.Install.dll)

public class Installer : Component

The Installer type exposes the following members.

Public methodInstallerInitializes a new instance of the Installer class.

Protected propertyCanRaiseEventsGets a value indicating whether the component can raise an event. (Inherited from Component.)
Public propertyContainerGets the IContainer that contains the Component. (Inherited from Component.)
Public propertyContextGets or sets information about the current installation.
Protected propertyDesignModeGets a value that indicates whether the Component is currently in design mode. (Inherited from Component.)
Protected propertyEventsGets the list of event handlers that are attached to this Component. (Inherited from Component.)
Public propertyHelpTextGets the help text for all the installers in the installer collection.
Public propertyInstallersGets the collection of installers that this installer contains.
Public propertyParentGets or sets the installer containing the collection that this installer belongs to.
Public propertySiteGets or sets the ISite of the Component. (Inherited from Component.)

Public methodCommitWhen overridden in a derived class, completes the install transaction.
Public methodCreateObjRefCreates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)
Public methodDispose()Releases all resources used by the Component. (Inherited from Component.)
Protected methodDispose(Boolean)Releases the unmanaged resources used by the Component and optionally releases the managed resources. (Inherited from Component.)
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeReleases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection. (Inherited from Component.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetLifetimeServiceRetrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Protected methodGetServiceReturns an object that represents a service provided by the Component or by its Container. (Inherited from Component.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodInitializeLifetimeServiceObtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)
Public methodInstallWhen overridden in a derived class, performs the installation.
Protected methodMemberwiseClone()Creates a shallow copy of the current Object. (Inherited from Object.)
Protected methodMemberwiseClone(Boolean)Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)
Protected methodOnAfterInstallRaises the AfterInstall event.
Protected methodOnAfterRollbackRaises the AfterRollback event.
Protected methodOnAfterUninstallRaises the AfterUninstall event.
Protected methodOnBeforeInstallRaises the BeforeInstall event.
Protected methodOnBeforeRollbackRaises the BeforeRollback event.
Protected methodOnBeforeUninstallRaises the BeforeUninstall event.
Protected methodOnCommittedRaises the Committed event.
Protected methodOnCommittingRaises the Committing event.
Public methodRollbackWhen overridden in a derived class, restores the pre-installation state of the computer.
Public methodToStringReturns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from Component.)
Public methodUninstallWhen overridden in a derived class, removes an installation.

Public eventAfterInstallOccurs after the Install methods of all the installers in the Installers property have run.
Public eventAfterRollbackOccurs after the installations of all the installers in the Installers property are rolled back.
Public eventAfterUninstallOccurs after all the installers in the Installers property perform their uninstallation operations.
Public eventBeforeInstallOccurs before the Install method of each installer in the installer collection has run.
Public eventBeforeRollbackOccurs before the installers in the Installers property are rolled back.
Public eventBeforeUninstallOccurs before the installers in the Installers property perform their uninstall operations.
Public eventCommittedOccurs after all the installers in the Installers property have committed their installations.
Public eventCommittingOccurs before the installers in the Installers property committ their installations.
Public eventDisposedOccurs when the component is disposed by a call to the Dispose method. (Inherited from Component.)

This is the base class for all custom installers in the .NET Framework. Installers are components that help install applications on a computer.

There are several steps you must follow to use an Installer:

  • Inherit the Installer class.

  • Override the Install, Commit, Rollback, and Uninstall methods.

  • Add the RunInstallerAttribute to your derived class and set it to true.

  • Put your derived class in the assembly with your application to install.

  • Invoke the installers. For example, use the InstallUtil.exe to invoke the installers.

The Installers property contains a collection of installers. If this instance of Installer is part of an installer collection, the Parent property is set to the Installer instance that contains the collection. For an example of the use of the Installers collection, see the AssemblyInstaller class.

The Install, Commit, Rollback, and Uninstall methods of the Installer class go through the collection of installers stored in the Installers property, and invokes the corresponding method of each installer.

The Install, Commit, Rollback, and Uninstall methods are not always called on the same Installer instance. For example, one Installer instance might be used while installing and committing an application, and then the reference to that instance is released. Later, uninstalling the application creates a reference to a new Installer instance, meaning that the Uninstall method is called by a different instance of Installer. For this reason, in your derived class, do not save the state of a computer in an installer. Instead, use an IDictionary that is preserved across calls and passed into your Install, Commit, Rollback, and Uninstall methods.

Two situations illustrate the need to save information in the state-saver IDictionary. First, suppose that your installer sets a registry key. It should save the key's original value in the IDictionary. If the installation is rolled back, the original value can be restored. Second, suppose the installer replaces an existing file. Save the existing file in a temporary directory and the location of the new location of the file in the IDictionary. If the installation is rolled back, the newer file is deleted and replaced by the original from the temporary location.

The Installer.Context property contains information about the installation. For example, information about the location of the log file for the installation, the location of the file to save information required by the Uninstall method, and the command line that was entered when the installation executable was run.

The following example demonstrates the use of the Installer class. It creates a class which inherits from Installer. When Commit is about to complete, Committing event occurs and a message is displayed.

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;

// Set 'RunInstaller' attribute to true.
public class MyInstallerClass: Installer
   public MyInstallerClass() :base()
      // Attach the 'Committed' event.
      this.Committed += new InstallEventHandler(MyInstaller_Committed);
      // Attach the 'Committing' event.
      this.Committing += new InstallEventHandler(MyInstaller_Committing);

   // Event handler for 'Committing' event.
   private void MyInstaller_Committing(object sender, InstallEventArgs e)
      Console.WriteLine("Committing Event occured.");
   // Event handler for 'Committed' event.
   private void MyInstaller_Committed(object sender, InstallEventArgs e)
      Console.WriteLine("Committed Event occured.");
   // Override the 'Install' method.
   public override void Install(IDictionary savedState)
   // Override the 'Commit' method.
   public override void Commit(IDictionary savedState)
   // Override the 'Rollback' method.
   public override void Rollback(IDictionary savedState)
   public static void Main()
      Console.WriteLine("Usage : installutil.exe Installer.exe ");

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.