Removing file from MSI's binary table does not change MSI file size

I tried to google my problem but without much luck. I'm trying to modify an MSI file through C#'s winform. The issue I'm having is that when I delete files (that I've added!) from the binary table, the records are gone but the MSI's file size is not reduced.

Here is how I add new files to the binary table:

        view = database.OpenView("INSERT INTO Binary (Name,Data) VALUES ('" + fileName + "', ?)");
        record = installer.CreateRecord(1);
        record.SetStream(1, filePath);
        if(record != null)
  • A commit is happening later in the code :


This is how I delete a record:

  view = database.OpenView("SELECT * FROM Binary WHERE Name = '" + binary + "'");
  Record record = view.Fetch();
  if (record != null && record.FieldCount > 0)
      view.Modify(MsiViewModify.msiViewModifyDelete, record);              
  if (record != null)

I don't think there is a problem with the deletion as files that were inserted using Orca were deleted just fine.

When I delete (either with Orca or with my code) a record that was inserted by me using the first code block above, the record is gone but the MSI's file size is reduced just by 10-20KB (probably the record's size) even if the file was 20MB.

So... Where is my problem...??

Hope I explained the situation well enough for you.

btw, just adding that I tried inserting a photo into the binary table using the code above and extracted the file using Orca. It was fine and the photo was OK. So it does work, just wrong I guess.


You should look into making a copy of the database and then modifying the copy. Then you can generate a transform based on the deltas. While MSI is a database, it's not a full featured database and there is no compact function that I know of.

In case someone will encounter the same problem, the issue was caused because I opened the database in MsiOpenDatabaseMode.msiOpenDatabaseModeDirect mode. Opening it in MsiOpenDatabaseMode.msiOpenDatabaseModeTransact mode fixed the file size issue.

Need Your Help

django-mssql on debian linux

debian django-pyodbc django-mssql

Anyone has success on install django-mssql on linux machine? My deploy server is debian linux and I cant deploy my applications made on windows machine.

Meteor reset on Heroku

mongodb heroku meteor

What is the best way to redeploy an alpha version on Heroku, and perform a meteor reset for the server mongo fixtures to be re-executed on the server?