如何编写自定义操作 DLL 以在 MSI 中使用?
这是我打算自己回答的问题,但请随意添加其他方法来完成此任务。
我正在打包一个应用程序以用于各种配置,并且我确定在 MSI 中执行自定义逻辑的最可靠方法是编写我自己的自定义操作 DLL,该 DLL 能够从 PROPERTY 表中读取/写入,终止进程,确定应用程序是否需要升级(然后将答案记录在 PROPERTY 表中),并写入标准 MSI 日志。
This is a question I intend to answer myself, but please feel free to add other ways to accomplish this.
I was packaging an application for use on a wide variety of configurations, and I determined that the most reliable way to perform custom logic within my MSI would be to write my own custom action DLL that would be able to read/write from the PROPERTY table, kill a process, determine if an application needed to be upgraded (and then record the answer in the PROPERTY table), and write to the standard MSI log.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的解决方案采用 Delphi,需要开源 JEDI API 翻译,您可以在此处下载< /a>. 我发现的一个问题是使用 JwaMSI 标头的示例很少。 希望有人会发现这是一个有用的例子。
这是主要单元,其后是第二个支持单元(您可以将其包含在同一个 DLL 项目中)。 只需在 Delphi 中创建一个新的 DLL(库),然后复制/粘贴此代码即可。 该单元导出 2 个可从 MSI 调用的函数。 它们是:
这两个函数都从属性表中读取 PROPERTY 值,并在完成时设置一个值。 这个想法是,第二个自定义操作可以读取此属性并抛出错误,或将其用作安装条件。
此代码更多地用于示例,在下面的示例中,它检查“notepad.exe”的版本是否需要升级(这意味着存储在属性表值“NOTEPAD_VERSON”中的版本大于版本号)系统上的 notepad.exe)。 如果不是,则它将“UPGRADEABLE_VERSION”属性设置为“NO”(该属性默认设置为“YES”)。
此代码还会在 PROPERTY 表中查找“PROGRAM_TO_KILL”,并在该程序正在运行时将其终止。 它需要包含要杀死的程序的文件扩展名,例如“Notepad.exe”
,这里是支持单元“MSILogging.pas”。 该单元可以在其他 MSI DLL 项目中按原样使用。
My solution is in Delphi, and requires the open-source JEDI API translations that you can download here. One problem that I have found is that examples for using the JwaMSI headers are few and far between. Hopefully someone will find this as a useful example.
Here is the main unit, with a 2nd supporting unit following it (that you can include in the same DLL project). Simply create a new DLL (library) in Delphi, and copy/paste this code. This unit exports 2 functions that are callable from the MSI. They are:
Both of these functions read a PROPERTY value from the property table, and set a value when the complete. The idea is that then a 2nd custom action can read this property and throw an error, or use it as an install condition.
This code is more for an example, and in this example below it is checking to see if the version of 'notepad.exe' needs to be upgraded (that means the version stored in the property table value "NOTEPAD_VERSON" is greater than the version of notepad.exe on the system). If it is not, then it sets the property of "UPGRADEABLE_VERSION" to "NO" (this property is set to "YES" by default).
This code also looks in the PROPERTY table for "PROGRAM_TO_KILL" and will kill that program if it is running. It needs to include the file extension of the program to kill, e.g. "Notepad.exe"
And here is the supporting unit "MSILogging.pas". This unit can be used as-is in other MSI DLL projects.