Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a new row to Property table of msi file using c#/cmd

I need to add a new row in the msi file database i.e. I need to add a new row in Property table. ServerUrl = "www.google.com". I have tried using orca and I was able to do it. But this is a manual process. I need to do it via code.

  1. Without starting the installer.
  2. Without using orca

How can I achieve this in c#? I tried to use the command line options but it starts the installer. I need to edit the table without starting the installer in the existing msi file.

like image 955
alohamora Avatar asked Jan 23 '26 08:01

alohamora


1 Answers

Been a while since I looked at this, I'll just point you to two previous answers.

Important!: You should always avoid post-processing the MSI if you can. You can create an MST (transform) to add this to the MSI during installation or set it as a property at the command line. See this old answer: Transforms and PUBLIC PROPERTIES: heavy-weight and light-weight customization of MSI installers and from section "Customizing Silent Install" onwards.


VBScript: There is a VBScript WiRunSQL.vbs - which is part of the Windows SDK - just search your SDK folder if you have Visual Studio installed.

You can use this and a batch file to post-process an MSI (sample here):

cscript.exe "%~dp0"\WiRunSQL.vbs "MySetup.msi" "INSERT INTO `Property` (`Property`, `Value`) VALUES ('MYPROPERTY', 'PropertyValue')"  
pause

There is a previous answer here on how to change things in the ControlCondition table.


C#: There is also some C# code here you can test. Not that well tested, and not the greatest code overall, but have a look?

Alternatively try this source. You need to know what DTF is for this source. What is DTF? DTF is included in the code by this reference: using Microsoft.Deployment.WindowsInstaller;

Briefly inlined:

public static void Set(string msi, string name, string value)
{
   using (Database db = new Database(msi, DatabaseOpenMode.Direct))
   {
      db.Execute("UPDATE `Property` SET `Value` = '{0}' WHERE `Property` = '{1}'", value, name);
   }
}

Some Links:

  • Currupted file in non-english locale (encoding problem?)
  • cx_freeze bdist_msi: create registry entries?
  • MSI code from github
  • Features, Transforms, Properties
  • How to tag or customize the a binary (for example of an installer)
like image 92
Stein Åsmul Avatar answered Jan 24 '26 21:01

Stein Åsmul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!