1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Text;
   4:  using System.ComponentModel;
   5:  using System.Windows.Forms;
   6:  using System.Configuration.Install;
   7:  using System.Collections;
   8:  using System.IO;
   9:  using System.Diagnostics;
  10:   
  11:  [System.ComponentModel.RunInstallerAttribute(true)]
  12:  public class MyInstall : System.Configuration.Install.Installer
  13:  {
  14:      const string ASSEMBLYPATH_STATENAME = "assemblypath";
  15:      private Container components = null;
  16:   
  17:      public MyInstall()
  18:      {
  19:          // This call is required by the Designer.
  20:          InitializeComponent();
  21:          this.Committed += new InstallEventHandler(MyInstall_Committed);
  22:      }
  23:   
  24:      private void InitializeComponent()
  25:      {
  26:   
  27:      }
  28:   
  29:      public override void Install(IDictionary stateSaver)
  30:      {
  31:          base.Install(stateSaver);
  32:          StringBuilder sb = new StringBuilder();
  33:          sb.AppendLine("Install...");
  34:          foreach (string key in stateSaver.Keys)
  35:          {
  36:              sb.AppendLine(string.Format("{0} = \"{1}\"", key, stateSaver[key]));
  37:          }
  38:          using (StreamWriter sw = new StreamWriter("C:\\MyInstallLog.txt", true))
  39:          {
  40:              sw.Write(sb.ToString());
  41:          }
  42:      }
  43:   
  44:      public override void Rollback(IDictionary savedState)
  45:      {
  46:          base.Rollback(savedState);
  47:          StringBuilder sb = new StringBuilder();
  48:          sb.AppendLine("Rollback...");
  49:          foreach (string key in savedState.Keys)
  50:          {
  51:              sb.AppendLine(string.Format("{0} = \"{1}\"", key, savedState[key]));
  52:          }
  53:          using (StreamWriter sw = new StreamWriter("C:\\MyInstallLog.txt", true))
  54:          {
  55:              sw.Write(sb.ToString());
  56:          }
  57:      }
  58:   
  59:      public override void Commit(IDictionary savedState)
  60:      {
  61:          base.Commit(savedState);
  62:          StringBuilder sb = new StringBuilder();
  63:          sb.AppendLine("Commit...");
  64:          foreach (string key in savedState.Keys)
  65:          {
  66:              sb.AppendLine(string.Format("{0} = \"{1}\"", key, savedState[key]));
  67:          }
  68:          using (StreamWriter sw = new StreamWriter("C:\\MyInstallLog.txt", true))
  69:          {
  70:              sw.Write(sb.ToString());
  71:          }
  72:      }
  73:   
  74:      public override void Uninstall(IDictionary savedState)
  75:      {
  76:          base.Uninstall(savedState);
  77:          StringBuilder sb = new StringBuilder();
  78:          sb.AppendLine("Uninstall...");
  79:          foreach (string key in savedState.Keys)
  80:          {
  81:              sb.AppendLine(string.Format("{0} = \"{1}\"", key, savedState[key]));
  82:          }
  83:          using (StreamWriter sw = new StreamWriter("C:\\MyInstallLog.txt", true))
  84:          {
  85:              sw.Write(sb.ToString());
  86:          }
  87:      }
  88:   
  89:      /// <summary> 
  90:      /// Clean up any resources being used.
  91:      /// </summary>
  92:      protected override void Dispose(bool disposing)
  93:      {
  94:          if (disposing)
  95:          {
  96:              if (components != null)
  97:              {
  98:                  components.Dispose();
  99:              }
 100:          }
 101:          base.Dispose(disposing);
 102:      }
 103:   
 104:      private void MyInstall_Committed(object sender, InstallEventArgs e)
 105:      {
 106:          StringBuilder sb = new StringBuilder();
 107:          sb.AppendLine("Committed (Context.Parameters...");
 108:          foreach (string key in Context.Parameters.Keys)
 109:          {
 110:              sb.AppendLine(string.Format("{0} = \"{1}\"", key, Context.Parameters[key]));
 111:          }
 112:          using (StreamWriter sw = new StreamWriter("C:\\MyInstallLog.txt", true))
 113:          {
 114:              sw.Write(sb.ToString());
 115:          }
 116:      }
 117:  }
 118:   
 119: