Click here to Skip to main content
12,760,014 members (34,410 online)
Click here to Skip to main content
Articles » Languages » VB.NET » Utilities » Downloads


28 bookmarked
Posted 22 Nov 2006

Microsoft Installer Database Reader

, 22 Nov 2006
An MSI database file reader, helps to get insights into the .msi DB structure.
Public Class Form1
    Inherits System.Windows.Forms.Form

    Dim Installer
    Dim Database
    Dim View
    Dim Record

#Region " Windows Form Designer generated code "

    Public Sub New()

        'This call is required by the Windows Form Designer.

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
            End If
        End If
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
    Friend WithEvents MainMenu1 As System.Windows.Forms.MainMenu
    Friend WithEvents ListView1 As System.Windows.Forms.ListView
    Friend WithEvents Splitter1 As System.Windows.Forms.Splitter
    Friend WithEvents DataView1 As System.Data.DataView
    Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
    Friend WithEvents MenuItem1 As System.Windows.Forms.MenuItem
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.components = New System.ComponentModel.Container
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog
        Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
        Me.MainMenu1 = New System.Windows.Forms.MainMenu
        Me.ListView1 = New System.Windows.Forms.ListView
        Me.Splitter1 = New System.Windows.Forms.Splitter
        Me.DataView1 = New System.Data.DataView
        Me.DataGrid1 = New System.Windows.Forms.DataGrid
        Me.MenuItem1 = New System.Windows.Forms.MenuItem
        CType(Me.DataView1, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.OpenFileDialog1.Filter = """Microsoft Installer DB (*.msi)|*.msi|All files (*.*)|*.*"""
        Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
        Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
        Me.ImageList1.TransparentColor = System.Drawing.Color.Transparent
        Me.MainMenu1.MenuItems.AddRange(New System.Windows.Forms.MenuItem() {Me.MenuItem1})
        Me.ListView1.Dock = System.Windows.Forms.DockStyle.Left
        Me.ListView1.Location = New System.Drawing.Point(0, 0)
        Me.ListView1.MultiSelect = False
        Me.ListView1.Name = "ListView1"
        Me.ListView1.Size = New System.Drawing.Size(112, 273)
        Me.ListView1.SmallImageList = Me.ImageList1
        Me.ListView1.StateImageList = Me.ImageList1
        Me.ListView1.TabIndex = 0
        Me.ListView1.View = System.Windows.Forms.View.SmallIcon
        Me.Splitter1.Location = New System.Drawing.Point(112, 0)
        Me.Splitter1.Name = "Splitter1"
        Me.Splitter1.Size = New System.Drawing.Size(3, 273)
        Me.Splitter1.TabIndex = 1
        Me.Splitter1.TabStop = False
        Me.DataGrid1.DataMember = ""
        Me.DataGrid1.DataSource = Me.DataView1
        Me.DataGrid1.Dock = System.Windows.Forms.DockStyle.Fill
        Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.DataGrid1.Location = New System.Drawing.Point(115, 0)
        Me.DataGrid1.Name = "DataGrid1"
        Me.DataGrid1.Size = New System.Drawing.Size(177, 273)
        Me.DataGrid1.TabIndex = 2
        Me.MenuItem1.Index = 0
        Me.MenuItem1.Text = "&Open"
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 273)
        Me.Menu = Me.MainMenu1
        Me.Name = "Form1"
        Me.Text = "Form1"
        CType(Me.DataView1, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()

    End Sub

#End Region

    Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1.Click

        If OpenFileDialog1.ShowDialog() = DialogResult.OK Then


            Installer = CreateObject("WindowsInstaller.Installer")

            Database = Installer.OpenDatabase(OpenFileDialog1.FileName, 0) ' 0 = read only; 1 = read/write

            ' Get table names
            View = Database.OpenView("SELECT `Name` FROM `_Tables`")

            Record = View.Fetch()
            While Not Record Is Nothing

                ListView1.Items.Add(Record.StringData(1), 0)

                Record = View.Fetch()

            End While

        End If
    End Sub

    Private Sub ListView1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListView1.SelectedIndexChanged

        If ListView1.SelectedItems.Count = 0 Then
            Exit Sub
        End If

        Installer = CreateObject("WindowsInstaller.Installer")

        ' Get Column names
        View = Database.OpenView("SELECT `Name` FROM `_Columns` WHERE `Table` = '" & ListView1.SelectedItems(0).Text & "' ")


        Dim DbColumns As String = ""
        Record = View.Fetch()
        While Not Record Is Nothing
            DbColumns = DbColumns & "`" & Record.StringData(1) & "`"
            Record = View.Fetch()
            If Not Record Is Nothing Then
                DbColumns = DbColumns & ", "
            End If
        End While

        View = Database.OpenView("SELECT " & DbColumns & " FROM `" & ListView1.SelectedItems(0).Text & "` ")

        Dim ColumnsAR() As String = Split(DbColumns, "`, `")

        ColumnsAR(0) = ColumnsAR(0).TrimStart("`")

        ColumnsAR(ColumnsAR.Length - 1) = ColumnsAR((ColumnsAR.Length - 1)).TrimEnd("`"c)

        DataView1.Table = New DataTable(ListView1.SelectedItems(0).Text)

        For Each TableColumn As String In ColumnsAR

            DataView1.Table.Columns.Add(TableColumn, Type.GetType("System.String"))

        Next TableColumn

        Dim NewRow As DataRow

        Record = View.Fetch()
        While Not Record Is Nothing

            NewRow = DataView1.Table.NewRow()
            For I As Integer = 0 To ColumnsAR.Length - 1
                    NewRow(ColumnsAR(I)) = Record.StringData(I + 1)
                Catch ex As Exception
                    NewRow(ColumnsAR(I)) = "(Binary)"
                End Try


            Record = View.Fetch()

        End While

    End Sub

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Software Developer CIMEX S.A.
Cuba Cuba
Rodolfo Ortega is a Cuban Computer Scientist. He works as IT Auditor for the CIMEX S.A. subsidiary in Holguin, Cuba. He lives and works in Holguin, in the eastern part of the island of Cuba.

You can contact him at rodolfom[] for any personal message: Ideas on new articles, bibliography about new APIs, questions, are wellcome.

Submit questions related with current article to the article forum.

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170217.1 | Last Updated 22 Nov 2006
Article Copyright 2006 by rmortega77
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid