5

更新

有趣的是,如果我运行 32 位 powershell 来运行脚本,它会给我同样的错误。看起来 32 位 powershell 无法访问 64 位注册表树?我尝试使用WixQuietExec64但它给出了同样的错误。我还尝试提供 powershell 的完整路径C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe

MSI (s) (4C:C0) [14:25:49:955]: Hello, I'm your 32bit Elevated Non-remapped custom action server.

原帖

我有以下test.ps1脚本:

$exchangeroot = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ExchangeServer\"
$allexchanges = Get-ChildItem -Path Registry::$exchangeroot -Name | Where-Object { $_ -match "^V.." }
$sorted = $allexchanges | Sort-Object -descending
If ($sorted.Count -gt 1) { $latest = $sorted[0] } Else { $latest = $sorted }
$setup = $exchangeroot + $latest + "\Setup"
$properties = Get-ItemProperty -Path Registry::$setup
$properties

在普通 PowerShell 窗口中运行脚本会产生以下输出:

PS C:\Program Files (x86)\TrustValidator Exchange Server Plugin> .\test.ps1

Required machine-level settings.          : 1
Services                                  : C:\Program Files\Microsoft\Exchange Server\V15
NewestBuild                               : 10845
CurrentBuild                              : 710737954
Information Store Service                 : 1
Messaging and Collaboration Event Logging : 1
MsiInstallPath                            : C:\Program Files\Microsoft\Exchange Server\V15\
...

所以它有效。现在从 WiX 安装程序启动 PowerShell 并执行脚本,它不会生成相同的结果:

WixQuietExec:  Get-ItemProperty : Cannot find path 
WixQuietExec:  'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ExchangeServer\v15\Setup' because it 
WixQuietExec:  does not exist.
WixQuietExec:  At C:\Program Files (x86)\TrustValidator Exchange Server Plugin\test.ps1:10 
WixQuietExec:  char:16
WixQuietExec:  +     $properties = Get-ItemProperty -Path Registry::$setup
WixQuietExec:  +                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
WixQuietExec:      + CategoryInfo          : ObjectNotFound: (HKEY_LOCAL_MACH...erver\v15\Set 
WixQuietExec:     up:String) , ItemNotFoundException
WixQuietExec:      + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetIt 
WixQuietExec:     emPropertyCommand

现在,如果我们观察到错误消息,就好像它可以访问树,直到HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ExchangeServer\,因为我的脚本将搜索并列出所有版本,所以v15到那时必须可以访问,但是当它试图更深入地得到ItemProperty,它不能。

这让我相信,从 WiX 安装程序启动我的 PowerShell 时,我可能遗漏了一些东西......?

这是我的 wxs 文件中的内容:

<SetProperty Id="InstallPlugin"
     Before ="InstallPlugin"
     Sequence="execute"
     Value ="&quot;powershell.exe&quot; -Command &quot;cd '[INSTALLFOLDER]'; &amp; '[#TestPS1]' ; exit $$($Error.Count)&quot;" />
<CustomAction Id="InstallPlugin" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Return="ignore" Impersonate="no" />

以下是我已经尝试或仔细检查过的项目列表:

  • 我尝试了,和 的不同组合-NoProfile,但仍然不行。-ExecutionPolicy ByPass-Version 2.0
  • 我已经在运行安装程序InstallPrivileges="elevated"
  • 我已经在运行CustomActionasExecute="deferred"Impersonate="no"
  • 我试过了AdminImage="yes"
  • 我试过设置<Property Id="MSIUSEREALADMINDETECTION" Value="1" />

任何其他线索将不胜感激。:(

4

1 回答 1

6

我的天啊...

好的,我终于让它工作了。实际上有几个问题,这些问题的解决方案实际上是我从多个 SO 问题中收集的零碎信息。

回顾一下,这就是我想要做的:

  1. 从 WiX 启动一个 powershell 来运行我的安装脚本。
  2. 我的脚本在 Windows 注册表(需要 64 位)中搜索已安装 Exchange Server 的位置
  3. 我的脚本从安装位置加载 Exchange 命令行管理程序 (EMS) 脚本(需要 64 位和正确的用户)
  4. 在 EMS 会话下,我的脚本运行其他脚本的早午餐来注册 Exchange 插件

问题 1)

无论我做什么,WiX 安装程序总是以 32 位启动我的 powershell,这与设置Platform="x64"Win64="yes"甚至WixQuietExec64. x64我什至在 Visual Studio中将安装程序构建为x64.

解决方案是直接引用sysnativepowershell,它必须sysnativeSetProperty.

C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe

实际上我之前确实尝试过,并认为它不起作用,但根本原因被下面的问题 2 掩盖了。

问题2)

我读到的所有地方,他们都说你需要使用Execute="deferred" Impersonate="No". 如果您不做任何时髦的事情,我相信这确实适用于大多数情况。但是,我不得不 Impersonate。我发现 WiX 安装程序会使用 user 以提升的身份运行您的NT Authority/SystemCA。这把我搞砸了,因为Exchange Management Shell我试图获取的脚本基本上会使用你的凭据并尝试与 Exchange Server 建立会话......当然你不能连接为NT Authority/System

解决方案是使用Impersonate="yes"WiX 安装程序以提升的身份运行您的 CA 以及您当前登录的用户。我一直认为您在使用Impersonate="no"时必须使用Execute="deferred"...但您没有

我放弃了几天的故障排除,然后回到它并让它工作。帮助我弄清楚这一点的两个最有用的命令实际上是:

  • 我是谁
  • Get-ChildItem env:(检查 PROCESSOR_ARCHITECTURE)
于 2017-08-03T21:02:00.830 回答