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

daemon: start daemon from a powershell script that hides window #3775

Merged
merged 1 commit into from
Aug 9, 2023

Conversation

anjannath
Copy link
Member

@anjannath anjannath commented Jul 28, 2023

after windows terminal became the default terminal/console host on windows the daemon scheduled task would show a console window upon running as it wasn't respecting the poweshell cmdline argument for hiding the window

this powershell script hides the window by using win32 api from powershell

fixes #3726

@cfergeau
Copy link
Contributor

I think you tried this kind of approaches https://stackoverflow.com/questions/23250505/how-do-i-create-an-executable-from-golang-that-doesnt-open-a-console-window-whe to avoid showing the window?
047873f seems to imply this isnot an option as we cannot run the binary directly from the task XMl, we need an intermediate powershell instance to start it?

@gbraad
Copy link
Contributor

gbraad commented Jul 31, 2023

I proposed something similar as Christophe; make the executable be 'regarded' as a GUI application, but not actually create the window.

Can this be tried?

The issue with the script is that this can be marked again as a problem when it comes to 'false positives' on scans.

@anjannath
Copy link
Member Author

I tried both the approaches mentioned there -- the issue with using -H=windowsgui is that, once CRC is compiled with this flag, it doesn't work as a CLI anymore, even when its launched from powershell as ./crc.exe --help, it means we have to ship two crc binaries, one for the daemon and another for the CLI. I didn't spend a lot of time looking to find a way if we can have an executable that is both GUI and CLI, but if that's possible i think we can use this method. as we can directly start it from task scheduler without having to invoke powershell

the other method using the github.com/gonutz/w32/v2 library to hide the windows after crc is launched seems to not do anything, my guess is because CRC doesn't create any window

@praveenkumar
Copy link
Member

Did we test it works with win10 and win11 both?

@gbraad
Copy link
Contributor

gbraad commented Jul 31, 2023

have an executable that is both GUI and CLI

You can't

"Each PE application contains a field in its header that specifies which subsystem it was designed to run under. You can say IMAGE_SUBSYSTEM_WINDOWS_GUI to mark yourself as a Windows GUI application, or you can say IMAGE_SUBSYSTEM_WINDOWS_CUI to say that you are a console application. If you are GUI application, then the program will run without a console." - Raymond Chen

... unless you do some trickery:

"In VisualStudio case, there are actually two binaries: devenv.com and devenv.exe. Devenv.com is a Console app. Devenv.exe is a GUI app. When you type devenv, because of the Win32 probing rule, devenv.com is executed. If there is no input, devenv.com launches devenv.exe, and exits itself. If there are inputs, devenv.com handles them as normal Console app.

In ildasm case, there is only one binary: ildasm.exe. It is first compiled as a GUI application. Later editbin.exe is used to mark it as console subsystem. In its main method it determines if it needs to be run as console mode or GUI mode. If need to run as GUI mode, it relaunches itself as a GUI app." - Junfeng Zhang

... so, let's conclude that it's not worth the extra effort at this point.

@anjannath
Copy link
Member Author

Did we test it works with win10 and win11 both?

yes, i have tested the script hides the powershell window on both win 10 and 11, but not an end-to-end test using crc setup

after windows terminal became the default terminal/console host on
windows the daemon scheduled task would show a console window upon
running as its not recognizing the powershell cmdline argument for
hiding the window

this powershell script hides the window by using win32 api from
powershell

fixes crc-org#3726
@anjannath
Copy link
Member Author

anjannath commented Jul 31, 2023

Did we test it works with win10 and win11 both?

yes, i have tested the script hides the powershell window on both win 10 and 11, but not an end-to-end test using crc setup

tested on both windows 10 and windows 11 now and its working as expected, (still shows the powershell window briefly when running crc setup and then disappears)

the new pushes were for fixing the quotes around the crc daemon command, the whole command was enclosed in quotes earlier along with the args, which was found when testing end-to-end

@openshift-ci
Copy link

openshift-ci bot commented Jul 31, 2023

@anjannath: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/integration-crc 882619b link true /test integration-crc
ci/prow/e2e-crc 882619b link true /test e2e-crc

Full PR test history. Your PR dashboard.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here.

@openshift-ci
Copy link

openshift-ci bot commented Aug 9, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gbraad

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label Aug 9, 2023
@anjannath anjannath merged commit da7f3bd into crc-org:main Aug 9, 2023
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Somethings launches a powershell terminal on Windows that stays around
4 participants