繁体   English   中英

是否可以在安装程序中嵌入 PowerShell 脚本并使用 Wix 从那里而不是位置运行它?

[英]Is it possible to embed a PowerShell script inside the installer and run it from there instead of a location, using Wix?

我想让安装程序在安装所有其他文件之前运行 PowerShell 脚本。 但是,它目前是如何构建的,它只能在安装完成后运行脚本,因为它将 powershell 脚本放在目标目录中。 现在,这可能可以通过使目录始终存在来解决。 但是,我不想一直为安装程序提供脚本,我希望将脚本嵌入到安装程序中并从那里运行,或者至少运行脚本文件中的命令。

我尝试将自定义操作的“After”更改为“InstallInitialize”,但是它会抛出一个错误,说它不能找到路径(这是合乎逻辑的,因为尚未创建路径,因为脚本是在安装文件之前执行的)。

下面是一些代码,其中提供了运行 powershell 脚本的所有逻辑:

<DirectoryRef Id="INSTALLFOLDER">
  <Component Id ="SOMESCRIPT" Guid="">
    <File Id="SOMESCRIPT" Name="My-Script.ps1" Source="My-Script.ps1" />
  </Component>
</DirectoryRef>

<Property Id="POWERSHELLEXE">
  <RegistrySearch Id="POWERSHELLEXE"
                  Type="raw"
                  Root="HKLM"
                  Key="SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell"
                  Name="Path" />
</Property>

<Condition Message="This application requires Windows PowerShell.">
  <![CDATA[Installed OR POWERSHELLEXE]]>
</Condition>

<SetProperty Id="PSscript"
         After="PSscript"
         Sequence="execute"
         Value ="&quot;[POWERSHELLEXE]&quot; -Version 3.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command &quot;&amp; '[#SOMESCRIPT]' ; exit $$($Error.Count)&quot;" />

<CustomAction Id="PSscript"
              BinaryKey="WixCA"
              DllEntry="WixQuietExec"
              Execute="deferred"
              Return="check"
              Impersonate="yes" />

<InstallExecuteSequence>
  <Custom Action="PSscript" After="InstallInitialize"><![CDATA[NOT Installed]]></Custom>
</InstallExecuteSequence>

预期结果是将脚本嵌入到 .msi 文件中,而不依赖于仅在安装后创建的文件。 错误消息是它找不到脚本,因为它尚未安装。 我实际上不希望将脚本文件放在文件夹中,我只希望脚本在安装程序中运行,并且不对脚本文件执行任何其他操作。

这是我可以在网上找到的 Wix 的唯一 PS 扩展,但似乎这也可能仅限于您的场景。

为了支持在安装之前运行脚本,我们(在Advanced Installer中)创建了一个预定义的支持,以便在启动安装时将 PS 脚本提取为临时文件并从该临时位置执行它。 如果 Wix 有类似的支持,我不知道。

披露:我在团队建设 Advanced Installer 工作。

暂无
暂无

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

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