Export (0) Print
Expand All
1 out of 8 rated this helpful - Rate this topic

Installer Class

Provides the foundation for custom installations.

For a list of all members of this type, see Installer Members.

System.Object
   System.MarshalByRefObject
      System.ComponentModel.Component
         System.Configuration.Install.Installer
            System.Configuration.Install.AssemblyInstaller
            System.Configuration.Install.ComponentInstaller
            System.Configuration.Install.TransactedInstaller
            System.Management.Instrumentation.DefaultManagementProjectInstaller
            System.Management.Instrumentation.ManagementInstaller

[Visual Basic]
Public Class Installer
   Inherits Component
[C#]
public class Installer : Component
[C++]
public __gc class Installer : public Component
[JScript]
public class Installer extends Component

Thread Safety

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

Remarks

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.

Example

[Visual Basic, C#, C++] 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.

[Visual Basic] 
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 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

[C#] 
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 ");
   }
}

[C++] 
#using <mscorlib.dll>
#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)]
__gc class MyInstallerClass : public Installer {
    // Event handler for 'Committing' event.
private:
    void MyInstaller_Committing(Object* sender, InstallEventArgs* e) {
        Console::WriteLine(S"");
        Console::WriteLine(S"Committing Event occured.");
        Console::WriteLine(S"");
    }
    // Event handler for 'Committed' event.
    void MyInstaller_Committed(Object* sender, InstallEventArgs* e) {
        Console::WriteLine(S"");
        Console::WriteLine(S"Committed Event occured.");
        Console::WriteLine(S"");
    }

public:
    MyInstallerClass() {
        // Attach the 'Committed' event.
        this->Committed += new InstallEventHandler(this, &MyInstallerClass::MyInstaller_Committed);
        // Attach the 'Committing' event.
        this->Committing += new InstallEventHandler(this, &MyInstallerClass::MyInstaller_Committing);

    }

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

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

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

int main() {
    Console::WriteLine(S"Usage : installutil.exe Installer.exe ");
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Namespace: System.Configuration.Install

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

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

See Also

Installer Members | System.Configuration.Install Namespace | AssemblyInstaller | ComponentInstaller | InstallerCollection | TransactedInstaller | Installer Tool (Installutil.exe)

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.