Installer Installer Installer Installer Class

Definição

Fornece a base para instalações 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
Herança
Derivado

Exemplos

O exemplo a seguir demonstra o uso da Installer classe.The following example demonstrates the use of the Installer class. Ele cria uma classe que herda de Installer.It creates a class which inherits from Installer. Quando Commit está prestes a ser concluída, Committing eventos ocorre e uma mensagem é exibida.When Commit is about to complete, Committing event occurs and a message is displayed. Para usar o Installer classe, você deve fazer referência a System.Configuration.Install assembly em seu projeto.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
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 'New

   ' 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 '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 occurred.")
      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

Comentários

Isso é a classe base para todos os instaladores personalizados no .NET Framework.This is the base class for all custom installers in the .NET Framework. Instaladores são componentes que ajudam a instalar aplicativos em um computador.Installers are components that help install applications on a computer.

Há várias etapas que devem ser seguidas para usar um Installer:There are several steps you must follow to use an Installer:

  • Herdar o Installer classe.Inherit the Installer class.

  • Substituir a Install, Commit, Rollback, e Uninstall métodos.Override the Install, Commit, Rollback, and Uninstall methods.

  • Adicione a RunInstallerAttribute para seu derivada de classe e defina-o como true.Add the RunInstallerAttribute to your derived class and set it to true.

  • Coloque sua classe derivada no assembly com seu aplicativo para instalar.Put your derived class in the assembly with your application to install.

  • Invocar os instaladores.Invoke the installers. Por exemplo, use o InstallUtil.exe para invocar os instaladores.For example, use the InstallUtil.exe to invoke the installers.

O Installers propriedade contém uma coleção de instaladores.The Installers property contains a collection of installers. Se esta instância do Installer faz parte de uma coleção de instalador, o Parent estiver definida como o Installer instância que contém a coleção.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 obter um exemplo do uso do Installers coleta, consulte o AssemblyInstaller classe.For an example of the use of the Installers collection, see the AssemblyInstaller class.

O Install, Commit, Rollback, e Uninstall métodos dos Installer classe percorrer a coleção de instaladores armazenados no Installers propriedade e invoca o método correspondente 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.

O Install, Commit, Rollback, e Uninstall métodos não são chamados sempre no mesmo Installer instância.The Install, Commit, Rollback, and Uninstall methods are not always called on the same Installer instance. Por exemplo, um Installer instância pode ser usada durante a instalação e a confirmação de um aplicativo e, em seguida, a referência a essa instância é liberada.For example, one Installer instance might be used while installing and committing an application, and then the reference to that instance is released. Posteriormente, a desinstalação do aplicativo cria uma referência a um novo Installer instância, o que significa que o Uninstall método é chamado por uma instância diferente do Installer.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 esse motivo, em sua classe derivada, salva o estado de um computador em um instalador.For this reason, in your derived class, do not save the state of a computer in an installer. Em vez disso, use uma IDictionary que é preservado durante as chamadas e passado para seus Install, Commit, Rollback, e Uninstall métodos.Instead, use an IDictionary that is preserved across calls and passed into your Install, Commit, Rollback, and Uninstall methods.

Duas situações ilustram a necessidade de salvar informações na proteção de estado IDictionary.Two situations illustrate the need to save information in the state-saver IDictionary. Primeiro, suponha que seu instalador define uma chave do registro.First, suppose that your installer sets a registry key. Ele deve salvar o valor da chave original na IDictionary.It should save the key's original value in the IDictionary. Se a instalação for revertida, o valor original pode ser restaurado.If the installation is rolled back, the original value can be restored. Em segundo lugar, vamos supor que o instalador substitui um arquivo existente.Second, suppose the installer replaces an existing file. Salve o arquivo existente em um diretório temporário e o local do novo local do arquivo no IDictionary.Save the existing file in a temporary directory and the location of the new location of the file in the IDictionary. Se a instalação for revertida, o arquivo mais recente é excluído e substituído por original do local temporário.If the installation is rolled back, the newer file is deleted and replaced by the original from the temporary location.

O Installer.Context propriedade contém informações sobre a instalação.The Installer.Context property contains information about the installation. Por exemplo, informações sobre o local do arquivo de log para a instalação, o local do arquivo para salvar as informações exigidas pelo Uninstall método e a linha de comando que foi digitada quando o executável de instalação foi executada.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.

Construtores

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

Inicializa uma nova instância da classe Installer.Initializes a new instance of the Installer class.

Propriedades

CanRaiseEvents CanRaiseEvents CanRaiseEvents CanRaiseEvents

Obtém um valor que indica se o componente pode acionar um evento.Gets a value indicating whether the component can raise an event.

(Inherited from Component)
Container Container Container Container

Obtém o IContainer que contém o Component.Gets the IContainer that contains the Component.

(Inherited from Component)
Context Context Context Context

Obtém ou define informações sobre a instalação atual.Gets or sets information about the current installation.

DesignMode DesignMode DesignMode DesignMode

Obtém um valor que indica se o Component está no modo de design no momento.Gets a value that indicates whether the Component is currently in design mode.

(Inherited from Component)
Events Events Events Events

Obtém a lista de manipuladores de eventos que estão anexados a este Component.Gets the list of event handlers that are attached to this Component.

(Inherited from Component)
HelpText HelpText HelpText HelpText

Obtém o texto de ajuda para todos os instaladores na coleção de instalador.Gets the help text for all the installers in the installer collection.

Installers Installers Installers Installers

Obtém a coleção de instaladores que contém esse instalador.Gets the collection of installers that this installer contains.

Parent Parent Parent Parent

Obtém ou define o instalador que contém a coleção à qual o instalador pertence.Gets or sets the installer containing the collection that this installer belongs to.

Site Site Site Site

Obtém ou define o ISite do Component.Gets or sets the ISite of the Component.

(Inherited from Component)

Métodos

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

Quando substituído em uma classe derivada, conclui a transação de instalação.When overridden in a derived class, completes the install transaction.

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

Cria um objeto que contém todas as informações relevantes necessárias para gerar um proxy usado para se comunicar com um 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 os recursos usados pelo Component.Releases all resources used by the Component.

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

Libera os recursos não gerenciados usados pelo Component e opcionalmente libera os recursos gerenciados.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 se o objeto especificado é igual ao objeto atual.Determines whether the specified object is equal to the current object.

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

Serve como a função de hash padrão.Serves as the default hash function.

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

Recupera o objeto de serviço de tempo de vida atual que controla a política de ciclo de vida para esta instância.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)

Retorna um objeto que representa um serviço fornecido pelo Component ou pelo seu Container.Returns an object that represents a service provided by the Component or by its Container.

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

Obtém o Type da instância atual.Gets the Type of the current instance.

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

Obtém um objeto de serviço de tempo de vida para controlar a política de tempo de vida para essa instância.Obtains a lifetime service object to control the lifetime policy for this instance.

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

Quando substituído em uma classe derivada, executa a instalação.When overridden in a derived class, performs the installation.

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

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

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

Cria uma cópia superficial do objeto MarshalByRefObject atual.Creates a shallow copy of the current MarshalByRefObject object.

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

Aciona o evento AfterInstall.Raises the AfterInstall event.

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

Aciona o evento AfterRollback.Raises the AfterRollback event.

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

Aciona o evento AfterUninstall.Raises the AfterUninstall event.

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

Aciona o evento BeforeInstall.Raises the BeforeInstall event.

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

Aciona o evento BeforeRollback.Raises the BeforeRollback event.

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

Aciona o evento BeforeUninstall.Raises the BeforeUninstall event.

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

Aciona o evento Committed.Raises the Committed event.

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

Aciona o evento Committing.Raises the Committing event.

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

Quando substituído em uma classe derivada, restaura o estado de pré-instalação do computador.When overridden in a derived class, restores the pre-installation state of the computer.

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

Retorna um String que contém o nome do Component, se houver.Returns a String containing the name of the Component, if any. Esse método não deve ser substituído.This method should not be overridden.

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

Quando substituído em uma classe derivada, remove uma instalação.When overridden in a derived class, removes an installation.

Eventos

AfterInstall AfterInstall AfterInstall AfterInstall

Ocorre depois que os métodos do Install(IDictionary) de todos os instaladores na propriedade Installers foram executados.Occurs after the Install(IDictionary) methods of all the installers in the Installers property have run.

AfterRollback AfterRollback AfterRollback AfterRollback

Ocorre após as instalações de todos os instaladores na propriedade Installers serem revertidas.Occurs after the installations of all the installers in the Installers property are rolled back.

AfterUninstall AfterUninstall AfterUninstall AfterUninstall

Ocorre depois que todos os instaladores na propriedade Installers realizam suas operações de desinstalação.Occurs after all the installers in the Installers property perform their uninstallation operations.

BeforeInstall BeforeInstall BeforeInstall BeforeInstall

Ocorre antes do método Install(IDictionary) de cada instalador no instalador em que a coleção foi executada.Occurs before the Install(IDictionary) method of each installer in the installer collection has run.

BeforeRollback BeforeRollback BeforeRollback BeforeRollback

Ocorre antes que os instaladores na propriedade Installers sejam revertidos.Occurs before the installers in the Installers property are rolled back.

BeforeUninstall BeforeUninstall BeforeUninstall BeforeUninstall

Ocorre antes dos instaladores na propriedade Installers executarem suas operações de desinstalação.Occurs before the installers in the Installers property perform their uninstall operations.

Committed Committed Committed Committed

Ocorre depois que todos os instaladores na propriedade Installers confirmaram suas instalações.Occurs after all the installers in the Installers property have committed their installations.

Committing Committing Committing Committing

Ocorre antes que os instaladores na propriedade Installers façam commit de suas instalações.Occurs before the installers in the Installers property commit their installations.

Disposed Disposed Disposed Disposed

Ocorre quando o componente é disposto por uma chamada para o método Dispose().Occurs when the component is disposed by a call to the Dispose() method.

(Inherited from Component)

Aplica-se a

Veja também