Identify the window that steals focus
The window that appeared last owns the foreground. Logging the foreground window over a minute names the app instead of guessing.
Add-Type @'
using System; using System.Runtime.InteropServices;
public class Fg { [DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow(); [DllImport("user32.dll")] public static extern int GetWindowText(IntPtr h, System.Text.StringBuilder s, int n); }
'@
1..10 | ForEach-Object { $b = New-Object System.Text.StringBuilder 256; [Fg]::GetWindowText([Fg]::GetForegroundWindow(), $b, 256) | Out-Null; "{0} {1}" -f (Get-Date -Format HH:mm:ss), $b.ToString(); Start-Sleep -Seconds 6 }