wilstxfm.ps1
wilstxfm.ps1
# Windows Installer transform viewer for use with Windows PowerShell
# Demonstrates the use of the database APIs for viewing transform files
# source: https://github.com/pauldotknopf/WindowsSDK7-Samples/blob/master/sysmgmt/msi/scripts/WiLstXfm.vbs
$iteAddExistingRow = 1
$iteDelNonExistingRow = 2
$iteAddExistingTable = 4
$iteDelNonExistingTable = 8
$iteUpdNonExistingRow = 16
$iteChangeCodePage = 32
$iteViewTransform = 256
$icdLong = 0
$icdShort = 0x400
$icdObject = 0x800
$icdString = 0xC00
$icdNullable = 0x1000
$icdPrimaryKey = 0x2000
$icdNoNulls = 0
$icdPersistent = 0x100
$icdTemporary = 0
$idoReadOnly = 0
$gErrors, $installer, $base, $database, $argCount, $arg, $argValue = $null
$gErrors = $iteAddExistingRow + $iteDelNonExistingRow + $iteAddExistingTable + $iteDelNonExistingTable + $iteUpdNonExistingRow + $iteChangeCodePage
$database = $null
# Check arg count, and display help if not all arguments present
$argCount = $args.Count
if ($argCount -lt 2) {
Write-Host "Windows Installer Transform Viewer for Windows Scripting Host (CScript.exe)" -BackgroundColor Black -ForegroundColor Green
Write-Host " 1st non-numeric argument is path to base database which transforms reference"
Write-Host " Subsequent non-numeric arguments are paths to the transforms to be viewed"
Write-Host " Numeric argument is optional error suppression flags (default is ignore all)"
Write-Host " Arguments are executed left-to-right, as encountered"
Write-Host ""
Write-Host "Copyright (C) Microsoft Corporation. All rights reserved." -BackgroundColor Black -ForegroundColor Green
exit 1
}
# Cannot run with GUI script host, as listing is performed to standard out
if (([System.Management.Automation.PSTypeName]'Host').CurrentHost.Name -eq "Windows PowerShell ISE Host") {
Write-Host "Cannot use WScript.exe - must use CScript.exe with this program"
exit 2
}
# Create installer object
trap {
Write-Host "$($_.Exception.Source) $($_.Exception.HResult): $($_.Exception.Message)"
if ($installer -ne $null) {
$errRec = $installer.LastErrorRecord
if ($errRec -ne $null) {
Write-Host "$($errRec.FormatText)"
}
}
exit 2
}
$installer = New-Object -ComObject "WindowsInstaller.Installer"
# Process arguments, opening database and applying transforms
for ($arg = 0; $arg -lt $argCount; $arg++) {
$argValue = $args[$arg]
if ($argValue -is [int]) {
$gErrors = $argValue
}
elseif ($database -eq $null) {
$database = $installer.OpenDatabase($argValue, $idoReadOnly)
}
else {
$database.ApplyTransform($argValue, $iteViewTransform + $gErrors)
}
}
ListTransform($database)
function DecodeColDef($colDef) {
$def = ""
switch ($colDef -band ($icdShort -bor $icdObject)) {
$icdLong {
$def = "LONG"
}
$icdShort {
$def = "SHORT"
}
$icdObject {
$def = "OBJECT"
}
$icdString {
$def = "CHAR($($colDef -band 255))"
}
}
if (($colDef -band $icdNullable) -eq 0) {
$def += " NOT NULL"
}
if (($colDef -band $icdPrimaryKey) -ne 0) {
$def += " PRIMARY KEY"
}
return $def
}
function ListTransform($database) {
$view, $record, $row, $column, $change = $null
$view = $database.OpenView("SELECT * FROM `_TransformView` ORDER BY `Table`, `Row`")
$view.Execute()
while ($true) {
$record = $view.Fetch()
if ($record -eq $null) {
break
}
$change = ""
if ($record.IsNull(3)) {
$row = "<DDL>"
if (-not $record.IsNull(4)) {
$change = "[ $($record.StringData(5)) ]: " + DecodeColDef($record.StringData(4))
}
}
else {
$row = "[ $($record.StringData(3) -split "`t" -join ",") ]"
if (($record.StringData(2) -ne "INSERT") -and ($record.StringData(2) -ne "DELETE")) {
$change = "{ $($record.StringData(5)) }->{ $($record.StringData(4)) }"
}
}
$column = "$($record.StringData(1)) $($record.StringData(2))"
if ($column.Length -lt 24) {
$column += " " * (24 - $column.Length)
}
Write-Host "$column $row $change"
}
}
# usage: .\wilstxfm.ps1 "Chemin\Vers\fichier.msi" "Chemin\Vers\Transform.mst"
/image%2F0881799%2F20140610%2Fob_a8c7fe_logo2.jpg)
Commenter cet article