更新
有趣的是,如果我运行 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 =""powershell.exe" -Command "cd '[INSTALLFOLDER]'; & '[#TestPS1]' ; exit $$($Error.Count)"" />
<CustomAction Id="InstallPlugin" BinaryKey="WixCA" DllEntry="WixQuietExec" Execute="deferred" Return="ignore" Impersonate="no" />
以下是我已经尝试或仔细检查过的项目列表:
- 我尝试了,和 的不同组合
-NoProfile
,但仍然不行。-ExecutionPolicy ByPass
-Version 2.0
- 我已经在运行安装程序
InstallPrivileges="elevated"
- 我已经在运行
CustomAction
asExecute="deferred"
和Impersonate="no"
- 我试过了
AdminImage="yes"
- 我试过设置
<Property Id="MSIUSEREALADMINDETECTION" Value="1" />
任何其他线索将不胜感激。:(