【问题标题】:Custom action of Wix failed to call vb scriptWix 的自定义操作调用 vb 脚本失败
【发布时间】:2018-08-30 19:28:17
【问题描述】:

我在包本身中有一个 VB 脚本。我需要使用 CMD 调用它,调用脚本的默认方式需要花费太多时间,所以我尝试使用 CMD 和 CSCRIPT 调用它,但安装程序在安装时会引发错误。

我正在使用以下代码,但它没有按预期工作。我搜索了很多,但没有找到解决方案。

<Binary Id="ServiceInstall"  SourceFile="..\..\..\AddVirDir.vbs" />

 <CustomAction Id="InstallService" BinaryKey ="ServiceInstall" 
               ExeCommand="CMD /C &quot;[#ServiceInstall]&quot;" 
               Execute="immediate" Return="check"  HideTarget="no" Impersonate="no"/>

【问题讨论】:

  • AddVirDir.vbs - 你在做 IIS 吗?
  • 是的,我正在做 IIS 的工作。基本上它是 VB 脚本创建一个虚拟目录。
  • 我添加了一个新答案,以防万一。

标签: wix windows-installer


【解决方案1】:

WiX IIS 元素:如果这都是 IIS,我会尽可能避免编写脚本和自定义操作,并使用 WiX 的内置 IIS元素。这里是a Web-installer sample from Rainer Stropek available on github.com

寻找 &lt;iis:WebVirtualDir ... /&gt; 等。 Find the WiX Documentation here。我相信您应该能够在没有太多自定义操作的情况下完成所需的操作。

DISM.exe:Stropek 自己在另一个示例源中使用自定义操作 set up IIS using DISM.exe。不确定我是否会这样做(虽然没有其他建议),但它是自定义操作和 IIS 的示例。


Need-For-Speed:至于您的安装性能问题。也许您需要禁止创建还原点并限制文件成本? Windows Installer 引擎允许这样做 - 请参阅下面的链接。我怀疑它会非常有效。我认为您的安装程序肯定有其他问题。一些超时问题?它可能与其他自定义操作、网络速度慢或其他问题有关。您能否详细说明您的部署方案?

无论如何,here is some documentation on speeding up MSI installations in general。本质上,MSIFASTINSTALL 属性是我唯一推荐的属性。 DISABLEROLLBACK 可能会导致真正的问题。


日志记录:我通常建议设置开发人员enable default verbose MSI logging - 如“Globally for all setups on a machine”部分所述,始终拥有需要时准备好日志文件。它是为 TEMP folder 中的每个 MSI 操作使用随机名称创建的,您可以通过修改进行排序以获取最新的操作。日志文件可能会提供有关安装缓慢原因的线索 - 只需确定实际发生的情况即可。如果这只是明显的小事,并且您已经设置好了,我们深表歉意。

手动创建日志文件

msiexec.exe /i C:\Path\Your.msi /L*v C:\Your.log

解读 MSI 日志:解读日志文件有时可能具有挑战性。 Here is an answer with some links to help with this.

【讨论】:

    【解决方案2】:

    服务安装和控制:您不应该使用脚本安装服务。 MSI 中有非常优越的内置机制。您只需使用ServiceInstallServiceControl WiX XML 元素并“声明”服务应该如何注册以及服务应该何时以及如何启动和停止:

    <Component>
       <File Source="$(var.SourceDir)\WindowsService.exe" />
       <ServiceInstall Name="MyService" ErrorControl="normal" Start="auto" Type="ownProcess" />
       <ServiceControl Id="MyService" Name="MyService" Start="install" Stop="both" Remove="uninstall" Wait="yes" />
    </Component>
    

    Look! No custom actions! :-) - Just MSI auto-magic。无需为此使用任何自定义操作。 MSI 功能齐全且可靠,前提是您的服务可执行文件按预期运行。

    Let me link to a similar sample on github 以防上述内容不清楚。它更加完整和详尽。


    VBScript:我在看到你处理服务之前写了这篇文章。我就把它扔进去:要调用一个没有函数的脚本,你可以尝试这样的事情:

    <!-- The VBScript file -->
    <Binary Id='Sample.vbs' SourceFile='Sample.vbs' />
    
    <!-- The Custom Action -->
    <CustomAction Id='Sample.vbs' VBScriptCall='' BinaryKey='Sample.vbs' 
                  Execute='immediate' Return='ignore'/>
    
    <!-- And Insert Into Installation Sequence -->
    <InstallExecuteSequence>
        <Custom Action='Sample.vbs' After='AppSearch'/>
    </InstallExecuteSequence>
    

    这应该适用于这样的脚本(Sample.vbs - 没有函数,只是一个隐式的主函数):

    MsgBox(Session.Property("ProductName"))
    

    这里有关于 VBScript 自定义操作主题的答案:WIX installer execute vbscript from CustomAction


    【讨论】:

    • 感谢您的回答。我知道 会起作用,但在 MS 服务器 2016 上需要很多时间。我正在尝试使用 ExeCommand 执行此操作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多