How can I change MSI in memory?

I would like to read the MSI file in a MemoryStream (or something similar) and modify it. What is the easiest way to do this without damaging the MSI?

All I need to do is change the value of one of the properties in MSI. I would prefer something in .Net, but I am open to other platforms.

Update:

Here's my working code using the Windows platform SDK, COM link to the Microsoft Windows Installer object library, and the WindowsInstaller namespace:

Installer installer = Activator.CreateInstance(Type.GetTypeFromProgID("WindowsInstaller.Installer")) as Installer; Database msi = installer.OpenDatabase("WixTest.msi", MsiOpenDatabaseMode.msiOpenDatabaseModeTransact); View view = msi.OpenView("update `Property` SET `Property`.`Value`='99' where `Property`='USERID'"); view.Execute(null); msi.Commit(); 
+4
source share
2 answers

Look at the Windows SDK , there are tons of samples included when using the Windows Installer API .

This uses a simplified version of the VBScript command line:

 Option Explicit Const msiOpenDatabaseModeReadOnly = 0 Const msiOpenDatabaseModeTransact = 1 Dim openMode : openMode = msiOpenDatabaseModeTransact Dim argCount:argCount = Wscript.Arguments.Count If (argCount < 3) Then WScript.Echo "usage: msisetproperty.vbs <msi> <property> <value>" : WScript.Quit 1 Dim MY_MSI : MY_MSI = Wscript.Arguments(0) Dim sProp1 : sProp1 = Wscript.Arguments(1) Dim sVal1 : sVal1 = Wscript.Arguments(2) Dim filesys : Set filesys=CreateObject("Scripting.FileSystemObject") If Not filesys.FileExists(MY_MSI) Then WScript.Echo "Unable to find msi, exiting" : WScript.Quit 1 Dim installer, database, view, result Set installer = CreateObject("WindowsInstaller.Installer") Dim sumInfo : Set sumInfo = installer.SummaryInformation(MY_MSI, 0) Set database = installer.OpenDatabase (MY_MSI, openMode) Set view = database.OpenView ("UPDATE Property SET Value='" & sVal1 & "' WHERE Property='" & sProp1 & "'") view.Execute database.Commit Set database = nothing 
+3
source

Despite the fact that this post is really old, for the sake of users who get here through search engines, there is a very neat .Net library that implements almost all the functions of the Windows installer SDK and is actively supported by Rob Menshing, a senior Microsoft developer. Its present in Wix Toolset, and you can get v3.6 RC0 here. After installing this toolkit, add a link to the Microsoft.Deployment.WindowsInstaller.dll file that is contained in the installation directory of this toolkit, and you should go. You can easily load the entire msi database into a DataSet and perform the necessary read / write operations and finally commit the changes to msi.

0
source

Source: https://habr.com/ru/post/1303029/


All Articles