如何在WiX中正确访问Windows注册表启动PowerShell?
更新 有趣的是,如果我运行32位powershell来运行脚本,它会给出相同的错误。32位powershell似乎无法访问64位注册表树?我尝试使用如何在WiX中正确访问Windows注册表启动PowerShell?,powershell,wix,windows-installer,registry,wix3.11,Powershell,Wix,Windows Installer,Registry,Wix3.11,更新 有趣的是,如果我运行32位powershell来运行脚本,它会给出相同的错误。32位powershell似乎无法访问64位注册表树?我尝试使用WixQuietExec64,但它给出了相同的错误。我还尝试提供powershell的完整路径(C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe),以确保安装程序启动64位版本,但仍然出现相同的错误。。。看起来这可能是由于MSI安装程序本身为32位 MSI (s) (4C:C0) [1
WixQuietExec64
,但它给出了相同的错误。我还尝试提供powershell的完整路径(C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe
),以确保安装程序启动64位版本,但仍然出现相同的错误。。。看起来这可能是由于MSI安装程序本身为32位
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 windows中运行脚本会产生以下输出:
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\U LOCAL\U 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=“hiveled”的身份运行安装程序了
- 我已经以
和Execute=“deferred”
Impersonate=“no”
- 我试过使用
AdminImage=“yes”
- 我已尝试设置
Platform=“x64”
,Win64=“yes”
,甚至WixQuietExec64
无关。我甚至在VisualStudio中构建了安装程序作为x64
和其他所有东西作为x64
解决方案是直接引用sysnative
powershell,它必须是SetProperty
中的sysnative
C:\Windows\sysnative\WindowsPowerShell\v1.0\powershell.exe
事实上,我以前确实尝试过这个方法,并且认为它不起作用,但根本原因是下面的问题2掩盖了
问题2)
无论我读到哪里,他们都说您需要使用Execute=“deferred”Impersonate=“No”
运行。我相信,如果你不做任何令人不安的事情,这在大多数情况下确实有效。但是,我必须模拟
。我发现WiX安装程序将使用userNT Authority/System
运行您的CA。这让我大吃一惊,因为我试图获取的Exchange命令行管理程序脚本基本上会使用您的凭据并尝试与Exchange服务器建立会话。。。当然,您不能以NT权限/系统的身份连接
解决方案是使用Impersonate=“yes”
,这样WiX安装程序将以提升的身份运行您的CA,并以您当前登录的用户的身份运行。我一直觉得在使用Execute=“deferred”
时必须使用Impersonate=“no”
但你没有
我放弃了这几天的故障排除,然后回到它,让它工作。帮助我解决这个问题的两个最有用的命令实际上是:
- 哇
- Get ChildItem env:(检查处理器\u体系结构)