Click here to Skip to main content
15,860,972 members
Articles / Desktop Programming / MFC
Article

Reading Data from MSI Database

Rate me:
Please Sign up or sign in to vote.
2.90/5 (9 votes)
29 Apr 20033 min read 139K   2.6K   20   19
A console application to read data from a Windows Installer database

Introduction

I was in need of reading data from an .msi file and after reading a nice article in the form of a pdf file, I made a simple console application that takse 2 command line arguments (first is full path to .msi file second one is the table name). I prefered doing a console application because it will be useful to all even having MFC or windows knowledge.

Background

Last week I installed InstallShield for Windows Installer 1.5 on my system and some how I learned how to create an .msi setup file. I was in need of it as we planned to port the tool on which I'm working to the newer version of InstallShield. I searched for help but finally helped myself to learn how to create msi files with InstallShield. I wouldn't say I mastered InstallShield but I can say I know little bit of InstallShield.

Actually the tool for which I have been working on needs the details of .msi files to create MOF files, so I was trying to read the .msi database (.msi is a setup file implemented as a database by Microsoft and it is run by Windows Installer, a service which runs in Windows 2000 and Windows XP).

Using the Code

First location I refered is MSDN. It says what are the functions we have to manipulate a .msi database. But as my attempt to work myself with the MSDN help to read .msi databse didn't work. So I searched on net. and I got nic pdf file regarding this pdf file http://www.wise.com/filelib/MSIwhitepaper.pdf. Please read the article for a full description on "how to". I used the code help from this article only. The flow goes like this. First we have to start with MsiOpenDatabase(..) which gives a MSIHANDLE after successful opening of the msi database. Then I called MsiDatabaseOpenView(hDatabase,szSelect,&hView) where hDatabase is the handle got from MsiOpenDatabase(). szSelect is a normal SQL query, then hView is the MSIHANDLE returned by this function on success. This function when called creates a view with the given query. To get the actual records we have to call MsiViewExecute(), which gives the perfectness to the view(means practically this function executes the query and stores the result in the view) Then remaining part of the code is parsing the data and printing on the screen. I once again repeat the pdf I read is the source for my application. I thank "Gary Chirhart" for writing such a nice article on Installer. my application takes 2 command line arguments( other than application name)

  1. msi file path: rememeber to give the path with "\\" separation like D:\\Share\\VMTNet.msi
  2. A table name existing in .msi database. There are so many tables but I prefer to give "File" as 2nd parameter.This table contains all the details embedded files in the .msi database.

For better understanding of the database structure one can use "ORCA" tool.

Points of Interest

The interesting thing I learned is actually we don't need any third party tools like Installshield or wise Installer to create .msi setup files. Everything can be done by us The only thing the third party vendors are doing is making things simple so that we can concentrate on development of our software so that we need not worry much about creating installers to our software.

License

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


Written By
Architect Careerscale IT Consulting LLP
India India
Hi, all

I have been working on java/j2EE technologies, and some time back in Microsoft technologies.


Harinath Mallepally,
Careerscale IT Consulting LLP
http://careerscale.in
Hyderabad
India

Comments and Discussions

 
Generalthank you. Pin
sanji200915-Apr-10 23:56
sanji200915-Apr-10 23:56 
GeneralGood info! Pin
Portatofe2-Oct-08 6:02
Portatofe2-Oct-08 6:02 
very informative and I look forward to the walk throughs


GeneralNeed examples Pin
z8871209-Aug-07 22:48
z8871209-Aug-07 22:48 
GeneralThanks for a useful link Pin
TroubleSolver20-Nov-05 13:26
TroubleSolver20-Nov-05 13:26 
GeneralGood work Pin
josephjk16-Sep-03 6:43
josephjk16-Sep-03 6:43 
QuestionVBScript anyone? Pin
Mike Klimentiev6-May-03 8:15
Mike Klimentiev6-May-03 8:15 
AnswerRe: VBScript anyone? Pin
harinath6-May-03 17:29
professionalharinath6-May-03 17:29 
AnswerRe: VBScript anyone? Pin
Blue(Shanghai)18-Jul-06 17:25
Blue(Shanghai)18-Jul-06 17:25 
AnswerRe: VBScript anyone? Pin
Mike Klimentiev19-Jul-06 8:50
Mike Klimentiev19-Jul-06 8:50 
GeneralNo Knowledge of Windows Installer Pin
Heath Stewart30-Apr-03 17:45
protectorHeath Stewart30-Apr-03 17:45 
GeneralRe: No Knowledge of Windows Installer Pin
harinath30-Apr-03 23:27
professionalharinath30-Apr-03 23:27 
GeneralRe: No Knowledge of Windows Installer Pin
Heath Stewart1-May-03 2:40
protectorHeath Stewart1-May-03 2:40 
GeneralRe: No Knowledge of Windows Installer Pin
harinath1-May-03 2:55
professionalharinath1-May-03 2:55 
GeneralRe: No Knowledge of Windows Installer Pin
Anonymous6-May-03 11:59
Anonymous6-May-03 11:59 
GeneralRe: No Knowledge of Windows Installer Pin
harinath6-May-03 17:34
professionalharinath6-May-03 17:34 
GeneralRe: No Knowledge of Windows Installer Pin
Anonymous26-Apr-05 5:00
Anonymous26-Apr-05 5:00 
GeneralRe: No Knowledge of Windows Installer Pin
TroubleSolver20-Nov-05 13:23
TroubleSolver20-Nov-05 13:23 
GeneralRe: No Knowledge of Windows Installer Pin
jbalaji8421-Dec-06 19:52
jbalaji8421-Dec-06 19:52 
GeneralRe: No Knowledge of Windows Installer Pin
tom Stratemeyer15-Dec-03 14:54
susstom Stratemeyer15-Dec-03 14:54 

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.