sleep-on-lan icon indicating copy to clipboard operation
sleep-on-lan copied to clipboard

Create non-console version, so conhost.exe doesn't also need to run

Open xtcrefugee opened this issue 1 year ago • 3 comments

Thank you for sol, it's working well for my needs. However, being a console app it also spawns a conhost on Windows, even when console output is directed to a file. An additional conhost consumes more memory than both sol and nssm combined, which is rather a shame as in a service configuration we don't need a console anyway.

Would it be possible to compile this as a non-console app as well, so it doesn't generate a conhost?

Many thanks for your work!

xtcrefugee avatar Apr 08 '23 18:04 xtcrefugee

I see your point, but i have no idea how to achieve that.

Do you have any evidence that it's possible / any clue about how to technically speaking achieve this ?

Because as far as i can tell, a windows program either has to be a "form-based" application (with a GUI), either a "console" application (launchable in a standalone way - and here of course with a console, or through a service machanism (here, just as a proposal, with the external tool NSSM).

And have you tried this, by the way, per the NSSM documentation ? (@see https://nssm.cc/usage)

Console window
As of version 2.22, nssm will by default create a new console window for the application. This allows some programs to work which would otherwise fail, such as those which expect to be able to read user input. The console window can be disabled if it is not needed by setting the integer (REG_DWORD) value AppNoConsole under HKLM\System\CurrentControlSet\Services\servicename\Parameters to a non-zero value.

Otherwise for reference, i have not found a lot of informations about that topic in golang :

  • this is about hiding the console (but it will still be visible inside TaskManager with a conhost.exe extra line, i would say) : https://github.com/ifrstr/hideconsole/blob/master/hideconsole_win.go
  • there is a "DETACHED_PROCESS" pure-indows property, used for example here, but not clear if this would work : https://github.com/tinygo-org/tinygo/blob/release/util_windows.go
  • there are huge golang frameworks like "https://github.com/judwhite/go-svc" (allowing to have the binaries themselves being able to register as a windows service), but a) i don't know if that would work anyway (about not having a "conhost.exe" associated process) and b) i really don't like this approach, which is not at all going in the good direction (wrapping as a service should be done around the processes ("unix philosophy"), and not with a lot of code inside the processes themselves)

SR-G avatar Apr 09 '23 11:04 SR-G

Sorry, I have no experience with Go so I don't know if it's possible within that framework.

The closest thing I can think of, with an app that stays resident but has no console window, would be something like a compiled AutoHotkey script. Those have a system tray icon to (minimally) just exit the program. I don't know if that's something you'd consider replicating here or not.

Unfortunately I'd already tried setting NSSM to not have a console window (it's also a checkbox in NSSM's interactive UI) but sol still spawns one. I also tried redirecting stdin and stdout to <NUL and >NUL respectively, but the console process still starts.

xtcrefugee avatar Apr 09 '23 14:04 xtcrefugee

Adding -ldflags -H=windowsgui to go build command produces a GUI executable and Windows stops allocating console automatically. I tested with NSSM and sol is working without spawning conhost

skrimix avatar May 20 '23 12:05 skrimix