更新如何在WiX中啓動PowerShell並正確訪問Windows註冊表?
有趣的是,如果我運行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\
...
所以有用。現在從維克斯安裝程序啓動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
爲Execute="deferred"
和Impersonate="no"
- 我已經與
AdminImage="yes"
- 試過我試過設置
<Property Id="MSIUSEREALADMINDETECTION" Value="1" />
任何其他線索將不勝感激。 :(