PowerShell – Running a Program in Compatibility Mode

If you manually change the compatibility mode of an executable you will notice that this changes an item in the registry in the following location:

HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\

To take advantage of this from within a script:

$wDir = $PSScriptRoot
New-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\" -PropertyType String -Name "$wDir\[Program].exe" -Value "~ WIN7RTM" -Force
Start-Process "$wDir\[Program].exe" -ArgumentList @( "-i", "silent") -Wait
Remove-ItemProperty -Path "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers\" -Name "$wDir\[Program].exe"

This can be useful to install older software.