Skip to content

Start-Process -WindowStyle Minimized steals focus #7790

Closed

Description

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

Activity

  1. added
    Resolution-Duplicate
    Issue-Enhancement
    on Sep 14, 2018
  2. BrucePay commented on Sep 14, 2018

    @BrucePay
    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.

  3. mklement0 commented on Sep 15, 2018

    @mklement0
    ContributorAuthor

    Bruce Payette (@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.

  4. mklement0 commented on Sep 15, 2018

    @mklement0
    ContributorAuthor

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

  5. added
    Resolution-External
    and removed
    Resolution-Duplicate
    Resolution-External
    on Sep 15, 2018
  6. BrucePay commented on Sep 15, 2018

    @BrucePay
    Collaborator

    Michael Klement (@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.

  7. mklement0 commented on Sep 16, 2018

    @mklement0
    ContributorAuthor

    Thanks, Bruce Payette (@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')
  8. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    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.

  9. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    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.

  10. microsoft-github-policy-service commented on Nov 16, 2023

    @microsoft-github-policy-service
    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.

  11. added
    Resolution-No Activity
    on Nov 16, 2023
  12. microsoft-github-policy-service commented on Nov 23, 2023

    @microsoft-github-policy-service
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-EnhancementResolution-No Activity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions