Skip to content
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

ps window loses focus after start-process #19606

Closed
5 tasks done
kasini3000 opened this issue May 3, 2023 · 2 comments
Closed
5 tasks done

ps window loses focus after start-process #19606

kasini3000 opened this issue May 3, 2023 · 2 comments

Comments

@kasini3000
Copy link

kasini3000 commented May 3, 2023

Prerequisites

Steps to reproduce

Start-Process -FilePath  "pwsh"  -ArgumentList " -NonInteractive -NoProfile -WindowStyle hidden -file a:\pscode\TEMP_2023\temp135\aaa-v2.ps1 "

When "Start-Sleep -second 5" on aaa-v2.ps1,The parent powershell process will soon return to focus.
When "Start-Sleep -second 55" on aaa-v2.ps1,The parent powershell process will long time return to focus.

Expected behavior

Return to focus right now after The parent powershell process script end  .

Actual behavior

ps window loses focus after start-process

Error details

Cause:
The powershell window loses focus after start-process.
When the "start-process process" ends, focus will resume, depending on the length of the process execution time.

If your script contains "start-process",
in order to retrieve the focus of the powershell window, you will frequently click on the window,


I want to write a script to fix it.
But it was found the script works normally in powershell, but does not work in win terminal.

Environment data

powershell 5.1.19041.1320 on win10
PowerShell 7.4.0-preview.3 on win10
all version win terminal.
parent powershell child pwsh,
parent pwsh child powershell,

Visuals

No response

@kasini3000 kasini3000 added the Needs-Triage The issue is new and needs to be triaged by a work group. label May 3, 2023
@mklement0
Copy link
Contributor

mklement0 commented May 3, 2023

By design, Start-Process makes the newly launched process' main window the active window (the foreground window with the input focus).

Since your intent appears to be to launch a hidden PowerShell instance, use -WindowStyle Hidden with Start-Process rather than the -WindowStyle hidden CLI parameter, which bypasses the problem of losing focus.

(With the CLI parameter, a visible console window is still invariably created initially, when PowerShell is launched, and is only then hidden by PowerShell itself - at which point the focus has already been lost; see also:

@kasini3000
Copy link
Author

good , 3q!

@ghost ghost removed the Needs-Triage The issue is new and needs to be triaged by a work group. label May 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants