how to read values from msi database?


i looked at that code but
Database dbMsiFile = new Database(strFileMsi, OpenDatabase.ReadOnly);
even in that code it is not a defined type, what is that Database class?

majestic0110, i will examine panayquil's code, then i will synthesize the knowledge and come back.

That MSI Analyzer is pretty cool, but here is a simplified answer I whipped up for ya:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices; // Deploying a .NET component customization
using WindowsInstaller;
using System.IO;
using System.Collections;

namespace MSIDataBaseStuff
    public partial class Form1 : Form
        class Installer { }

        public Form1()

        private void Form1_Load(object sender, EventArgs e)
            FileInfo msiFile = new FileInfo("setup1.msi");

            // open MSI database
            WindowsInstaller.Installer inst = (WindowsInstaller.Installer)new Installer();
            Database instDb = inst.OpenDatabase(msiFile.FullName,

            // query the database
            WindowsInstaller.View view = instDb.OpenView
                ("Select `Property`,`Value` FROM `Property`");

            //fetch each record...
            Record record = view.Fetch();
            while (record != null)
                int iRow = dataGridView1.Rows.Add();
                dataGridView1.Rows[iRow].Cells[0].Value = record.get_StringData(1);// property
                dataGridView1.Rows[iRow].Cells[1].Value = record.get_StringData(2);// value

                record = view.Fetch();

            // close the database
partial class Form1
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
            if (disposing && (components != null))

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
            this.dataGridView1 = new System.Windows.Forms.DataGridView();
            this.Property = new System.Windows.Forms.DataGridViewTextBoxColumn();
            this.Value = new System.Windows.Forms.DataGridViewTextBoxColumn();
            // dataGridView1
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.dataGridView1.Location = new System.Drawing.Point(0, 0);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.Size = new System.Drawing.Size(761, 350);
            this.dataGridView1.TabIndex = 0;
            // Property
            this.Property.HeaderText = "Property";
            this.Property.Name = "Property";
            this.Property.Width = 200;
            // Value
            this.Value.HeaderText = "Value";
            this.Value.Name = "Value";
            this.Value.Width = 700;
            // Form1
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(761, 350);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);



        private System.Windows.Forms.DataGridView dataGridView1;
        private System.Windows.Forms.DataGridViewTextBoxColumn Property;
        private System.Windows.Forms.DataGridViewTextBoxColumn Value;
havent checked yet but if works, oh man!

i have a question here, you open an .msi by specifying a path to .msi.
i want to read that information without knowing the physical path of that .msi. i will use this from within custom installer class, so in any case .msi will be executed first, i want to read information from the .msi which is being executed at the time of reading. Is that clear?

This article has been dead for over six months. Start a new discussion instead.