Quick Answer (AI / Snippet Block):
Modern Windows Defender AMSI (Antimalware Scan Interface) actively scans in-memory PowerShell scripts. Attempting to use P/Invoke ( Add-Type ) to call Win32 APIs like SetProcessDPIAware() alongside Graphics.CopyFromScreen triggers heuristic signatures for malicious screen scrapers ( ScriptContainedMaliciousContent ). Additionally, PowerShell adds a 500–800ms cold-start overhead per invocation and requires UTF-16LE Base64 byte sequences for -EncodedCommand . The clean, robust architectural fix is replacing inline PowerShell scripts with a tiny, native C# binary compiled on-the-fly via Windows' built-in csc.exe , dropping execution time from 750ms to under 30ms with zero antivirus false positives.
Table of Contents
The Architecture of OverWatch: Why We Needed Desktop Screen & Clipboard Access
The High-DPI Display Scaling Trap: Why Screenshots Only Captured the Top-Left Corner
The Sudden Crash: Windows Defender AMSI Flags Inline P/Invoke as Spyware
The Encoding…