You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Reacted by OneManMonkeySquad, Dan G, Anton Trapp and Eamon Nerbonne
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.
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')
Reacted by Zian
microsoft-github-policy-service commented on Nov 16, 2023
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 commented on Nov 16, 2023
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 commented on Nov 16, 2023
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.
Activity
BrucePay commentedon Sep 14, 2018
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 commentedon Sep 15, 2018
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:
Therefore, this issue calls for a different solution, namely an enhancement to the
Start-Processcmdlet, as proposed.mklement0 commentedon Sep 15, 2018
Thus - unless you see a flaw in my clarification - please remove the
Resolution-Duplicatelabel from this issue, Bruce Payette (@BrucePay).BrucePay commentedon Sep 15, 2018
Michael Klement (@mklement0) You didn't mention
Start-Processin the issue so I assumed you were talking aboutpwshitself. 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 commentedon Sep 16, 2018
Thanks, Bruce Payette (@BrucePay):
Start-Processwas 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):
microsoft-github-policy-service commentedon Nov 16, 2023
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 commentedon Nov 16, 2023
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 commentedon Nov 16, 2023
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 commentedon Nov 23, 2023
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes.