gerardog / gsudo

Sudo for Windows
https://gerardog.github.io/gsudo
MIT License
5.07k stars 136 forks source link

Issue: Running gsudo from a desktop shortcut flashes a console window quickly #327

Open eebssk1 opened 6 months ago

eebssk1 commented 6 months ago

Description

I'm using gsudo prepended on a shortcut to start a GUI program as admin.(gsudo cache auto spawned via taskscheduler) Everytime I open the shotcut it flashes a cmd windows quickly and then start the target application. This is a bit annoying to me.

Proposed technical details

I found a workaround, by prepending "conhost.exe --headless" which precreate a invisible console that gsudo will take over. It's better if there is something like gsudow which supports this natively.

eebssk1 commented 6 months ago

Also There's a weired API behavior of OBS started by gsudo(normal or cache). The monitor capturing api failed with 0x8007006(HANDLE_INVLAID) error although it has admin rights. And I found the fix is set "Run as admin for this user" on the obs64.exe and it works normally after started by gsudo. Pretty weired hmmm.

gerardog commented 6 months ago

Hi @eebssk1,

Windows spawns the console before actually starting gsudo, hence gsudo.exe can't avoid the console from flashing, besides what is already doing. BTW super nice hack with the conhost.exe --headless prefix!

Another workaround is to set the shortcut to show minimized, which reduces the flashing to just a minimum on to the taskbar: image

The idea of having a different gsudow.exe compiled as a windows app just to solve this particular annoyance, IMO is just going to bring more confusion that benefits. How would a console-less gsudo show errors, outputs, etc? And the problem it solves can be avoided so easily.... So, I am sorry, but I am going to close this one as By Design.

Regarding the OBS issue, that's an interesting one that can get more attention. We can repurpose this issue in that direction if you want instead of creating another one. Do you have a stacktrace or additional debug info, logs, repro steps on obs, etc? Thank you.

eebssk1 commented 6 months ago

Hi @gerardog . Then let's focusing on the OBS one and repurpose the issue.

OBS log is here though there's no much useful infomation > https://catbin.sh/b/c17c3e15

It's rather easy to reproduce. You just start obs with gsudo and then add monitor capture source, then it fails.

There's a pretty weired workaround. You tick the "Run as admin" for this user compatibility flag of obs64.exe and then start with gsudo and it the works without problem.

PS:Looks like only monitor capture api has such problem so maybe some windows internal related.

eebssk1 commented 6 months ago

Hi @gerardog . Then let's focusing on the OBS one and repurpose the issue.

OBS log is here though there's no much useful infomation > https://catbin.sh/b/c17c3e15

It's rather easy to reproduce. You just start obs with gsudo and then add monitor capture source, then it fails.

There's a pretty weired workaround. You tick the "Run as admin" for this user compatibility flag of obs64.exe and then start with gsudo and it the works without problem.

PS:Looks like only monitor capture api has such problem so maybe some windows internal related.

Just found another weired point. The way in workaround always start OBS in minimized.

eebssk1 commented 5 months ago

Hi @gerardog . Then let's focusing on the OBS one and repurpose the issue.

OBS log is here though there's no much useful infomation > https://catbin.sh/b/c17c3e15

It's rather easy to reproduce. You just start obs with gsudo and then add monitor capture source, then it fails.

There's a pretty weired workaround. You tick the "Run as admin" for this user compatibility flag of obs64.exe and then start with gsudo and it the works without problem.

PS:Looks like only monitor capture api has such problem so maybe some windows internal related.

Hmm I reinstalled windows in this lunar new year and then the issue is gone... All possible changes I do is I only prepended 'start ""' before the command..

Kamilkampfwagen-II commented 4 months ago

run-hidden could be used for this. The final command line: run-hidden.exe gsudo.exe mspaint

eebssk1 commented 3 months ago

@gerardog Hi. Thanks for the new release. Also I found the myth here. As long as you start obs detached from gsudo,then there will be no problems. like this C:\Windows\System32\conhost.exe --headless gsudo start "" D:\Portable\OBS\bin\64bit\obs64.exe cmd's start cmdlet without any arguments start process in detached mode ,where process itself becomes the group leader,not a subprocess of gsudo.