How to extract and run a file during installation

心不动则不痛 提交于 2020-01-05 08:47:08

问题


I have created a Custom Action (DTF) with C#.
In that CA, I would like to extract a file from the msi (declared as Binary in wix) and run it with some arguments.
I haven't found any samples or help about that..
I have to execute a request on the msi, but I would like to have a sample. Thanks!


回答1:


The DTF.chm has a sample how to update the Binary table. It's in "Working with MSI Databases" topic. And you can guess how to do the opposite operation. The code might look like this:

  using (var db = new Database("test.msi", DatabaseOpenMode.Direct))
  {
    using (var view = db.OpenView("SELECT `Data` FROM `Binary` WHERE `Name` = '{0}'", "testbinary"))
    {
      view.Execute();
      var rec = view.Fetch();

      var inStream = rec.GetStream("Data");
      if (inStream != null)
      {
        using (var file = File.OpenWrite("S:\\testfile.zip"))
        {
          CopyStream(inStream, file);
        }
      }
    }
  }

The code of CopyStream method can be taken from this answer of omnipresent Jon Skeet. Note that if you should do this from CA, you will reference the database object like session.Database, instead of creating it.



来源:https://stackoverflow.com/questions/8034133/how-to-extract-and-run-a-file-during-installation

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!