Skip to content

-WindowStyle Hidden still flashes a console window

args quoting · case

bothsilentscriptagentfirst-partyrepro: verifiedconsole-allocation
Affectspowershell 51, pwsh 7, windows, win32 api
Fails assilent
Mechanismconsole allocation
Safe fixcreate no window

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.

Terminal window
# 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).

  • Set windowsHide: true (CREATE_NO_WINDOW) in the spawning runtime; treat -WindowStyle Hidden as a cosmetic hint, not a suppression mechanism.
  • The referenced production fix moved identity/CIM lookups to windowsHide after user-visible console flashes (#1236).