首页 > 解决方案 > MSI 安装程序 - 调用 PowerShell 脚本

问题描述

我在 MSI 安装程序包创建中有一个阻止程序,请找到以下详细信息,如果有任何解决方案,请告诉我,

我编写了 PowerShell 脚本来自动配置 Hyper-V 虚拟机(AWS i3.metal 实例类型),并且该脚本运行良好。

我希望 PowerShell 脚本作为 MSI 安装程序包 在 Visual Studio 2017 社区版中工作以制作 MSI 安装程序包 为此,我使用 WIX 安装程序命令并创建 wxs 文件来制作 MSI

使用 WIX 成功创建 MSI 安装程序,但在安装该 MSI 时,它没有调用 PowerShell 脚本

但我可以看到已安装的应用程序(在控制面板中列出 & 安装文件夹是在 C:\programFiles 中创建的)

使用 wix SetProperty、CustomAction 和 InstallExecuteSequence cmd,但调用 Powershell 脚本没有运气

这适用于新的 Windows 服务器

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="19fe6e20-a840-4829-8883-bde0bfa51d4c" Name="testing" Language="1033" Version="1.0.0.0" Manufacturer="muni" UpgradeCode="93008c8b-adb9-4498-8be2-4a83162b3a35">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate />

    <Feature Id="ProductFeature" Title="test" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
    </Feature>
  </Product>

  <Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <Component Id="ProductComponent">
        <File Source="C:\Users\Administrator\source\repos\testMSI\test\Invoke-Test.ps1" Id="InvokeTestPS1"  />
      </Component>
    </ComponentGroup>
  </Fragment>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="testing" />
      </Directory>
    </Directory>
  </Fragment>

  <Fragment>
    <DirectoryRef Id="INSTALLFOLDER">
      <Component Guid="*">
        <File Id="InvokeTestPS1" Source="Invoke-Test.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="InvokeTestPS1"
             Before="InstallFinalize"
             Sequence="execute"
             Value ="&quot;[POWERSHELLEXE]&quot; -Version 2.0 -NoProfile -NonInteractive -InputFormat None -ExecutionPolicy Bypass -Command &quot;&amp; '[#InvokeTestPS1]' ; exit $$($Error.Count)&quot;" />
    <CustomAction Id="InvokeTestPS1"
                  BinaryKey="WixCA"
                  DllEntry="WixSilentExec"
                  Execute="immediate"
                  Return="check"
                  Impersonate="yes" />
    <InstallExecuteSequence>
      <Custom Action="InvokeTestPS1" After="InstallFinalize">
        <![CDATA[NOT Installed]]>
      </Custom>
    </InstallExecuteSequence>

  </Fragment>
  <Fragment>
    <Feature Id="Application" Title="Minefold" Level="1">
      <ComponentRef Id="ProductComponent" />
    </Feature>
  </Fragment>
</Wix>

MSI 安装程序应该调用 Powershell 脚本 - 意味着一旦我创建了 MSI 然后我需要安装那个 MSI 并且 MSI 需要调用 powershell 脚本

标签: powershellwindows-installer

解决方案


推荐阅读