Tuesday 15 May 2018

PowerShell: Script to display the Properties in MSI(Windows Installer)

For editing MSI we need to have a tool like ORCA, Install shield, Wise Package studio, etc.
By using the PowerShell script, we can get the properties from MSI without any tool.

Script:

Function Get-MsiProperties
{
    param
    (
              [Parameter(Mandatory = $true, Position=0)]
        [ValidateNotNullOrEmpty()]
        [ValidateScript({Test-Path $_})]
        [ValidateScript({$_.EndsWith(".msi")})]
        [String]$MsiPath
    )

    $MsiPath = Resolve-Path $MsiPath
    $type = [Type]::GetTypeFromProgID("WindowsInstaller.Installer")
    $installer = [Activator]::CreateInstance($type)

    $db = Invoke-MemberOnType "OpenDatabase" $installer @($MsiPath,0)
  
    $view = Invoke-MemberOnType "OpenView" $db ('SELECT * FROM Property')

    Invoke-MemberOnType "Execute" $view $null

    $record = Invoke-MemberOnType "Fetch" $view $null
    while($record -ne $null)
    {
        $property = Invoke-MemberOnType "StringData" $record 1 "GetProperty"
        $value = Invoke-MemberOnType "StringData" $record 2 "GetProperty"
        Write-Output "$property = $value"
        $record = Invoke-MemberOnType "Fetch" $view $null
    }

    Invoke-MemberOnType "Close" $view $null
}


Function Invoke-MemberOnType
{
    param
    (
        [Parameter(Mandatory=$true, Position = 0)]
        [ValidateNotNullOrEmpty()]
        [String]$Name,
      
        [Parameter(Mandatory=$false, Position = 3)]
        [System.Reflection.BindingFlags]$InvokeAttr = "InvokeMethod",

        [Parameter(Mandatory=$true, Position = 1)]
        [ValidateNotNull()]
        [Object]$Target,
       
        [Parameter(Mandatory=$false, Position = 2)]
        [Object[]]$Arguments = $null
    )

    $Target.GetType().InvokeMember($Name,$InvokeAttr,$null,$Target,$Arguments)
}

Get-MsiProperties -MsiPath "C:\subinacl.msi" | Out-GridView


Steps To Do:
1. Copy the code and save the script as XXX.PS1
2. Set the execution policy to run the script.
3. Execute the script and it will display the properties detail.


Note: Above script, has taken reference from the Microsoft Tech Net site.

MSI: Disabling Cancel button in Windows Installer repair dialog

During the first launch of an application with a current user self-repair feature, windows installer pops up a window with a cancel button. In other way(Self Heal by advertised shortcut)When the application is launched by advertised shortcut, it checks for all the key paths of the Current Feature, if any of the key paths is missing it will launch Repair.
During that repair is happening Users have the option to cancel out of this, leaving the self-repair incomplete. If the component key path has been written out, then the self heal of this component will not happen next time the application is launched.


How can we disable the cancel button on windows installer dialogs?

Solution
1. Create a custom action New VB script --> Stored in custom action.




2. Click on Next



3. Click on Next


4. Click on Next


5. Enter the following VB script code.
Dim Record
Set Record = Installer.CreateRecord(2)
Record.IntegerData(1) = 2
Record.IntegerData(2) = 0
Session.Message &H0B000000, Record



6. Click on Next



7. In-Script Execution : Immediate Execution. click on Next


8. Keep Install Execute Sequence at the very beginning.
Install Execute Condition: NOT REMOVE
#Action runs during Install and repair


9. Click on Finish.



After install, launch the advertised shortcut and you will see repair popup without cancel button.

Note:
The cancel button may appear for a short time when the self-repair starts, but will quickly disappear removing the ability for the user to cancel out of the self-repair.