1

我使用 AddIn Express .Net 组件创建了一个 Excel 插件。业务用户使用构建团队提供的 MSI 安装加载项。每次我们对产品进行任何更改并将其提供给业务用户时,他们都需要手动卸载现有插件,然后使用更新的 MSI 安装新插件。

我想知道是否有任何方法可以使用一些 Windows 批处理文件、脚本或小型 C# 控制台程序来自动化此过程。理想情况下,它应该卸载现有的插件,等待卸载过程完成,然后安装新的插件。

我使用 Msiexec、scriptcs 等尝试了多个选项,但到目前为止没有任何成功。我的主要问题是一旦现有的加载项卸载过程开始,它会立即开始安装新的加载项,然后会弹出标准的 Windows 消息“安装已经在进行中......”

任何帮助,将不胜感激。

谢谢

4

2 回答 2

1

我已经回答了一个似乎有帮助的类似问题:

Windows 批处理文件不等待命令完成

通常,当您有一个包含两行的批处理文件时:

call msiexec /x {...} /qb
call msiexec /i "c:\myPath\myProduct.msi" /qb

它应该在安装开始之前等待卸载。

  • “电话”很重要!
  • 对于以前版本的卸载,您必须使用/x {ProductCode to fill in}而不是/x "filename". 在每种情况下,使用产品代码更安全。
  • 为了确定会发生什么,您可以pause在两者之间和末尾添加一条线。

如果它似乎仍然不起作用,则必须循环直到产品真正卸载,等待两秒钟然后继续安装。

有几种可能性可以找出是否仍然安装了程序。

大多数人会推荐 VB 脚本作为最简单的解决方案,至少这些是最知名的。这是来自 saschabeaumont 的 VBS 片段,用于来自另一个问题的卸载调用: MSI Install Fails because "Another version of this product is already installed"

它主要找出给定产品名称(部分)的产品代码,如果合适则开始卸载(注意部分匹配)。如果卸载已经完成(= 产品不再在已安装的产品列表中),您可以将它用于相同的事情并再次复制算法以异步询问。

当然,在其他脚本语言中也是可能的,即 JScript、Powershell 和传统编程语言。在纯批处理脚本中很难做到 - 例如,如果安装了产品,您可以测试HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall下的 ProductCode 注册表项。但只有一个缺点要提:如果批处理是从 32/64 位子系统启动和/或 MSI 是 32/64 位,则必须考虑差异。因此,我建议使用 VBS 而不是批处理(您可以从批处理中调用它cscript xxx.vbs)。

于 2014-09-24T15:29:37.547 回答
0

A few things here:

  1. First question is if you are aware of the xlstart folder in Excel which allows you to easily load certain addin files on Excel startup just by putting them into this folder. As far as I know you can't disable addins this way via the Excel GUI, you have to remove them from the xlstart folder to not load them into Excel.

  2. Second issue is that you should update your MSI file to use a major upgrade so that it automatically removes the existing MSI whilst installing the new one. This would probably remove the whole problem that you describe.

  3. Finally you should be able to use start wait msiexec.exe /i /qn File.msi to have your batch file wait for msiexec to return from the first msiexec call. Check Waiting for msiexec.exe to finish. Or you can try MSI Software Deployment Using Batch File.

于 2014-09-25T14:06:43.637 回答