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
public ref class Installer : Component
type Installer = 
    class
        inherit Component
    end
Public Class Installer
	Inherits Component
NameDescription
System_CAPS_pubmethod Installer

Initializes a new instance of the Installer class.

NameDescription
System_CAPS_protproperty

Gets a value indicating whether the component can raise an event.(Inherited from Component.)

System_CAPS_pubproperty

Gets the IContainer that contains the Component.(Inherited from Component.)

System_CAPS_pubproperty

Gets or sets information about the current installation.

System_CAPS_protproperty

Gets a value that indicates whether the Component is currently in design mode.(Inherited from Component.)

System_CAPS_protproperty

Gets the list of event handlers that are attached to this Component.(Inherited from Component.)

System_CAPS_pubproperty

Gets the help text for all the installers in the installer collection.

System_CAPS_pubproperty

Gets the collection of installers that this installer contains.

System_CAPS_pubproperty

Gets or sets the installer containing the collection that this installer belongs to.

System_CAPS_pubproperty

Gets or sets the ISite of the Component.(Inherited from Component.)

NameDescription
System_CAPS_pubmethod Commit

When overridden in a derived class, completes the install transaction.

System_CAPS_pubmethod 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.)

System_CAPS_pubmethod Dispose

Releases all resources used by the Component.(Inherited from Component.)

System_CAPS_protmethod Dispose

Releases the unmanaged resources used by the Component and optionally releases the managed resources.(Inherited from Component.)

System_CAPS_pubmethod Equals

Determines whether the specified object is equal to the current object.(Inherited from Object.)

System_CAPS_protmethod Finalize

Releases unmanaged resources and performs other cleanup operations before the Component is reclaimed by garbage collection.(Inherited from Component.)

System_CAPS_pubmethod GetHashCode

Serves as the default hash function. (Inherited from Object.)

System_CAPS_pubmethod GetLifetimeService

Retrieves the current lifetime service object that controls the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_protmethod GetService

Returns an object that represents a service provided by the Component or by its Container.(Inherited from Component.)

System_CAPS_pubmethod GetType

Gets the Type of the current instance.(Inherited from Object.)

System_CAPS_pubmethod InitializeLifetimeService

Obtains a lifetime service object to control the lifetime policy for this instance.(Inherited from MarshalByRefObject.)

System_CAPS_pubmethod Install

When overridden in a derived class, performs the installation.

System_CAPS_protmethod MemberwiseClone

Creates a shallow copy of the current Object.(Inherited from Object.)

System_CAPS_protmethod MemberwiseClone

Creates a shallow copy of the current MarshalByRefObject object.(Inherited from MarshalByRefObject.)

System_CAPS_protmethod OnAfterInstall

Raises the AfterInstall event.

System_CAPS_protmethod OnAfterRollback

Raises the AfterRollback event.

System_CAPS_protmethod OnAfterUninstall

Raises the AfterUninstall event.

System_CAPS_protmethod OnBeforeInstall

Raises the BeforeInstall event.

System_CAPS_protmethod OnBeforeRollback

Raises the BeforeRollback event.

System_CAPS_protmethod OnBeforeUninstall

Raises the BeforeUninstall event.

System_CAPS_protmethod OnCommitted

Raises the Committed event.

System_CAPS_protmethod OnCommitting

Raises the Committing event.

System_CAPS_pubmethod Rollback

When overridden in a derived class, restores the pre-installation state of the computer.

System_CAPS_pubmethod ToString

Returns a String containing the name of the Component, if any. This method should not be overridden.(Inherited from Component.)

System_CAPS_pubmethod Uninstall

When overridden in a derived class, removes an installation.

NameDescription
System_CAPS_pubevent AfterInstall

Occurs after the Install methods of all the installers in the property have run.

System_CAPS_pubevent AfterRollback

Occurs after the installations of all the installers in the property are rolled back.

System_CAPS_pubevent AfterUninstall

Occurs after all the installers in the property perform their uninstallation operations.

System_CAPS_pubevent BeforeInstall

Occurs before the Install method of each installer in the installer collection has run.

System_CAPS_pubevent BeforeRollback

Occurs before the installers in the property are rolled back.

System_CAPS_pubevent BeforeUninstall

Occurs before the installers in the property perform their uninstall operations.

System_CAPS_pubevent Committed

Occurs after all the installers in the property have committed their installations.

System_CAPS_pubevent Committing

Occurs before the installers in the property committ their installations.

System_CAPS_pubevent Disposed

Occurs 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 property contains a collection of installers. If this instance of Installer is part of an installer collection, the property is set to the Installer instance that contains the collection. For an example of the use of the 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 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 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. To use the Installer class, you must reference the System.Configuration.Install assembly in your project.

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

// Set 'RunInstaller' attribute to true.
[RunInstaller(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("");
      Console.WriteLine("Committing Event occured.");
      Console.WriteLine("");
   }
   // Event handler for 'Committed' event.
   private void MyInstaller_Committed(object sender, InstallEventArgs e)
   {
      Console.WriteLine("");
      Console.WriteLine("Committed Event occured.");
      Console.WriteLine("");
   }
   // Override the 'Install' method.
   public override void Install(IDictionary savedState)
   {
      base.Install(savedState);
   }
   // Override the 'Commit' method.
   public override void Commit(IDictionary savedState)
   {
      base.Commit(savedState);
   }
   // Override the 'Rollback' method.
   public override void Rollback(IDictionary savedState)
   {
      base.Rollback(savedState);
   }
   public static void Main()
   {
      Console.WriteLine("Usage : installutil.exe Installer.exe ");
   }
}
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Configuration.Install

' Set 'RunInstaller' attribute to true.
<RunInstaller(True)> _
Public Class MyInstallerClass
   Inherits Installer

   Public Sub New()
       MyBase.New()
      ' Attach the 'Committed' event.
      AddHandler Me.Committed, AddressOf MyInstaller_Committed
      ' Attach the 'Committing' event.
      AddHandler Me.Committing, AddressOf MyInstaller_Committing
   End Sub 'NewNew

   ' Event handler for 'Committing' event.
   Private Sub MyInstaller_Committing(ByVal sender As Object, _
                                      ByVal e As InstallEventArgs)
      Console.WriteLine("")
      Console.WriteLine("Committing Event occured.")
      Console.WriteLine("")
   End Sub 'MyInstaller_Committing

   ' Event handler for 'Committed' event.
   Private Sub MyInstaller_Committed(ByVal sender As Object, _
                                     ByVal e As InstallEventArgs)
      Console.WriteLine("")
      Console.WriteLine("Committed Event occured.")
      Console.WriteLine("")
   End Sub 'MyInstaller_Committed

   ' Override the 'Install' method.
   Public Overrides Sub Install(ByVal savedState As IDictionary)
      MyBase.Install(savedState)
   End Sub 'Install

   ' Override the 'Commit' method.
   Public Overrides Sub Commit(ByVal savedState As IDictionary)
      MyBase.Commit(savedState)
   End Sub 'Commit

   ' Override the 'Rollback' method.
   Public Overrides Sub Rollback(ByVal savedState As IDictionary)
      MyBase.Rollback(savedState)
   End Sub 'Rollback
   Public Shared Sub Main()
      Console.WriteLine("Usage : installutil.exe Installer.exe ")
   End Sub 'Main
End Class 'MyInstallerClass
#using <System.dll>
#using <System.Configuration.Install.dll>

using namespace System;
using namespace System::Collections;
using namespace System::ComponentModel;
using namespace System::Configuration::Install;

// Set 'RunInstaller' attribute to true.

[RunInstaller(true)]
ref class MyInstallerClass: public Installer
{
private:

   // Event handler for 'Committing' event.
   void MyInstaller_Committing( Object^ sender, InstallEventArgs^ e )
   {
      Console::WriteLine( "" );
      Console::WriteLine( "Committing Event occured." );
      Console::WriteLine( "" );
   }


   // Event handler for 'Committed' event.
   void MyInstaller_Committed( Object^ sender, InstallEventArgs^ e )
   {
      Console::WriteLine( "" );
      Console::WriteLine( "Committed Event occured." );
      Console::WriteLine( "" );
   }


public:
   MyInstallerClass()
   {

      // Attach the 'Committed' event.
      this->Committed += gcnew InstallEventHandler( this, &MyInstallerClass::MyInstaller_Committed );

      // Attach the 'Committing' event.
      this->Committing += gcnew InstallEventHandler( this, &MyInstallerClass::MyInstaller_Committing );
   }


   // Override the 'Install' method.
   virtual void Install( IDictionary^ savedState ) override
   {
      Installer::Install( savedState );
   }


   // Override the 'Commit' method.
   virtual void Commit( IDictionary^ savedState ) override
   {
      Installer::Commit( savedState );
   }


   // Override the 'Rollback' method.
   virtual void Rollback( IDictionary^ savedState ) override
   {
      Installer::Rollback( savedState );
   }

};

int main()
{
   Console::WriteLine( "Usage : installutil.exe Installer.exe " );
}
.NET Framework
Available since 1.1

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

Return to top