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 sudio, etc.
By using PowerShell script we can get the properties from MSI without any tool.


Function Get-MsiProperties
              [Parameter(Mandatory = $true, Position=0)]
        [ValidateScript({Test-Path $_})]

    $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
        [Parameter(Mandatory=$true, Position = 0)]
        [Parameter(Mandatory=$false, Position = 3)]
        [System.Reflection.BindingFlags]$InvokeAttr = "InvokeMethod",

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


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

Steps To DO:
1. Copy 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, have taken reference from 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?

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.

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.