Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在WiX中正确访问Windows注册表启动PowerShell?_Powershell_Wix_Windows Installer_Registry_Wix3.11 - Fatal编程技术网

如何在WiX中正确访问Windows注册表启动PowerShell?

如何在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

更新

有趣的是,如果我运行32位powershell来运行脚本,它会给出相同的错误。32位powershell似乎无法访问64位注册表树?我尝试使用
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 ="&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=“hiveled”的身份运行安装程序了
  • 我已经以
    Execute=“deferred”
    Impersonate=“no”
  • 我试过使用
    AdminImage=“yes”
  • 我已尝试设置
如有任何其他线索,将不胜感激(

哦……天哪

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

总而言之,我想做的是:

  • 从WiX启动powershell以运行我的安装脚本
  • “我的脚本”在Windows注册表(需要64位)中搜索已安装Exchange服务器的位置
  • 我的脚本从安装位置加载Exchange命令行管理程序(EMS)脚本(需要64位和正确的用户)
  • 在EMS会话下,我的脚本运行一系列其他脚本来注册一个Exchange插件
  • 问题1)

    无论我做了什么,WiX安装程序总是以32位启动我的powershell,这与设置
    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安装程序将使用user
    NT Authority/System
    运行您的CA。这让我大吃一惊,因为我试图获取的
    Exchange命令行管理程序
    脚本基本上会使用您的凭据并尝试与Exchange服务器建立会话。。。当然,您不能以NT权限/系统的身份连接

    解决方案是使用
    Impersonate=“yes”
    ,这样WiX安装程序将以提升的身份运行您的CA,并以您当前登录的用户的身份运行。我一直觉得在使用
    Execute=“deferred”
    时必须使用
    Impersonate=“no”
    但你没有

    我放弃了这几天的故障排除,然后回到它,让它工作。帮助我解决这个问题的两个最有用的命令实际上是:

    • Get ChildItem env:(检查处理器\u体系结构)