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
Powershell -WindowStyle Hidden still shows a window briefly #3028
Comments
powershell.exe is a console application. The console window is automatically created by the OS when the process starts. The powershell.exe code that processes -WindowStyle Hidden is therefore executed after the console window is opened hence the flash. To fix this, we would need the equivalent of wscript i.e. a win32 host application instead of a console host application. |
Given there's no code change we can do in powershell.exe to address this, I've changed this issue to a feature request to have a wscript-like host to support this type of scenario |
http://www.f2ko.de/en/p2e.php |
You could have a |
Can It makes sense that powershell.exe can't be changed after all this time and its legacy. |
I would support a community contribution to add |
Agree .. this would be consistant with other language executables and solve me having to currently wrap my powershell scripts in vbs scripts. |
Technically we could do like https://github.com/AvaloniaUI/Avalonia/wiki/Hide-console-window-for-self-contained-.NET-Core-application editbin.exe /subsystem:windows yourapp.exe But I wonder - if PowerShell Core is portable what is expected behavior on Unix? Can we be unified on all platforms? Maybe @mklement0 have any thoughts? |
@iSazonov |
Yes, I meant - have we the same behavior on Unix by creating a console? Have we scenarios where we don't want to create the console on Unix? |
@iSazonov: I haven't really looked into this; the only thing I can tell you, from personal experience, is that invoking |
What I've been using so far is a shortcut named PS with the Target: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe and the option Run: Minimized |
Seems like the |
So, we are starting to support Windows PowerShell now?? Just a friendly reminder, if this is a PowerShell Core issue? Please provide the PowerShell Core version as is required when submitting an issues. Otherwise, Windows PowerShell need to go thru UserVoice at: https://windowsserver.uservoice.com/forums/301869-powershell For more information see: https://github.com/PowerShell/PowerShell#windows-powershell-vs-powershell-core :) |
@aresowj: While the placement of arguments does matter when calling PowerShell's CLI (given that anything following @MaximoTrinidad: While this issue may have started out as focused on Windows PowerShell only, it has long since morphed into a PS Core feature request (which also deserves back-porting to Windows PowerShell). To recap: In order to get fully invisible invocations via the PowerShell CLI:
|
Thanks @mklement0! |
Sorry guys, mistook the two Powershells and thanks for your clarification. :) |
What about initially starting Powershell in the back ground with a non visible console, then checking for any console window arguments |
I created an issue in the windows console team issue repo here: microsoft/terminal#249 |
We therefore need the previously discussed separate, GUI-subsystem executable, @Jawz84: I don't think the console team can help here:
|
I'll leave the console issue open, see what they think. I see your point, and i know it may be totally impossible. Yet then again, it may be something they would like to consider. [Edit:] I've got the answer that this is not currently feasable to make amends for in console. A separate pwshw.exe would be the way to go for now. |
I reviewed this issue and the related Console Allocation Policy proposal again today. It looks to me will be pretty straightforward for PowerShell once the proposed PowerShell will have
This will keep the exact same behavior as of today, while fixing the flashing windows problem. |
NativeCommandProcessor sometimes allocates hidden console. Perhaps we will have to re-review this too. |
Downside is obvious -- this won't work on down-level machines, so the option of If we decide to support
With the hidden console session, all existing PowerShell script will work (yeah, won't write out or read anything, but it will not crash, and will run just like how it works today with |
Another workaround VBScript that will launch one or more scripts passed as args (great for task scheduling): Set shell = CreateObject("WScript.Shell")
For Each arg In WScript.Arguments
shell.Run("pwsh -windowstyle hidden -executionpolicy bypass -noninteractive -command ""&"" ""'" & arg & "'"""),0
Next Just save as |
How about Powershell.exe -WindowStyle VeryHidden -Command "write-host kiss" |
Maybe we can use vbs + bat + ps1! ps1: bat: vbs: |
This PR is uses windows powershell to create `crc daemon` as task and start it on demand for the current user. This doesn't need any elevated privillages to run `crc daemon` for user context. It try to perform following tasks - Check if there is already crcDaemon task + If present does it the latest one using version info - Install the task using predefined xml definition - Start the task which run the `crc daemon` in background. There is a known issue with windows powershell when you start a task in background using `powershell.exe` then for a second the windows pops up and disappear, PowerShell/PowerShell#3028 have more details around it but as of now this is only the way for interactive user context otherwise the task will need the admin privillages which we want to avoid.
This PR is uses windows powershell to create `crc daemon` as task and start it on demand for the current user. This doesn't need any elevated privillages to run `crc daemon` for user context. It try to perform following tasks - Check if there is already crcDaemon task + If present does it the latest one using version info - Install the task using predefined xml definition - Start the task which run the `crc daemon` in background. There is a known issue with windows powershell when you start a task in background using `powershell.exe` then for a second the windows pops up and disappear, PowerShell/PowerShell#3028 have more details around it but as of now this is only the way for interactive user context otherwise the task will need the admin privillages which we want to avoid.
This PR is uses windows powershell to create `crc daemon` as task and start it on demand for the current user. This doesn't need any elevated privillages to run `crc daemon` for user context. It try to perform following tasks - Check if there is already crcDaemon task + If present does it the latest one using version info - Install the task using predefined xml definition - Start the task which run the `crc daemon` in background. There is a known issue with windows powershell when you start a task in background using `powershell.exe` then for a second the windows pops up and disappear, PowerShell/PowerShell#3028 have more details around it but as of now this is only the way for interactive user context otherwise the task will need the admin privillages which we want to avoid.
This PR is uses windows powershell to create `crc daemon` as task and start it on demand for the current user. This doesn't need any elevated privillages to run `crc daemon` for user context. It try to perform following tasks - Check if there is already crcDaemon task + If present does it the latest one using version info - Install the task using predefined xml definition - Start the task which run the `crc daemon` in background. There is a known issue with windows powershell when you start a task in background using `powershell.exe` then for a second the windows pops up and disappear, PowerShell/PowerShell#3028 have more details around it but as of now this is only the way for interactive user context otherwise the task will need the admin privillages which we want to avoid.
This PR is uses windows powershell to create `crc daemon` as task and start it on demand for the current user. This doesn't need any elevated privillages to run `crc daemon` for user context. It try to perform following tasks - Check if there is already crcDaemon task + If present does it the latest one using version info - Install the task using predefined xml definition - Start the task which run the `crc daemon` in background. There is a known issue with windows powershell when you start a task in background using `powershell.exe` then for a second the windows pops up and disappear, PowerShell/PowerShell#3028 have more details around it but as of now this is only the way for interactive user context otherwise the task will need the admin privillages which we want to avoid.
This PR is uses windows powershell to create `crc daemon` as task and start it on demand for the current user. This doesn't need any elevated privillages to run `crc daemon` for user context. It try to perform following tasks - Check if there is already crcDaemon task + If present does it the latest one using version info - Install the task using predefined xml definition - Start the task which run the `crc daemon` in background. There is a known issue with windows powershell when you start a task in background using `powershell.exe` then for a second the windows pops up and disappear, PowerShell/PowerShell#3028 have more details around it but as of now this is only the way for interactive user context otherwise the task will need the admin privillages which we want to avoid.
This PR is uses windows powershell to create `crc daemon` as task and start it on demand for the current user. This doesn't need any elevated privillages to run `crc daemon` for user context. It try to perform following tasks - Check if there is already crcDaemon task + If present does it the latest one using version info - Install the task using predefined xml definition - Start the task which run the `crc daemon` in background. There is a known issue with windows powershell when you start a task in background using `powershell.exe` then for a second the windows pops up and disappear, PowerShell/PowerShell#3028 have more details around it but as of now this is only the way for interactive user context otherwise the task will need the admin privillages which we want to avoid.
I ported run-hidden from C# to C++, so it's a tiny bit faster: https://github.com/stax76/run-hidden
|
Hi, Just adding my 2 cents here. This bug doesn't just occur when you run the Windows style Hidden argument in a run dialog but also through any task called by the Windows Task Scheduler. For example certbot's auto renew is a task that runs twice a day with this argument and has the PowerShell window briefly flash. It's a really spooky bug if you don't know what's going on. I thought I had a virus because PowerShell would flash randomly. I'm not the only one who has thought this because when I searched PowerShell flashing randomly I found a Stack Overflow post mentioning to check the Task Scheduler. It's one thing to see the Powershell window flash briefly after you entered a command in the run dialog and hit enter. It's another thing when you're just using your computer normally and this just happens randomly. |
I know this is already implied in @Roelovic 's comment, but I just want to emphasize that the method won't work for commands, e.g. |
Steps to reproduce
In Windows Run dialog type this:
PowerShell.exe -WindowStyle Hidden -Command ping www.microsoft.com
Expected behavior
There should be no window, right now you can't start powershell without window flashing, making it rather useless e.g. for scheduled tasks.
Note I think this is intended behavior, but it's confusing and new option is probably required. If you search how to run a powershell in scheduled task, the go-to workaround is to do a vbs script of all things! Such as:
This is not a good thing, powershell needs this feature in the shell itself, scheduled tasks are important feature and having a window flash on scheduled task is a really bad experience.
Actual behavior
It flashes the powershell window briefly.
Environment data
The text was updated successfully, but these errors were encountered: