<# set-appcompat.ps1 - apply the DirectDraw compatibility shim to the MW4 executables sitting NEXT TO this script, wherever that copy of the game happens to live. WHY THIS EXISTS MW4 renders at bitdepth=16. Modern GPUs report ZERO 16-bit display modes, so the exclusive-fullscreen path cannot set a mode and fails. The DWM8And16BitMitigation AppCompat layer is what makes 8/16-bit fullscreen work under the desktop compositor. Without it GameOS reports: "Another application is preventing use of full screen mode." That message is a catch-all raised after every SetDisplayMode attempt has failed -- it even scans for NetMeeting -- so it sends you hunting for a conflicting program that does not exist. The real cause is the missing shim. The layer is keyed on the executable's FULL PATH. Every install needs its own entry, and copying or moving an install silently loses it. Hence this script: run it from inside any deployment and it fixes that deployment. USAGE Double-click set-appcompat.bat (recommended - one click, no execution-policy fuss) or: .\set-appcompat.ps1 apply the shim .\set-appcompat.ps1 -Remove remove the entries this script adds .\set-appcompat.ps1 -WhatIfOnly report current state, change nothing Run as Administrator to also write the all-users (HKLM) entry. Without elevation the per-user (HKCU) entry is written, which is enough for the account that runs the game. #> param( [string]$Layer = "DWM8And16BitMitigation HIGHDPIAWARE", [switch]$Remove, [switch]$WhatIfOnly ) $ErrorActionPreference = "Stop" # --- Locate ourselves ------------------------------------------------------------- # $PSScriptRoot is empty on very old hosts and when dot-sourced, so fall back. $here = $PSScriptRoot if ([string]::IsNullOrEmpty($here)) { $here = Split-Path -Parent $MyInvocation.MyCommand.Path } $hkcuLayers = "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" $hklmLayers = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" $isAdmin = ([Security.Principal.WindowsPrincipal] ` [Security.Principal.WindowsIdentity]::GetCurrent() ).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) Write-Host "" Write-Host "MW4 DirectDraw compatibility shim" -ForegroundColor Cyan Write-Host "---------------------------------" -ForegroundColor Cyan Write-Host " folder : $here" Write-Host " elevated : $(if ($isAdmin) { 'yes (HKCU + HKLM)' } else { 'no (HKCU only)' })" Write-Host "" # --- Find the executables that need it -------------------------------------------- # Only the game/editor executables drive DirectDraw. Launcher/autoconfig/mw4print do not. $wanted = @("MW4.exe", "MW4pro.exe", "MW4Ed2.exe") $targets = @() foreach ($name in $wanted) { $p = Join-Path $here $name if (Test-Path -LiteralPath $p) { $targets += $p } } if ($targets.Count -eq 0) { Write-Host "No MW4 executables found next to this script." -ForegroundColor Red Write-Host "Expected one of: $($wanted -join ', ')" Write-Host "Put this script in the same folder as MW4.exe and run it again." exit 1 } # --- Helpers ---------------------------------------------------------------------- function Get-Layer([string]$root, [string]$exe) { if (-not (Test-Path -LiteralPath $root)) { return $null } $item = Get-ItemProperty -LiteralPath $root -ErrorAction SilentlyContinue if ($null -eq $item) { return $null } $prop = $item.PSObject.Properties | Where-Object { $_.Name -eq $exe } if ($null -eq $prop) { return $null } return $prop.Value } function Set-Layer([string]$root, [string]$exe, [string]$value) { if (-not (Test-Path -LiteralPath $root)) { New-Item -Path $root -Force | Out-Null } Set-ItemProperty -LiteralPath $root -Name $exe -Value $value -Type String } $failed = 0 foreach ($exe in $targets) { Write-Host $exe -ForegroundColor White $before = Get-Layer $hkcuLayers $exe if ($null -ne $before) { Write-Host " existing HKCU : $before" -ForegroundColor DarkGray # The historical failure mode: a HIGHDPIAWARE-only entry, which suppresses the # automatic shim and produces exactly the fullscreen failure this script fixes. if (-not $Remove -and $before -notmatch "DWM8And16BitMitigation") { Write-Host " NOTE: entry exists but has no DWM8And16BitMitigation -" -ForegroundColor Yellow Write-Host " this specific state BLOCKS fullscreen. Replacing it." -ForegroundColor Yellow } } if ($WhatIfOnly) { $lm = Get-Layer $hklmLayers $exe Write-Host " existing HKLM : $(if ($null -ne $lm) { $lm } else { '(none)' })" -ForegroundColor DarkGray Write-Host "" continue } if ($Remove) { Remove-ItemProperty -LiteralPath $hkcuLayers -Name $exe -ErrorAction SilentlyContinue if ($isAdmin) { Remove-ItemProperty -LiteralPath $hklmLayers -Name $exe -ErrorAction SilentlyContinue } Write-Host " removed" -ForegroundColor Yellow Write-Host "" continue } # Per-user. No admin needed, and applies to the account that actually runs the game. Set-Layer $hkcuLayers $exe $Layer # All-users, if we can. Note the different value format: the HKLM entries use a # leading "$ " marker. Do not copy one format into the other key. if ($isAdmin) { Set-Layer $hklmLayers $exe ("$ " + ($Layer -replace '\s*HIGHDPIAWARE\s*', '')) } # Verify by reading back rather than trusting the write. $after = Get-Layer $hkcuLayers $exe if ($after -eq $Layer) { Write-Host " HKCU set : $after" -ForegroundColor Green } else { Write-Host " HKCU FAILED : got '$after'" -ForegroundColor Red $failed++ } if ($isAdmin) { $afterM = Get-Layer $hklmLayers $exe if ($null -ne $afterM) { Write-Host " HKLM set : $afterM" -ForegroundColor Green } else { Write-Host " HKLM FAILED" -ForegroundColor Red $failed++ } } Write-Host "" } if ($WhatIfOnly) { Write-Host "Report only - nothing was changed." -ForegroundColor Cyan exit 0 } if ($failed -gt 0) { Write-Host "$failed registry write(s) failed." -ForegroundColor Red exit 1 } if ($Remove) { Write-Host "Shim removed. Fullscreen will fail on modern GPUs until it is re-applied." -ForegroundColor Yellow } else { Write-Host "Done. The shim is read when the process starts -" -ForegroundColor Green Write-Host "restart MW4 to pick it up. No reboot needed." -ForegroundColor Green if (-not $isAdmin) { Write-Host "" Write-Host "Applied for the current user only. To cover all accounts on this" -ForegroundColor DarkGray Write-Host "machine, run this script again as Administrator." -ForegroundColor DarkGray } } exit 0