Skip to content

feat: prevent conhost from pop-up on Windows - #10334

Closed
rafaeloledo wants to merge 1 commit into
syncthing:mainfrom
rafaeloledo:main
Closed

rafaeloledo wants to merge 1 commit into
syncthing:mainfrom
rafaeloledo:main

Conversation

@rafaeloledo

@rafaeloledo rafaeloledo commented Sep 1, 2025 •

Copy link
Copy Markdown

Purpose

This change prevents the conhost process from popping. So the docs can remain the same and the --no-console flag remains working. If the change isn't made, it's needed to refactor the entire docs adapting it to powershell ... -Hidden wrapping approach. Wrapping with conhost --headless still pops the terminal in a bat/cmd script since it's a compilation-related problem and the OS forces the window appearing if there's no conhost process in the tree, only working, then, inside a terminal, which less tech savvy users won't do.

The problem of wrapping it with powershell, though, it's that user must run ExecutionPolicy changes similar to scoop.sh which i think it's not desired.

Testing

I've compiled the program in the GOOS matching windows and GOARCH amd64.
You can reproduce in your machine quite easily. The problem is the default debug log is omitted on Windows.
wezterm uses the approach of wezterm.exe and wezterm-gui.exe which could be desired in this case, depending on maintainers will.

Screenshots

It's not a GUI change. The webclient is the same and it maintains working.

Documentation

Relates and may close syncthing/docs#957 and syncthing/docs#955.
Derived from syncthing/docs#926 and #8760

Authorship

@github-actions github-actions Bot added the enhancement New features or improvements of some kind, as opposed to a problem (bug) label Sep 1, 2025
@calmh

calmh commented Sep 1, 2025 •

Copy link
Copy Markdown
Member

Yeah we've had this up as a suggestion a few times, potentially as a separate build that is also shipped beside the regular one. The problem with having it as the default as you suggest is that all the CLI commands that Syncthing provide become useless. Including stuff like just running syncthing --help from cmd.

@Shablone

Shablone commented Sep 1, 2025 •

Copy link
Copy Markdown
Contributor

While I'm glad, seing this PR, I'll suggest to use a seperate build, as the cli will be broken with that flag
// oh @calmh was faster :)

@rafaeloledo

rafaeloledo commented Sep 1, 2025 •

Copy link
Copy Markdown
Author

Can we work, then, in a separate build similar to wezterm? I'm accepting suggestions and modifications on the commits, btw. Feel free to do it.

Starting doing some research on how wezterm handles that problem...

@calmh

calmh commented Sep 1, 2025

Copy link
Copy Markdown
Member

It requires a few more changes to ship two binaries using our build process, I made a couple of attempts but first attempt got pushback, second attempt got crickets, so I concluded nobody really cares about it: #8760

@calmh

calmh commented Sep 1, 2025

Copy link
Copy Markdown
Member

If you want to take that attempt and rework it into the current version, I don't think it should be too many changes from what was there, I think we can work with that.

@rafaeloledo

Copy link
Copy Markdown
Author

@AudriusButkevicius Seems that only you are not sure of the changes. Before aiming that idea i've tried similar changes that mentioned in #8760 . In syncthing/docs#926 i've shown that the only way of hiding the window from pop-up beside creating another build .exe is wrapping it with powershell script. Even with conhost that is another candidate, it work only running the command by hand.

  • Creating another build
  • Wrapping with powershell and requiring ExecutionPolicy changes
  • Wrapping with conhost but resolving nothing
image image

You have a suggestion, then?

@rafaeloledo

rafaeloledo commented Sep 1, 2025 •

Copy link
Copy Markdown
Author

Tested

syncthing-service.bat

cmd /C "syncthing.exe --no-console --no-browser"

The window pops similar to conhost.exe

So, only powershell ... -Hidden is capable of hiding the console build

@calmh

calmh commented Sep 1, 2025

Copy link
Copy Markdown
Member

Is powershell available everywhere relevant, can we just ship a syncthing-no-console.ps1 in the zip archive and be good?

@rafaeloledo

Copy link
Copy Markdown
Author

Is powershell available everywhere relevant, can we just ship a syncthing-no-console.ps1 in the zip archive and be good?

It's the last resort possibility if no ones fit.

syncthing-service.ps1

Start-Process -FilePath "syncthing.exe" -ArgumentList "--no-console --no-browser" -WindowStyle Hidden

This works with the console build but also needs modifying, by hand, the ExecutionPolicy.

For the task scheduler to automatically run the script is needed to know the installation path, which can be done within scoopinstaller/extras and write in the installation process to te stream.

install-syncthing-service.bat

schtasks /create /sc ONLOGON /tn Syncthing /tr "$expanded_path_to_ps1"

@tomasz1986

tomasz1986 commented Sep 1, 2025 •

Copy link
Copy Markdown
Member

Is powershell available everywhere relevant, can we just ship a syncthing-no-console.ps1 in the zip archive and be good?

Not sure how useful it would be, as running unsigned PowerShell scripts is blocked by default in Windows, and I assume that the main target of having a version of Syncthing that runs completely hidden are the non-tech-savvy, who won't be changing this setting (which is a good thing in terms of security).

@calmh

calmh commented Sep 1, 2025

Copy link
Copy Markdown
Member

Can we sign it to make it useful? We codesign the normal binary.

@rafaeloledo

rafaeloledo commented Sep 1, 2025 •

Copy link
Copy Markdown
Author

Not sure how useful it would be, as running unsigned PowerShell scripts is blocked by default in Windows, and I assume that the main target of having a version of Syncthing that runs completely hidden are the non-tech-savvy, who won't be changing this setting (which is a good thing in terms of security).

We can ship the installation with a ps1 for who wants and let the installation be done by scoop that already changed ExecutionPolicy as requirement (tech savvy users).

@tomasz1986

Copy link
Copy Markdown
Member

Honestly, I think having a separate syncthingw.exe signed binary would be the best and most user-friendly approach. Then those, who need it, would be able to just run it without any additional configuration necessary.

@rafaeloledo

Copy link
Copy Markdown
Author

Honestly, I think having a separate syncthingw.exe signed binary would be the best and most user-friendly approach. Then those, who need it, would be able to just run it without any additional configuration necessary.

@tomasz1986, is only possible to merge with @AudriusButkevicius review? In the last PR made by @calmh, he noted that two binaries aren't necessary.

@rafaeloledo

rafaeloledo commented Sep 1, 2025 •

Copy link
Copy Markdown
Author

Honestly, I think having a separate syncthingw.exe signed binary would be the best and most user-friendly approach. Then those, who need it, would be able to just run it without any additional configuration necessary.

I also think this, considering that no changes in the docs are needed with the changes. Only updating the places where syncthing.exe is mentioned to syncthing-gui.exe/syncthingw.exe

@calmh

calmh commented Sep 1, 2025 •

Copy link
Copy Markdown
Member

It totally is, and we could have done so previously, but there was no one else that had a positive view of it either. And windows isn't my platform, so I didn't really feel like spearheading the effort too strongly. This isn't a "Audrius said no", it's "Audrius tried to provide a better alternative, then nobody else cared either way". :)

@rafaeloledo

rafaeloledo commented Sep 1, 2025 •

Copy link
Copy Markdown
Author

It totally is, and we could have done so previously, but there was no one else that had a positive view of it either. And windows isn't my platform, so I didn't really feel like spearheading the effort too strongly. This isn't a "Audrius said no", it's "Audrius tried to provide a better alternative, then nobody else cared either way". :)

So, the work of investigating is done by me. Only powershell will fit the requirements of not popping the console window. May we wait for another opinion of @AudriusButkevicius ?

@rafaeloledo

rafaeloledo commented Sep 1, 2025 •

Copy link
Copy Markdown
Author

I think it would be great to commit all the changes here and let him remove the not desired. How can i open to you merge your PR changes @calmh ?

@tomasz1986

Copy link
Copy Markdown
Member

I would say that the situation has changed with Windows Terminal becoming the default shell, and thus --no-console no longer doing its job for the majority of Windows users. I think this is the main reason why having a separate executable is more necessary/useful than it was before.

@bt90

bt90 commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

+1 from me for a dedicated binary. That's also how e.g Java handles this. All this Powershell and task scheduler stuff is just hacky IMHO 🤷

@tomasz1986

Copy link
Copy Markdown
Member

That's also how e.g Java handles this.

Python as well (via pythonw.exe) 😉.

@Shablone

Shablone commented Sep 1, 2025

Copy link
Copy Markdown
Contributor

In the meantime I created a PR for the root cause: #10335

@rafaeloledo

rafaeloledo commented Sep 1, 2025 •

Copy link
Copy Markdown
Author

In the meantime I created a PR for the root cause: #10335

Since @Shablone is trying to solve the problem in a different way, i'll continue integrating the solutions from #8760 and putting some powershell-related files to the project and let @AudriusButkevicius decide. This PR and #10335 are mutually exclusive and have a different approach on solving the problem.

This aims to make minor changes and the one from @Shablone is restructing the way sycnthing interacts with Windows APIs which could make breaking changes since it interacts directly with kernel32.

@rafaeloledo

Copy link
Copy Markdown
Author

@calmh Did you mind revamping #8760 here or it's better to only have the powershell solution?

@calmh

calmh commented Sep 2, 2025

Copy link
Copy Markdown
Member

Go for it. I don't think there's a need to keep invoking Audrius. If he has an opinion on it he'll be around. :)

@rafaeloledo

rafaeloledo commented Sep 2, 2025 •

Copy link
Copy Markdown
Author

@calmh I think a3bed33 is the best i can do for integrating powershell in the project. I'll be studying the two-binary approach and commiting it here with some possible changes and your co-author. If there's any problem you can send me here.

I've added inline ExecutionPolicy to override global definitions. When user gives admin privileges on running the install script, it giving that power to run the ps1 in the task even with Current User Scope set as Restricted. Which is the Windows 11 default policy on installation. It can prevent user from running commands in the terminal as well as persisting rules.

@calmh

calmh commented Sep 2, 2025

Copy link
Copy Markdown
Member

So, looking at how these things apparently actually work in Windows, this doesn't help with the somewhat basic desire to have something that you can double click to start Syncthing without having a console window remain on screen. It seems to me then that it is not enormously useful and fits better either in an etc dir (like we ship startup suggestions for other systems, in this case it'd be in windows-taskscheduler or something with the scripts and a readme) or as instructions on the docs site.

@tomasz1986

Copy link
Copy Markdown
Member

On a side note, there is also Syncthing Windows Setup (which we recommend on the official site) that can take care of the whole installation and autostart operation.

@rafaeloledo

rafaeloledo commented Sep 2, 2025 •

Copy link
Copy Markdown
Author

On a side note, there is also Syncthing Windows Setup (which we recommend on the official site) that can take care of the whole installation and autostart operation.

This contribution is aimed for those who not use wizards or managers. I manage my entire programs with scoop installer. For me, using external programs in addition is just a waste of time.

For all my teammates that are using Windows i recommend the installer. Asking for using yet another tool when having a meeting is out of my mind.

I've been merging PRs quite a while in Windows just to it have a better experience without GUIs and Managers. Simplifying, making Windows more similar to Linux in this matter.

@tomasz1986

Copy link
Copy Markdown
Member

Yeah, but isn't it better to just utilise the existing Windows Setup for that? It supports various command line arguments, including silent installation, per-user installation, installation as a service, etc. It is also available via WinGet, which makes deployment easy.

@rafaeloledo

rafaeloledo commented Sep 2, 2025 •

Copy link
Copy Markdown
Author

Yeah, but isn't it better to just utilise the existing Windows Setup for that? It supports various command line arguments, including silent installation, per-user installation, installation as a service, etc. It is also available via WinGet, which makes deployment easy.

It's not related to what is better. I prefer to let the user decide it. Syncthing Windows Setup could be a good program and using CLI tools too, it's just a preference. As a terminal-based user, i tend to use terminal for as much work as i can. If syncthing is opinionated on not having both, i have no problem with it.

I'm current working on making the scripts work being shipped inside the /etc, which is already a secondary folder.

@rafaeloledo

rafaeloledo commented Sep 3, 2025 •

Copy link
Copy Markdown
Author

Bad news. After some tests, i've discovered that, in my old ones, the Poweshell 5.1 was opened and the process was being reutilized the same way as conhost reutilizes itself. The -WindowStyle Hidden argument just prevents the pop window from being focused while in another app.

@calmh the only way to fix this is in fact rebuilding the app as gui application or making direct WinAPI calls if a duplicated binary is not wanted as proposed in #8760 and #10335.

I will close this PR just because i consider my powershell proposals finished and i don't have time to revamp the #8760 for now.

this change checks wether the current OS of compilation matches windows, if so, it assumes the form of a gui application which tells the OS to not spawn a conhost window

Co-authored-by: Rafael Ledo <[email protected]>
Co-authored-by: calmh <[email protected]>
Co-authored-by: Shablone <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New features or improvements of some kind, as opposed to a problem (bug)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants