how to read values from msi database?
Thanks
how to read values from msi database?
Thanks
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!
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?
majestic0110, i will examine panayquil's code, then i will synthesize the knowledge and come back.
Excellent, hope it helps!
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.
no problem, i downloaded it before you post that.
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
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;
}
}
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?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.