terminal: PowerShell argument `WindowStyle -Hidden` is not respected when the default terminal application is Windows Terminal

Windows Terminal version

1.12.10393.0

Windows build number

Microsoft Windows NT 10.0.22549.0

Other Software

Software Version
PowerShell.exe Multiple Versions
pwsh.exe Multiple Versions

Steps to reproduce

  1. Set Windows Terminal as the default terminal application: . image

  2. Make sure to save changes to Windows Terminal Settings, and then using Windows Run, run pwsh -WindowStyle Hidden -Command Sleep 10: image

Expected Behavior

A new PowerShell process launches (Windows Terminal), and it isn’t visible. The window may flash for a second. PowerShell window shouldn’t be displayed when it’s launched with WindowStyle -Hidden.

Actual Behavior

A new PowerShell process launches (on Windows Terminal), and it is visible and remains visible (and waits) for 10 seconds.

image

Note: There is no repro for this issue with Windows Console Host as the default terminal application.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 7
  • Comments: 22 (8 by maintainers)

Most upvoted comments

Request: Since all SW_HIDE related-issues get closed as duplicates of this thread, perhaps change this issue title to something not so Powershell-specific?

DHowett’s idea makes the most sense to me: Hide the tab, and I’m with KG-droid, if we wanted users to mess with the window, we’d minimize it.

Yeh confirmed it just minimises it. I have found what seems to be a work around though:

$script:showwindowAsync = Add-Type -memberDefinition @" [DllImport (“user32.dll”)] public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdshow); "@ -name “Win32ShowWindowAsync” -namespace Win32Functions -passThru

$showwindowAsync: : ShowWindowAsync( (Get-Process -id $pid).MainWindowHandle, 2)

If you add that to the start of your scripts it hides the window via win32api. At least then you don’t have to just disable Windows Terminal in your organisation to get around this. Although that said it depends how many scripts you have that run as the user, if it’s pheasable to add that script to all of them.

Yeah, many thanks for that, i already use a C# app for hide console if needed, but… As of this is a Bug-Report (Issue Tracker) for “Windows Terminal” and the BUG still exists, it is not my point “how to workaround”, but thanks anyway!

It’s still bugged in “Windows Terminal” and so it is up to them to fix this in the Terminal Code! Especially as of this is a “Feature” used and working PROPERLY in the default Terminal but it is NOT in “Windows Terminal” and exactly THAT is the point of this Bug-Report!

You can Block me or set anything to Off-topic as often as you want… But this will NOT fix the (1+ Year old) Bug, it still exists and is not working with powershell.exe nor is it on pwsh.exe, that is REALITY not not a problem with Powershell at all!

Based on other bugs I’ve logged even with Premier support, it seems Microsoft barely have enough devs to make new features, as they seem to have no time to fix non critical bugs!

Yeah… Maybe it’s time to prioritize Fixing existing Bugs instead of creating new ones. 🤣

@KG-droid Check the changelogs and spare us your childish frustration. can you be more “specific”? Link to a Page where X Tags are listed is not helpful! Also your derogatory comment is not at all…

The changelog Windows Terminal Preview v1.17.1023 does not contain any Fix for THIS problem and the last non-Preview also does not of course, so… What is your point?

@youk not sure why that was directed towards @KG-droid, as it’s @fuba82 being childish.

Nonetheless, let’s not make this a pie-throwing contest 😃

Most useful comment I’ve seems, thanks…👍

Error still exists 1 year after report… really? 👍

Hey @zadjii-msft! Now that we merged tearoff plus #14944 and #13478, we might have the right underpinnings to let console applications “hide” their windows.

Mini-proposal (which should be fleshed out into a spec):

A console application that hides its window should be detached from the pane/tab it’s in and moved to a new tab in a hidden window. That window can show up in the tray icon list of windows, and users can show them if they want, but we won’t have to present UI for it. If that console app was already the only tenant in a window (no panes/tabs), we could just mark that one hidden.

Hi DHowett When you say “That window can show up in the tray icon list of windows”, do you mean a user would be able to just click the icon in the tray/taskbar icons and re-open the hidden window? As ideally from a business point of view, you wouldn’t want users to be able to see and mess with hidden windows that easily, that are configuring things, as inevitably, some users would end up closing it, and then end up logging incidents because something is no longer working.

I’m gonna lock this thread for a bit to give everyone some time to relax. Obviously, this is still busted (at least, for Powershell 7 pwsh, though, it seems to work for powershell.exe). You’ll note, there’s plenty of issues on this repo that are even older than this one. We do our best to fix as many issues as we can, but if this is one that you’re particularly passionate about, we’d love to hear suggestions on how to fix it. The Terminal (and PowerShell) are open-source after all ☺️

@HenryBaby Marriage made in heaven.

@fuba82

What is your point?

Read the message I was replying to and you’ll have a chance to see the point. Instead of wasting my time reading your postings.

@youk not sure why that was directed towards @KG-droid, as it’s @fuba82 being childish.

Nonetheless, let’s not make this a pie-throwing contest 😃

Hey @zadjii-msft! Now that we merged tearoff plus #14944 and #13478, we might have the right underpinnings to let console applications “hide” their windows.

Mini-proposal (which should be fleshed out into a spec):

A console application that hides its window should be detached from the pane/tab it’s in and moved to a new tab in a hidden window. That window can show up in the tray icon list of windows, and users can show them if they want, but we won’t have to present UI for it. If that console app was already the only tenant in a window (no panes/tabs), we could just mark that one hidden.

it seems to work for powershell.exe

NO it does not… The Terminal Window just “minimize” but is not “Hidden” as intended!

with the “default” console both of this work: powershell -WindowStyle Hidden -Command Sleep 10 AND pwsh -WindowStyle Hidden -Command Sleep 10

This is a blocker for many applications such as rush that use PowerShell to run background tasks. Rush issue tracked here.

PowerShell/PowerShell#3028 looks like it’s related. This probably requires quite a bit of thinking…

The console window being shown for a second may still be tolerable but with WT the window isn’t hidden at all - there’s no difference between using the PowerShell argument -WindowStyle Hidden and not using this argument when WT is the default terminal application.