tags:

views:

188

answers:

3

I have found how to read MSI files with .Net. Some of them use some libraries that come with Wix. Is there a way I read MSI data using Java. I would like to access the tables and get text values.

+1  A: 

An .MSI is basically a database. If you can read an MS Access .MDB file with Java's JdbcOdbc driver, you can use the same code to open the .MSI instead and read it's tables.

Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String msiFileName= "d:/java/test.msi";
String connectString = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
connectString += msiFileName.trim() + ";DriverID=22;READONLY=true}";
Connection con = DriverManager.getConnection( connectString ,"",""); 

At least in theory. :)

Geno
Unfortunately, it throws a java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver] Cannot open database '(unknown)'. It may not be a database that your application recognizes, or the file may be corrupt.
tou
Perhaps try one of the java native access readers (eg, jackcess)?
jsight
In theory it should work. The problem is probably the MSI itself. If it isn't a standard Windows Installer MSI, it might fail.
Geno
jackcess did not work either. It gave a java.io.IOException: Unsupported version: 0.
tou
+1  A: 

MSI files are COM structured storage. http://en.wikipedia.org/wiki/COM_Structured_Storage

There are a few options. You could try to access it with something like this: http://poi.apache.org/poifs/index.html

You could use JNI to access the native MSI APIs.

Or, you could shell out to something like a vbscript. The script dumps the results you want to stdout, which you then capture and parse in your java app.

Ed
I found this packager.jar file from the JDIC project. It has a JNI wrapper to WinMSIWrapper.dll. However, I went with the vbscript approach.
tou
A: 

Can you use Windows Installer API via Java?

The API is the only supported way of manipulating MSI files. If you're using .NET or WiX, you'll either be using these functions or functions that call these.

The binary file format of MSI is undocumented and may change between versions, so trying to read/write the binary format directly is just going to give you a real headache.

sascha