简体   繁体   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?

I want to make an installer run a PowerShell script, before installing all the other files.我想让安装程序在安装所有其他文件之前运行 PowerShell 脚本。 However, how it is build currently, it only works to run the script when the install is done, because it is placing the powershell script in the target directory.但是,它目前是如何构建的,它只能在安装完成后运行脚本,因为它将 powershell 脚本放在目标目录中。 Now this could probably be fixed by making the directory something that is always existing.现在,这可能可以通过使目录始终存在来解决。 However, I don't want to have to provide the script with the installer all the time, I want the script to be embedded into the installer and run from there or at least run the commands that are in the script file.但是,我不想一直为安装程序提供脚本,我希望将脚本嵌入到安装程序中并从那里运行,或者至少运行脚本文件中的命令。

I tried changing the custom action's "After" to "InstallInitialize", however it throws an error saying it can't the path (which is logical, because the path isn't created yet because the script is executed before the installation of the files).我尝试将自定义操作的“After”更改为“InstallInitialize”,但是它会抛出一个错误,说它不能找到路径(这是合乎逻辑的,因为尚未创建路径,因为脚本是在安装文件之前执行的)。

Here is a bit of the code where all the logic for running the powershell script is provided:下面是一些代码,其中提供了运行 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>

The Expected result is the script being embedded into the.msi file, not relying on a file that is only created after installation.预期结果是将脚本嵌入到 .msi 文件中,而不依赖于仅在安装后创建的文件。 The error message is that it can't find the script because it isn't installed yet.错误消息是它找不到脚本,因为它尚未安装。 I actually don't want the script file to be placed in the folder to begin with, I just want the script run inside the installer and do nothing else with the script file.我实际上不希望将脚本文件放在文件夹中,我只希望脚本在安装程序中运行,并且不对脚本文件执行任何其他操作。

This the only PS extension of Wix I could find online, but it seems this could be limited to your scenario too. 这是我可以在网上找到的 Wix 的唯一 PS 扩展,但似乎这也可能仅限于您的场景。

To support running scripts before they are installed we (at Advanced Installer ) created a predefined support to extract the PS script as a temporary file when the installation is launched and execute it from that temp location.为了支持在安装之前运行脚本,我们(在Advanced Installer中)创建了一个预定义的支持,以便在启动安装时将 PS 脚本提取为临时文件并从该临时位置执行它。 I don't if Wix has a similar support.如果 Wix 有类似的支持,我不知道。

Disclosure: I work on the team building Advanced Installer.披露:我在团队建设 Advanced Installer 工作。

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

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