2

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.

Eduardo Ortiz
  • 715
  • 3
  • 14
alohamora
  • 61
  • 5

1 Answers1

2

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:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • If it worked you can set the answer accepted. What solution did you end up with? – Stein Åsmul Oct 07 '21 at 13:31
  • C# solution, sure let me set the answer accepted – alohamora Oct 07 '21 at 16:10
  • Hi @stein if possible can you please help here: https://stackoverflow.com/questions/69556798/wix-customaction-gives-error-2896-when-used-with-publish-event-doaction – alohamora Oct 14 '21 at 01:49
  • A bit busy right now, but please check if this project helps: https://github.com/glytzhkof/WiXOpenLogFile and [have a read here](https://stackoverflow.com/a/60850388/129130) and follow the links please. There are further WiX examples at the top level of that Github repository. – Stein Åsmul Oct 14 '21 at 23:58