Help‎ > ‎NvnInstaller.MsiDotNet‎ > ‎

Steps to build custom UI application

1. Create MsiInstaller object. Pass name of MSI package to install.
For example: MsiInstaller msiInstaller = new MsiInstaller("test.msi");

2.  Now subscribe InstallerMessageReceived event to handle Windows Installer messages.
 
    msiInstaller.InstallerMessageReceived += new EventHandler<InstallerMessageEventArgs>(InstallerMessageReceived_EventHadler);
 
    Event handler body. Download sample for complete code
   
    void InstallerMessageReceived_EventHadler(object sender, InstallerMessageEventArgs e) {
      string message = string.Empty;
      if (e.InstallerMessage.Type == InstallerMessageType.ActionInfo) {
        message = ((ActionInfoMessage)e.InstallerMessage).ToString();
      } else if (e.InstallerMessage.Type == InstallerMessageType.ProgressAddition) {
        message = ((ProgressAdditionMessage)e.InstallerMessage).ToString();
      } else if (e.InstallerMessage.Type == InstallerMessageType.ProgressReport) {
          ProgressReportMessage progressReportMessage = (ProgressReportMessage)e.InstallerMessage;
          progressBar1.Value += (int)progressReportMessage.TicksMoved;
      } else if (e.InstallerMessage.Type == InstallerMessageType.FileInUse) {
        DialogResult userAction = MessageBox.Show("file in use:" + ((FileInUseMessage)e.InstallerMessage).FilePath, "File in use", MessageBoxButtons.RetryCancel);
        MsiInterfaceObject.SetUserAction((int)userAction);
      } else if.....
    }
   
3. Using features

    MsiFeature is the basic class which contains all feature information. Installer user interface author can use the list of features to selectively install/uninstall.
 
    Use MsiInstaller.FeatureTree to get list of feature. This property gives only root features. Use ChildFeatures property recursively to get complete list of features.
 
Following example recursively get list of features and updates Treeview

    public void LoadFeatures() {
        MsiInstaller msiInterface = new MsiInstaller(<msi filename>);
        List<MsiFeature> features = msiInterface.FeatureTree;
        foreach (MsiFeature feature in features) {
          LoadFeatureTree(feature, null);
        }
    }

    private void LoadFeatureTree(MsiFeature feature, TreeNode node) {
      TreeNode newNode = null;
      if (node == null) {
        newNode = tvFeatures.Nodes.Add(feature.Title);
      } else {
        newNode = node.Nodes.Add(feature.Title);
      }

      newNode.Checked = feature.IsAlreadyInstalled;

      if (feature.ChildFeatures != null) {
        foreach (MsiFeature childFeature in feature.ChildFeatures) {
          LoadFeatureTree(childFeature, newNode);
        }
      }
    }
 
4. Use MsiFeature.IsAlreadyInstalled to know whether feature is already installed on local system.
   
5. MsiInstaller.IsAlreadyInstalled says whether MSI package with same ID is already installed or not. This can be used to show Install Dialog or Update/Remove dialog
   
6. Call Install, Update Remove method of MsiInstaller object. These methods can also be used with specific list features.