2017-04-07 160 views
1

我必須從應用MST的MSI中讀取一些信息。我知道如何從純MSI讀取表格,但不知道如何應用MST。Powershell獲取MST信息

我用這個微星:

Process { 
    try { 
     # Read property from MSI database 
     $WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer 
     $MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $null, $WindowsInstaller, @($Path.FullName, 0)) 
     $Query = "SELECT Value FROM Property WHERE Property = '$($Property)'" 
     # $Query = "SELECT Action FROM CustomAction WHERE Action = '$($CustomAction)'" 
     $View = $MSIDatabase.GetType().InvokeMember("OpenView", "InvokeMethod", $null, $MSIDatabase, ($Query)) 
     $View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null) | out-null 
     $Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $null, $View, $null) 
     try { 
      $Value = $Record.GetType().InvokeMember("StringData", "GetProperty", $null, $Record, 1) 

      # Commit database and close view 
      $MSIDatabase.GetType().InvokeMember("Commit", "InvokeMethod", $null, $MSIDatabase, $null) | out-null 
      $View.GetType().InvokeMember("Close", "InvokeMethod", $null, $View, $null) | Out-Null 
      $MSIDatabase = $null 
      $View = $null 
     } catch { 
      $Value = "-" 
     } 
     # Return the value 

     return $Value 

如果有人能幫助我,這將是非常好的!

謝謝,莫里茨:)

回答

0

退房從贏SDK 「wilstxfm.vbs」 的例子。在我的系統它的安裝在此路徑:

c:\Program Files (x86)\Windows Kits\8.1\bin\x64\wilstxfm.vbs 

不能在這裏粘貼代碼,因爲版權問題,但他們基本上做到這一點:

database = installer.OpenDatabase(msiPath,0) 
database.ApplyTransform(mstPath, iteViewTransform + iteAddExistingRow + iteDelNonExistingRow + iteAddExistingTable + iteDelNonExistingTable + iteUpdNonExistingRow + iteChangeCodePage) 
view = database.OpenView("SELECT * FROM `_TransformView` ORDER BY `Table`, `Row`") 

然後,他們遍歷視圖的記錄打印變換將執行的更改。

您應該能夠將該.vbs示例轉換爲PowerShell代碼,或者只需從PS中調用.vbs腳本即可。