简体   繁体   English

尝试从WIX MSI运行嵌入式工具以进行选择性安装

[英]Attempting to run embedded tool from WIX msi for selective installation

Basically I'm trying to build a WIX msi that can run devcon.exe (command line version of windows hardware manager) to detect if a particular piece of hardware is installed. 基本上,我试图构建一个可以运行devcon.exe(Windows硬件管理器的命令行版本)的WIX msi,以检测是否安装了特定的硬件。 If it is, then install msi A, else install msi B (A and B already exist as separate msi packages, we need automatic selective installation based on the hardware). 如果是,则安装msi A,否则安装msi B(A和B已经作为独立的msi软件包存在,我们需要基于硬件的自动选择性安装)。

Currently I've installed the WIX SDK and have created a WIX project that correctly builds an msi. 当前,我已经安装了WIX SDK,并创建了正确构建msi的WIX项目。 I can do simple things like execute CustomActions to open notepad.exe, that kind of simple things. 我可以做一些简单的事情,例如执行CustomActions打开notepad.exe。

1st problem: I'm having trouble finding out how to package a file into the installer that isn't going to be installed into a directory. 第一个问题:我在寻找如何将文件打包到不会安装到目录中的安装程序时遇到麻烦。 I've found references to it, but nowhere that explicitly states how to do it. 我找到了对它的引用,但没有任何地方明确说明如何做。 I don't have to put it inside 'Directory' tags, if it's not going to be installed onto the host drive, right? 如果不必将其安装在主机驱动器上,则不必将其放在“目录”标签中,对吗?

2nd problem: devcon.exe doesn't (from what I can tell, correct me if I'm wrong) seem to change it's return value depending on what it finds, probably because it does so many things and isn't restricted to whether a hardware device exists or not. 第二个问题:devcon.exe不会(根据我的判断,如果我错了,请更正我)似乎会根据发现的内容更改其返回值,这可能是因为它做了很多事情并且不受限于是否硬件设备是否存在。 So if I can get it embedded and get it to run, then I need to somehow take what it outputs to the standard output stream, and then parse it for the particular values that I'm looking for. 因此,如果我可以将其嵌入并使其运行,那么我需要以某种方式将其输出到标准输出流,然后将其解析为我正在寻找的特定值。

Of course it would be a bit easier because I've already got a batch file that can do the parsing and set an environment variable which will tell me what I need to know, but, if I can embed them both, how do I get the batch file to reference the embedded devcon.exe, and then get WIX to read the variable, or perhaps I can set one up (or a property) in WIX and then set it from the batch file? 当然,这会容易一些,因为我已经有了一个可以进行解析并设置环境变量的批处理文件,该变量将告诉我我需要知道的内容,但是,如果我可以将它们都嵌入,该如何获取?批处理文件引用嵌入式devcon.exe,然后让WIX读取变量,或者我可以在WIX​​中设置一个(或属性),然后从批处理文件进行设置?

Maybe I should create a dll custom action instead? 也许我应该改为创建dll自定义操作? Is it possible to run an embedded executable from a dll custom action? 是否可以通过dll自定义操作运行嵌入式可执行文件? Then I could run devcon.exe, and do all the parsing in there, then simply set a Wix variable or Property to choose what to do next. 然后,我可以运行devcon.exe,并在那里进行所有解析,然后只需设置Wix变量或“属性”来选择下一步。

3rd problem: being able to run one msi from another. 第三个问题:能够从另一个运行一个msi。 I'm not quite upto this yet, but I've found (http://softwareinstall.blogspot.com/2008/06/fun-with-msiembeddedchainer.html) which looks promising, although I haven't read through it all yet. 我还没有完全了解这一点,但是我发现(http://softwareinstall.blogspot.com/2008/06/fun-with-msiembeddedchainer.html)看起来很有希望,尽管我还没有阅读全部然而。 One problem at a time, I've certainly got enough already :) 一次有一个问题,我当然已经受够了:)

Okay, first problem is solved: 好的,第一个问题已解决:

<Binary Id="Devcon" SourceFile="D:\Programming\Device_Selection\Device_Selection\devcon.exe"/>
<CustomAction Id="RunDevcon" BinaryKey="Devcon" ExeCommand="resources *vendor*device*" Return="check" Execute="deferred" Impersonate="no" />

This ensures that the devcon.exe tool is embedded in the installer and that I can run it in administrator mode (which doesn't work unless you specify Impersonate to "no" and Execute to "deferred"). 这样可以确保devcon.exe工具嵌入在安装程序中,并且可以在管理员模式下运行它(除非您将Impersonate设置为“ no”并将Execute设置为“ deferred”,否则该模式将不起作用)。

The next thing I need to do is be able to read the output that devcon usually send to the console (ie. cmd window) and then parse it for information. 我需要做的下一件事是能够读取devcon通常发送到控制台的输出(即cmd窗口),然后对其进行解析以获取信息。 Is there a way to capture that output? 有没有办法捕获该输出?

For the 2nd problem, I'd create an EXE or DLL custom action which starts devcon.exe, reads its output and parses it. 对于第二个问题,我将创建一个EXE或DLL自定义操作,该操作将启动devcon.exe,读取其输出并进行解析。 The devcon.exe itself could be stored in resources of EXE/DLL and extracted into a temporary directory before starting, then you remove it when done with it. devcon.exe本身可以存储在EXE / DLL的资源中,并在启动前提取到一个临时目录中,然后在完成后将其删除。

If you choose DLL, you can change MSI public properties. 如果选择DLL,则可以更改MSI公共属性。 That way you can set a property which will control what will be done next in the MSI. 这样,您可以设置一个属性,该属性将控制接下来在MSI中执行的操作。

If you choose EXE, all you have is exit code. 如果选择EXE,则仅是退出代码。 As far as I know there's not much you can do with it actually in MSI. 据我所知,在MSI中您实际上无能为力。


Chaining MSI installs is not recommended. 不建议链接MSI安装。 You can embed both drivers into one package and select which components to install depending on the property set as the result from devcon.exe detection. 您可以将两个驱动程序都嵌入一个程序包中,并根据devcon.exe检测的结果,根据属性集选择要安装的组件。


Another approach would be to create a bootstrapper EXE which runs devcon.exe and determines which package to install. 另一种方法是创建一个引导程序EXE,该程序运行devcon.exe并确定要安装的软件包。 Then it simply installs the correct MSI package. 然后,它仅安装正确的MSI软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM