Installer Installer Installer Installer Class

Definición

Proporciona la base para las instalaciones personalizadas.Provides the foundation for custom installations.

public ref class Installer : System::ComponentModel::Component
public class Installer : System.ComponentModel.Component
type Installer = class
    inherit Component
Public Class Installer
Inherits Component
Herencia
Derivado

Ejemplos

En el siguiente ejemplo se muestra el uso Installer de la clase.The following example demonstrates the use of the Installer class. Crea una clase que hereda de Installer.It creates a class which inherits from Installer. Cuando Commit está a punto de completarse, Committing se produce un evento y se muestra un mensaje.When Commit is about to complete, Committing event occurs and a message is displayed. Para usar la Installer clase, debe hacer referencia al ensamblado System. Configuration. Install en el proyecto.To use the Installer class, you must reference the System.Configuration.Install assembly in your project.

#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 occurred." );
      Console::WriteLine( "" );
   }


   // Event handler for 'Committed' event.
   void MyInstaller_Committed( Object^ sender, InstallEventArgs^ e )
   {
      Console::WriteLine( "" );
      Console::WriteLine( "Committed Event occurred." );
      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 " );
}

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 occurred.");
      Console.WriteLine("");
   }
   // Event handler for 'Committed' event.
   private void MyInstaller_Committed(object sender, InstallEventArgs e)
   {
      Console.WriteLine("");
      Console.WriteLine("Committed Event occurred.");
      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.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

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

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

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

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

   ' Override the 'Rollback' method.
   Public Overrides Sub Rollback(ByVal savedState As IDictionary)
      MyBase.Rollback(savedState)
   End Sub
   Public Shared Sub Main()
      Console.WriteLine("Usage : installutil.exe Installer.exe ")
   End Sub
End Class 'MyInstallerClass

Comentarios

Esta es la clase base para todos los instaladores personalizados en el .NET Framework.This is the base class for all custom installers in the .NET Framework. Los instaladores son componentes que ayudan a instalar aplicaciones en un equipo.Installers are components that help install applications on a computer.

Hay varios pasos que debe seguir para usar Installer:There are several steps you must follow to use an Installer:

  • Hereda la Installer clase.Inherit the Installer class.

  • InstallInvalide los métodos, Uninstall Rollback Commit, y.Override the Install, Commit, Rollback, and Uninstall methods.

  • Agregue a la clase derivada y establézcala en true. RunInstallerAttributeAdd the RunInstallerAttribute to your derived class and set it to true.

  • Coloque la clase derivada en el ensamblado con la aplicación que se va a instalar.Put your derived class in the assembly with your application to install.

  • Invoque a los instaladores.Invoke the installers. Por ejemplo, use InstallUtil. exe para invocar a los instaladores.For example, use the InstallUtil.exe to invoke the installers.

La Installers propiedad contiene una colección de instaladores.The Installers property contains a collection of installers. Si esta instancia de Installer forma parte de una colección de instalador, Parent la propiedad se establece en Installer la instancia de que contiene la colección.If this instance of Installer is part of an installer collection, the Parent property is set to the Installer instance that contains the collection. Para obtener un ejemplo del uso de la Installers colección, vea la AssemblyInstaller clase.For an example of the use of the Installers collection, see the AssemblyInstaller class.

Los Installmétodos Commit, ,Rollback Installers y deUninstall la clasepasanporlacoleccióndeinstaladoresalmacenadosenlapropiedadeinvocanelmétodoInstaller correspondiente de cada instalador.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.

No Installsiempre Commitse Rollbackllama a Uninstall los métodos,, y en la misma Installer instancia.The Install, Commit, Rollback, and Uninstall methods are not always called on the same Installer instance. Por ejemplo, se Installer puede usar una instancia de al instalar y confirmar una aplicación y, a continuación, se libera la referencia a esa instancia.For example, one Installer instance might be used while installing and committing an application, and then the reference to that instance is released. Más adelante, al desinstalar la aplicación, se crea una referencia Installer a una nueva instancia, Uninstall lo que significa que una instancia diferente de Installerllama al método.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. Por esta razón, en la clase derivada, no guarde el estado de un equipo en un instalador.For this reason, in your derived class, do not save the state of a computer in an installer. En su lugar, utilice IDictionary un que se conserva en las llamadas y se Installpasa a Rollbacklos métodos Uninstall , Commit, y.Instead, use an IDictionary that is preserved across calls and passed into your Install, Commit, Rollback, and Uninstall methods.

Dos situaciones ilustran la necesidad de guardar información en el protector IDictionaryde estado.Two situations illustrate the need to save information in the state-saver IDictionary. En primer lugar, supongamos que el instalador establece una clave del registro.First, suppose that your installer sets a registry key. Debe guardar el valor original de la clave en IDictionary.It should save the key's original value in the IDictionary. Si se revierte la instalación, se puede restaurar el valor original.If the installation is rolled back, the original value can be restored. En segundo lugar, supongamos que el instalador reemplaza un archivo existente.Second, suppose the installer replaces an existing file. Guarde el archivo existente en un directorio temporal y la ubicación de la nueva ubicación del archivo en el IDictionary.Save the existing file in a temporary directory and the location of the new location of the file in the IDictionary. Si la instalación se revierte, el archivo más reciente se elimina y se reemplaza por el original de la ubicación temporal.If the installation is rolled back, the newer file is deleted and replaced by the original from the temporary location.

La Installer.Context propiedad contiene información sobre la instalación de.The Installer.Context property contains information about the installation. Por ejemplo, información sobre la ubicación del archivo de registro para la instalación, la ubicación del archivo para guardar la información requerida por el Uninstall método y la línea de comandos que se especificó cuando se ejecutó el ejecutable de instalación.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.

Constructores

Installer() Installer() Installer() Installer()

Inicializa una nueva instancia de la clase Installer.Initializes a new instance of the Installer class.

Propiedades

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

Obtiene un valor que indica si el componente puede generar un evento.Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

Obtiene IContainer que contiene Component.Gets the IContainer that contains the Component.

(Inherited from Component)
Context Context Context Context

Obtiene o establece información sobre la instalación actual.Gets or sets information about the current installation.

DesignMode DesignMode DesignMode DesignMode

Obtiene un valor que indica si Component está actualmente en modo de diseño.Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events Events Events Events

Obtiene la lista de controladores de eventos asociados a Component.Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
HelpText HelpText HelpText HelpText

Obtiene el texto de ayuda de todos los instaladores que se encuentran en la colección de instaladores.Gets the help text for all the installers in the installer collection.

Installers Installers Installers Installers

Obtiene la colección de instaladores que contiene este instalador.Gets the collection of installers that this installer contains.

Parent Parent Parent Parent

Obtiene o establece el instalador que contiene la colección a la que pertenece este instalador.Gets or sets the installer containing the collection that this installer belongs to.

Site Site Site Site

Obtiene o establece el ISite de Component.Gets or sets the ISite of the Component.

(Inherited from Component)

Métodos

Commit(IDictionary) Commit(IDictionary) Commit(IDictionary) Commit(IDictionary)

Cuando se reemplaza en una clase derivada, finaliza la transacción de instalación.When overridden in a derived class, completes the install transaction.

CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type) CreateObjRef(Type)

Crea un objeto que contiene toda la información relevante necesaria para generar un proxy utilizado para comunicarse con un objeto remoto.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() Dispose() Dispose() Dispose()

Libera todos los recursos que usa Component.Releases all resources used by the Component.

(Inherited from Component)
Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

Libera los recursos no administrados que usa Component y, de forma opcional, libera los recursos administrados.Releases the unmanaged resources used by the Component and optionally releases the managed resources.

(Inherited from Component)
Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Inherited from Object)
GetLifetimeService() GetLifetimeService() GetLifetimeService() GetLifetimeService()

Recupera el objeto de servicio de duración actual que controla la directiva de duración de esta instancia.Retrieves the current lifetime service object that controls the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
GetService(Type) GetService(Type) GetService(Type) GetService(Type)

Devuelve un objeto que representa el servicio suministrado por Component o por Container.Returns an object that represents a service provided by the Component or by its Container.

(Inherited from Component)
GetType() GetType() GetType() GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService() InitializeLifetimeService()

Obtiene un objeto de servicio de duración para controlar la directiva de duración de esta instancia.Obtains a lifetime service object to control the lifetime policy for this instance.

(Inherited from MarshalByRefObject)
Install(IDictionary) Install(IDictionary) Install(IDictionary) Install(IDictionary)

Cuando se reemplaza en una clase derivada, se lleva a cabo la instalación.When overridden in a derived class, performs the installation.

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean) MemberwiseClone(Boolean)

Crea una copia superficial del objeto MarshalByRefObject actual.Creates a shallow copy of the current MarshalByRefObject object.

(Inherited from MarshalByRefObject)
OnAfterInstall(IDictionary) OnAfterInstall(IDictionary) OnAfterInstall(IDictionary) OnAfterInstall(IDictionary)

Genera el evento AfterInstall.Raises the AfterInstall event.

OnAfterRollback(IDictionary) OnAfterRollback(IDictionary) OnAfterRollback(IDictionary) OnAfterRollback(IDictionary)

Genera el evento AfterRollback.Raises the AfterRollback event.

OnAfterUninstall(IDictionary) OnAfterUninstall(IDictionary) OnAfterUninstall(IDictionary) OnAfterUninstall(IDictionary)

Genera el evento AfterUninstall.Raises the AfterUninstall event.

OnBeforeInstall(IDictionary) OnBeforeInstall(IDictionary) OnBeforeInstall(IDictionary) OnBeforeInstall(IDictionary)

Genera el evento BeforeInstall.Raises the BeforeInstall event.

OnBeforeRollback(IDictionary) OnBeforeRollback(IDictionary) OnBeforeRollback(IDictionary) OnBeforeRollback(IDictionary)

Genera el evento BeforeRollback.Raises the BeforeRollback event.

OnBeforeUninstall(IDictionary) OnBeforeUninstall(IDictionary) OnBeforeUninstall(IDictionary) OnBeforeUninstall(IDictionary)

Genera el evento BeforeUninstall.Raises the BeforeUninstall event.

OnCommitted(IDictionary) OnCommitted(IDictionary) OnCommitted(IDictionary) OnCommitted(IDictionary)

Genera el evento Committed.Raises the Committed event.

OnCommitting(IDictionary) OnCommitting(IDictionary) OnCommitting(IDictionary) OnCommitting(IDictionary)

Genera el evento Committing.Raises the Committing event.

Rollback(IDictionary) Rollback(IDictionary) Rollback(IDictionary) Rollback(IDictionary)

Cuando se reemplaza en una clase derivada, restaura el estado en el que estaba el equipo antes de la instalación.When overridden in a derived class, restores the pre-installation state of the computer.

ToString() ToString() ToString() ToString()

Devuelve una String que contiene el nombre del Component, si existe.Returns a String containing the name of the Component, if any. Este método no se debe invalidar.This method should not be overridden.

(Inherited from Component)
Uninstall(IDictionary) Uninstall(IDictionary) Uninstall(IDictionary) Uninstall(IDictionary)

Cuando se reemplaza en una clase derivada, quita una instalación.When overridden in a derived class, removes an installation.

Eventos

AfterInstall AfterInstall AfterInstall AfterInstall

Se produce después de ejecutarse los métodos Install(IDictionary) de todos los instaladores de la propiedad Installers.Occurs after the Install(IDictionary) methods of all the installers in the Installers property have run.

AfterRollback AfterRollback AfterRollback AfterRollback

Se produce después de deshacerse la instalación de todos los instaladores de la propiedad Installers.Occurs after the installations of all the installers in the Installers property are rolled back.

AfterUninstall AfterUninstall AfterUninstall AfterUninstall

Se produce después de que todos los instaladores de la propiedad Installers realicen sus operaciones de desinstalación.Occurs after all the installers in the Installers property perform their uninstallation operations.

BeforeInstall BeforeInstall BeforeInstall BeforeInstall

Se produce antes de ejecutarse el método Install(IDictionary) de cada instalador en la colección de instaladores.Occurs before the Install(IDictionary) method of each installer in the installer collection has run.

BeforeRollback BeforeRollback BeforeRollback BeforeRollback

Se produce antes de deshacerse los instaladores de la propiedad Installers.Occurs before the installers in the Installers property are rolled back.

BeforeUninstall BeforeUninstall BeforeUninstall BeforeUninstall

Se produce antes de que los instaladores de la propiedad Installers realicen sus operaciones de desinstalación.Occurs before the installers in the Installers property perform their uninstall operations.

Committed Committed Committed Committed

Se produce después de que todos los instaladores de la propiedad Installers confirmen sus instalaciones.Occurs after all the installers in the Installers property have committed their installations.

Committing Committing Committing Committing

Se produce antes de que los instaladores de la propiedad Installers confirmen sus instalaciones.Occurs before the installers in the Installers property commit their installations.

Disposed Disposed Disposed Disposed

Se produce cuando el componente se elimina mediante una llamada al método Dispose().Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

Se aplica a

Consulte también: