8000 Start-Process -WindowStyle Minimized steals focus · Issue #7790 · PowerShell/PowerShell · GitHub
[go: up one dir, main page]

Skip to content

Start-Process -WindowStyle Minimized steals focus #7790

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mklement0 opened this issue Sep 14, 2018 · 9 comments
Closed

Start-Process -WindowStyle Minimized steals focus #7790

mklement0 opened this issue Sep 14, 2018 · 9 comments
Labels
Issue-Enhancement the issue is more of a feature request than a bug Resolution-No Activity Issue has had no activity for 6 months or more

Comments

@mklement0
Copy link
Contributor
mklement0 commented Sep 14, 2018

It's fair to assume that you typically do not want the newly created, minimized window to steal focus from the calling application when you use Start-Process -WindowStyle Minimized.

That is, the calling application (console window) should remain the active application and continue to receive keyboard output.

Currently, -WindowStyle Minimized invariably focuses the minimized window - while the calling window is by definition not obscured, it loses keyboard focus that way.

Two possible enhancements:

  • Change -WindowStyle Minimized to not steal focus.

  • Since that is technically a breaking change - someone may rely on the old behavior, though I have trouble picturing why - alternatively introduce a new style, MinimizedNoFocus similar to Visual Basic's [AppWinStyle] enumeration.

    • Conceivably, NormalNoFocus could be implemented too (that is, start a process with normal window size, but without giving it focus).

Update:

A related, but distinct issue is #3028, which concern's the CLI's (the pwsh executable's) -WindowStyle parameter, notably the ability to start PowerShell as a whole hidden.

Environment data

Written as of:

PowerShell Core 6.1.0
@BrucePay BrucePay added Resolution-Duplicate The issue is a duplicate. Issue-Enhancement the issue is more of a feature request than a bug labels Sep 14, 2018
@BrucePay
Copy link
Collaborator

This is basically the same issue as #3028 and the solution is the same: create a windows host for PowerShell as opposed to the existing console host.

@mklement0
Copy link
Contributor Author
mklement0 commented Sep 15, 2018

@BrucePay:

This issue and #3028 are distinct use cases:

  • Powershell -WindowStyle Hidden still shows a window briefly #3028 is about launching PowerShell itself, completely and persistently hidden, which is currently impossible without the help of a non-console-subsystem entry point, as proposed in the linked issue.

  • This issue is about launching processes from PowerShell (a visible console window) in a way that:

    • launches them asynchronously, initially out of sight
    • yet still allows inspecting their output interactively, on demand, by manually opening the minimized window.

Therefore, this issue calls for a different solution, namely an enhancement to the Start-Process cmdlet, as proposed.

@mklement0
Copy link
Contributor Author

Thus - unless you see a flaw in my clarification - please remove the Resolution-Duplicate label from this issue, @BrucePay.

@BrucePay BrucePay added Resolution-External The issue is caused by external component(s). and removed Resolution-Duplicate The issue is a duplicate. Resolution-External The issue is caused by external component(s). labels Sep 15, 2018
@BrucePay
Copy link
Collaborator

@mklement0 You didn't mention Start-Process in the issue so I assumed you were talking about pwsh itself. Thanks for clarifying. Perhaps you could update the issue text to include this information. As to supporting this functionality, the API you mentioned is only available by including the VisualBasic assembly which isn't likely in Core. It should be possible to use interop to implement the equivalent in pwsh but it would be better if it were supported in CoreFx since it is a base OS kind of thing. I'm inclined to mark it as "resolution external" but I suppose some enterprising individual could decide to do it in PoweShell instead.

@mklement0
Copy link
Contributor Author
mklement0 commented Sep 16, 2018
edited
Loading

Thanks, @BrucePay: Start-Process was in the title to begin with, but I've now added it to the initial post for clarity.

Yes, arguably [System.Diagnostics.ProcessStartInfo] should always have provided this functionality - though it's quite likely this will always remain a Windows-only feature.

To future readers / potential implementers in PowerShell: It is the ShellExecute[Ex] WinAPI function that provides the requisite functionality.

Examples of using the VisualBasic assembly you mention (Windows only):

Add-Type -Assembly Microsoft.VisualBasic
# Launch a GUI application in a minimized window without focus:
[Microsoft.VisualBasic.Interaction]::Shell('Notepad', 'MinimizedNoFocus')

# Launch a console application in a minimized window without focus
# !! Specifying a console application *directly* doesn't work, because it would run in the 
# !! *current* console window.
# !! The *conhost.exe workaround* requires *Windows 10*
[Microsoft.VisualBasic.Interaction]::Shell('conhost cmd /k echo hi', 'MinimizedNoFocus')

Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

2 similar comments
Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

Copy link
Contributor

This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you.

@microsoft-github-policy-service microsoft-github-policy-service bot added Resolution-No Activity Issue has had no activity for 6 months or more labels Nov 16, 2023
Copy link
Contributor

This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement the issue is more of a feature request than a bug Resolution-No Activity Issue has had no activity for 6 months or more
Projects
None yet
Development

No branches or pull requests

2 participants
0