954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to read values from msi database?

how to read values from msi database?

Thanks

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

Hi Serkan Sendur, I hope you are well. Reading data from a .msi file is not something I have done myself before but I did some research for you and came up with this :

http://rongchaua.net/blog/c-how-to-read-data-from-msi-file/

I hope this helps!

majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

Thanks,
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?

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 
papanyquiL
Junior Poster
168 posts since May 2009
Reputation Points: 55
Solved Threads: 18
 

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

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

Excellent, hope it helps!

majestic0110
Nearly a Posting Virtuoso
1,328 posts since Oct 2007
Reputation Points: 256
Solved Threads: 72
 

Really?

Reading Data from MSI Database

Sorry buddy--I didn't realize it was C++. I can probably translate for you though if you need it.

DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
 

no problem, i downloaded it before you post that.

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

Scratch that last reply--I couldn't even get it to compile. Here is a link that I compiled and played with a little: MSI Analyzer

DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
 

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
    {
        [System.Runtime.InteropServices.ComImport(),
            System.Runtime.InteropServices.Guid
            ("000C1090-0000-0000-C000-000000000046")]
        class Installer { }

        public Form1()
        {
            InitializeComponent();
        }

        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,
                WindowsInstaller.MsiOpenDatabaseMode.msiOpenDatabaseModeReadOnly);

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

            //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
            view.Close();
        }
    }
}
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))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #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();
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
            this.SuspendLayout();
            // 
            // dataGridView1
            // 
            this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
            this.Property,
            this.Value});
            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.Controls.Add(this.dataGridView1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.Load += new System.EventHandler(this.Form1_Load);
            ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
            this.ResumeLayout(false);

        }

        #endregion

        private System.Windows.Forms.DataGridView dataGridView1;
        private System.Windows.Forms.DataGridViewTextBoxColumn Property;
        private System.Windows.Forms.DataGridViewTextBoxColumn Value;
    }
}
DdoubleD
Posting Shark
996 posts since Jul 2009
Reputation Points: 341
Solved Threads: 233
 

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?

serkan sendur
Postaholic
Banned
2,062 posts since Jan 2008
Reputation Points: 854
Solved Threads: 127
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You