Click here to Skip to main content
13,899,765 members
Click here to Skip to main content
Add your own
alternative version


28 bookmarked
Posted 22 Nov 2006

Microsoft Installer Database Reader

, 22 Nov 2006
Rate this:
Please Sign up or sign in to vote.
An MSI database file reader, helps to get insights into the .msi DB structure.


There are many tools, such as Orca, for tampering with the Microsoft Installer Database .msi files. This sample shows how to build a MSI database file reader. Though it does not allow to modify it, it will be helpful to those who want to get some insights in to the structure of an MSI.

Using the code

Create the project

  1. File -> New -> New project

    Create a new MsiDbReader Visual Basic Windows Application.

Add the Windows components

  1. Click View -> Toolbox (Ctrl+Alt+X).

  2. Drag an OpenFileDialog, an ImageList, and a MainMenu into the form.

  3. Right click the OpenFileDialog1 in the form designer -> Properties. Set the Filter property to "Microsoft Installer DB (*.msi)|*.msi|All files (*.*)|*.*".

  4. Right click the ImageList1 in the form designer -> Properties.

  5. Click the button next to the Image Collection property. Add an icon image.

  6. Right click MainMenu1 -> Edit menu. Type &Open.

  7. From the Toolbox, drag a ListView into the form.

  8. Right click the ListView1 -> Properties. Set the Dock property to Left. Set SmallImageList and StateImageList properties to ImageList1. Set MultiSelect property to False. Set View property to SmallIcon.

  9. From the Toolbox, drag a Splitter into the form.

  10. From the Toolbox, drag a DataGrid into the form.

  11. From the Toolbox Data tab, drag a DataView into the form.

  12. Right click DataGrid1 -> Properties. Set Dock property to Fill. Set DataSource property to DataView1.

Add the code:

Right click Form1 -> View Code. Add the following variable declarations to the Form1 class:

Dim Installer
Dim Database
Dim View
Dim Record

Add the following MenuItem1_Click event method:

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

        ' _Tables stores all database 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

Add the following ListView1_SelectedIndexChanged event method:s

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")

    ' _Columns stores all database table 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, _

    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

Build and run the application.


  • 21 Nov. 2006 - Intial release.


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...

Comments and Discussions

QuestionApply a Patch to the MSI Pin
tshades12-Jul-13 6:15
membertshades12-Jul-13 6:15 
GeneralMy vote of 3 Pin
RogerioHsjr27-Jan-13 8:57
memberRogerioHsjr27-Jan-13 8:57 
GeneralThanks . Pin
cc_wang4-Sep-07 19:13
membercc_wang4-Sep-07 19:13 
GeneralCreateObject("WindowsInstaller.Installer") for C# Pin
Jose Rizal28-Feb-07 13:00
memberJose Rizal28-Feb-07 13:00 
GeneralRe: CreateObject("WindowsInstaller.Installer") for C# Pin
rmortega772-Mar-07 5:19
memberrmortega772-Mar-07 5:19 
GeneralRe: CreateObject("WindowsInstaller.Installer") for C# Pin
royk12326-Apr-07 21:55
memberroyk12326-Apr-07 21:55 
QuestionExtract files? Pin
Martin Lercher1-Dec-06 6:46
memberMartin Lercher1-Dec-06 6:46 
GeneralGreat Utility Pin
sides_dale28-Nov-06 18:05
membersides_dale28-Nov-06 18:05 
GeneralThanks Pin
Ilíon22-Nov-06 10:33
memberIlíon22-Nov-06 10:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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