2017-07-25 36 views
2

更新如何在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 ="&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"
  • 我已經運行CustomActionExecute="deferred"Impersonate="no"
  • 我已經與AdminImage="yes"
  • 試過我試過設置<Property Id="MSIUSEREALADMINDETECTION" Value="1" />

任何其他線索將不勝感激。 :(

回答

0

哦...我...上帝...

好吧,我終於得到了它的工作。實際上有幾個問題以及這些問題的解決方案位實際上是和的信息,我從多個SO問題中收集信息。

總括來說,這裏就是我試圖做的事:

  1. 啓動一個PowerShell從維克斯運行我的安裝腳本。
  2. 我的腳本搜索註冊表(需要64位)用於安裝Exchange Server的位置
  3. 我的腳本加載在Exchange命令行管理程序(EMS)腳本(需要64位和正確的用戶)從安裝位置
  4. 根據EMS會議,我的腳本運行的其他腳本的早午餐來註冊一個Exchange插件

問題1)

無論我做什麼,該WiX的安裝程序總是啓動我的32B的PowerShell它,這是不管設置Platform="x64"Win64="yes",甚至WixQuietExec64。我甚至在Visual Studio中構建了安裝程序x64其他所有內容作爲x64

的解決方案是直接引用sysnative的powershell,它必須是在SetPropertysysnative

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

其實我以前嘗試過這一點,並認爲這是行不通的,但根本原因是受到以下問題2所掩蓋。

問題2)

我到處看,他們說你需要與Execute="deferred" Impersonate="No"運行。如果你沒有做任何事情,我相信這對大多數情況確實有效。但是,我必須Impersonate。我發現WiX安裝程序會以用戶NT Authority/System提升您的CA。這使我搞砸了,因爲我試圖從源代碼中獲取的Exchange Management Shell腳本基本上會使用您的憑據並嘗試與Exchange Server建立會話......當然,您無法連接爲NT Authority/System

的解決方案是使用Impersonate="yes",使維克斯安裝程序將運行CA的升高,你當前登錄的用戶。使用Execute="deferred"時,我總是有,你必須使用Impersonate="no"的印象...... 但你不't

我放棄了幾天的故障排除,然後回到它並得到它的工作。幫助我想通了這一點的2個最有用的命令實際上是:

  • WHOAMI
  • 獲取-ChildItem ENV:(檢查PROCESSOR_ARCHITECTURE)