haimgel / display-switch

Turn a $30 USB switch into a full-featured multi-monitor KVM switch
https://haim.dev/posts/2020-07-28-dual-monitor-kvm/
MIT License
2.85k stars 112 forks source link

Run as Windows Service #17

Closed cocowalla closed 10 months ago

cocowalla commented 3 years ago

Firstly, thanks for this - it works great with my cheap USB switch!

Similarly to #5, I don't want to have display-switch.exe visible in the task bar all the time, taking up space. I understand you prefer not to clutter the tray bar (altho IMO that would be preferable to cluttering the task bar :smile:) - could display-switch run as a Windows Service instead?

I know absolutely nothing about DDC/CI, so I don't know if perhaps display-switch needs access to the desktop session, or if there might be other barriers.

haimgel commented 3 years ago

Cluttering the task bar

This is actually a regression in the current master comparing to 0.1.0! It should not do that, it should run silently without a console window visible (at least by default).

haimgel commented 3 years ago

Furthermore about "run as a windows service": I'd prefer this to require as few permissions as possible, to allow this to be run on corp computers where the user does not necessarily have admin rights. I don't think there's a great value in this, comparing to just dropping the exe into the startup folder and forget about it.

cocowalla commented 3 years ago

Furthermore about "run as a windows service": I'd prefer this to require as few permissions as possible, to allow this to be run on corp computers where the user does not necessarily have admin rights. I don't think there's a great value in this, comparing to just dropping the exe into the startup folder and forget about it.

I have such corp computers, so fully agree as long as no window is shown 👍

cocowalla commented 3 years ago

@haimgel I don't know if you want to re-open this issue, but after using display-switch for a while there is one niggling issue I have, which is related to it running as a console app.

Because display-switch runs as a console app in a user session, you have to login once to the computer before it will switch automatically.

This is because before you login, display-switch doesn't start. If instead it ran as a Windows service, it would start when the computer booted.

haimgel commented 3 years ago

Yeah, this is a valid concern. As long as this "service mode" is optional, it could be a useful thing to have. I won't have time for this right now, but I'll keep the ticket open.

oddbjornkvalsund commented 3 years ago

A third party solution to this could be to use https://github.com/winsw/winsw as a service wrapper. I've used this for years (in a different context) and it works great!

cocowalla commented 3 years ago

@oddbjornkvalsund I tried this just the other day, but unfortunately it doesn't seem to work. When running as a service, I can see from the logs that display-switch does detect the USB changes, but it logs this with regards to displays:

[ERROR] Did not detect any DDC-compatible displays

I tried even running the service as LocalSystem, and also tried allowing it to interact with the desktop, but get the same result, whether logged in already or not.

oddbjornkvalsund commented 3 years ago

@cocowalla Ah, I haven't tried using winsw with display-switch unfortunately, so I have no first hand experience to offer, but did you try running the service as your personal user? I'm not sure if that's even possible...

LegendaryB commented 2 years ago

@oddbjornkvalsund I tried this just the other day, but unfortunately it doesn't seem to work. When running as a service, I can see from the logs that display-switch does detect the USB changes, but it logs this with regards to displays:

[ERROR] Did not detect any DDC-compatible displays

I tried even running the service as LocalSystem, and also tried allowing it to interact with the desktop, but get the same result, whether logged in already or not.

The problem could be that by default windows services are not allowed to access the desktop. You need to enable that explicitly in the service control panel. Maybe some API calls fail because of that. You could try it out. Not sure if this is the solution