-WindowStyle Hidden still flashes a console window
args quoting · case
Affectspowershell 51, pwsh 7, windows, win32 api
Fails assilent
Mechanismconsole allocation
Safe fixcreate no window
Symptom
Section titled “Symptom”A background service launches powershell.exe -WindowStyle Hidden -Command ...
for a quick lookup, and users see a console window flash on screen anyway —
sometimes stealing focus mid-typing. The flag looks correct; the window appears
regardless.
# From a console-less parent (a GUI app or service):powershell.exe -WindowStyle Hidden -Command "whoami"# A new console window is allocated and briefly visible.powershell.exe is a console-subsystem binary. When its parent has no console,
Windows allocates a brand-new console at process creation — BEFORE PowerShell
ever parses -WindowStyle Hidden. The flag hides the window only after startup,
which is why it flashes. Suppression must happen at the Win32 level:
CREATE_NO_WINDOW (windowsHide: true in Node/Bun spawn options).
Workaround
Section titled “Workaround”- Set
windowsHide: true(CREATE_NO_WINDOW) in the spawning runtime; treat-WindowStyle Hiddenas a cosmetic hint, not a suppression mechanism. - The referenced production fix moved identity/CIM lookups to
windowsHideafter user-visible console flashes (#1236).