如何在安装过程中提取和运行文件 [英] How to extract and run a file during installation

查看:114
本文介绍了如何在安装过程中提取和运行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用C#创建了自定义操作(DTF).
在该CA中,我想从msi(在wix中声明为Binary)中提取文件,并使用一些参数运行它.
我还没有找到任何样品或帮助..
我必须在MSI上执行一个请求,但是我想要一个示例.谢谢!

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!

推荐答案

DTF.chm提供了一个如何更新Binary表的示例.在使用MSI数据库"主题中.您可以猜测如何执行相反的操作.代码可能看起来像这样:

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);
        }
      }
    }
  }

CopyStream方法的代码可以从

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.

这篇关于如何在安装过程中提取和运行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆