The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Win32::MSI::DB - Modify MSI databases


  use Win32::MSI::DB;

  $database = Win32::MSI::DB::new("filename", $flags);

  $database->transform("filename", $flags);

  $table = $database->table("table");
  $view = $database->view("SELECT * FROM File WHERE FileSize < ?", 100000);

  @rec = $table->records();
  $rec4 = $table->record(4);

  $rec->set("field", "value"); # string
  $rec->set("field", 4);       # int
  $rec->set("field", "file");  # streams

  $rec->getintofile("field", "file");

  $field = $rec->field("field");
  $data = $field->get();



Obtaining a database object

MSI::DB::new($filename, $mode) returns a new database object, open in one of the following modes:


This doesn't really open the file read-only, but changes will not be written to disk.


Open in transactional mode so that changes are written only on commit. This is the default.


Opens read/write without transactional behaviour.


This creates a new database in transactional mode.

A database object allows creation of tables or views. If you simply need access to a table you can use the table method; for a subset of records or even a SQL-query you can use the view method.

Using transforms

When you have got a handle to a database, you can successively apply transforms to it. You do this by using transform, which needs the filename of the transform file (normally with extension .mst) and optionally a flag specification.

Most of the possible flag values specify which merge errors are to be suppressed.


Ignores adding a row that already exists.


Ignores adding a table that already exists.


Ignores deleting a row that doesn't exist.


Ignores deleting a table that doesn't exist.


Ignores updating a row that doesn't exist.


Ignores that the code pages in the MSI database and the transform file do not match and neither has a neutral code page.


This flag combines all of the above mentioned flags. This is the default.


This flag should not be used together with the other flags. It specifies that instead of merging the data, a table named _TransformView is created in memory, which has the columns Table, Column, Row, Data and Current.

This way the data in a transform file can be directly queried.

For more information please see

This doesn't open the file read-only, but changes will not be written to disk.

A transform is a specification of changed values. So you get a MSI database from your favorite vendor, make a transform to overlay your own settings (the target installation directory, the features to be installed, etc.) and upon installation you can use these settings via a commandline similar to

  msiexec /i TRANSFORMS = F<your transform file> F<the msi database> /qb

The changes in a transform are stored by a (table, row, cell, old value, new value) tuple.

Fetch records from a table or view

When you have obtained a table or view object, you can use the record method to access individual records. It takes a number as parameter. Records are fetched as needed. Using undef as parameter fetches all records and returns the first (index 0).

Another possibility is to use the records method, which returns an array of all records in this table or view.

A record has fields

A record's fields can be queried or changed using the record object, as in

  $rec->set("field", "value"); # string
  $rec->set("field", 4);       # int
  $rec->set("field", "file");  # streams

  $rec->getintofile("field", "file");

or you can have separate field objects:

  $field = $rec->field("field");

  $data = $field->get();

Access to files (streams) is currently not finished.


Each object may access an error method, which gives a string or an array (depending on context) containing the error information.

Help wanted: Is there a way to get a error string from the number which does not depend on the current MSI database? In particular, the developer errors (2000 and above) are not listed.


This module depends on Win32::API, which is used to import the functions out of the msi.dll.

Currently the Exporter is not used - patches are welcome.


Please contact for questions, suggestions, and patches (diff -wu2 please).

A big thank you goes to DBH for various changes throughout the code.

Further plans

A Win32::MSI::Tools package is planned - which will allow to compare databases and give a diff, and similar tools.

I have started to write a simple Tk visualization.