### Use: Stop annoying flashing of windows. ### Author: xxxxxxxxxx ### Date: Apr 24 2017 ### Ver: 1 ### Source: http://pinvoke.net/default.aspx/user32/FlashWindowEx.html Add-Type -TypeDefinition @" using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Runtime.InteropServices; public class Window { [StructLayout(LayoutKind.Sequential)] public struct FLASHWINFO { public UInt32 cbSize; public IntPtr hwnd; public UInt32 dwFlags; public UInt32 uCount; public UInt32 dwTimeout; } //Stop flashing. The system restores the window to its original state. const UInt32 FLASHW_STOP = 0; //Flash the window caption. const UInt32 FLASHW_CAPTION = 1; //Flash the taskbar button. const UInt32 FLASHW_TRAY = 2; //Flash both the window caption and taskbar button. //This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags. const UInt32 FLASHW_ALL = 3; //Flash continuously, until the FLASHW_STOP flag is set. const UInt32 FLASHW_TIMER = 4; //Flash continuously until the window comes to the foreground. const UInt32 FLASHW_TIMERNOFG = 12; [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)] static extern bool FlashWindowEx(ref FLASHWINFO pwfi); public static bool FlashWindow(IntPtr handle, UInt32 timeout, UInt32 count) { IntPtr hWnd = handle; FLASHWINFO fInfo = new FLASHWINFO(); fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); fInfo.hwnd = hWnd; fInfo.dwFlags = FLASHW_ALL; //| FLASHW_TIMERNOFG; fInfo.uCount = count; fInfo.dwTimeout = timeout; return FlashWindowEx(ref fInfo); } public static bool StopFlashWindow(IntPtr handle) { IntPtr hWnd = handle; FLASHWINFO fInfo = new FLASHWINFO(); fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo)); fInfo.hwnd = hWnd; fInfo.dwFlags = FLASHW_STOP; return FlashWindowEx(ref fInfo); } } "@ [int]$Duration = Read-Host "Minutes to suppress flashes [30]" if($Duration -eq ""){ $Duration = 30 } [int]$TargetWindowName = Read-Host "Enter the name of the program to suppress [All]" if($TargetWindowName -eq ""){ $TargetWindowName = 's_AllPrograms' } $StartTime = Get-Date while((New-TimeSpan -Start $StartTime -End (Get-Date)).Minutes -lt $Duration){ if($TargetWindowName -eq "s_AllPrograms"){ (Get-Process).MainWindowHandle | % {[Window]::StopFlashWindow($_)} > $null Write-Host "Stopping all flashing of task windows for another $($Duration - (New-TimeSpan -Start $StartTime -End (Get-Date)).Minutes) Minutes..." } else{ (Get-Process -Name $TargetWindowName).MainWindowHandle | % {[Window]::StopFlashWindow($_)} > $null Write-Host "Stopping $TargetWindowName from flashing for another $($Duration - (New-TimeSpan -Start $StartTime -End (Get-Date)).Minutes) Minutes..." } cls Start-Sleep -Seconds 1 } Write-Host "Timed out, job finished..." -fo Green