Launching a gui app from a windows service (Session 0) is usually a dead end — the app just vanishes, blocked by the os. Here’s what i actually did to make it work:
is_running_in_session_zero()
which checks if the current process is running in Session 0.launch_process_in_user_session()
function. This grabs the active user’s session id with WTSGetActiveConsoleSessionId
, then gets the user token using WTSQueryUserToken
.DuplicateTokenEx
) to get a primary token, then build the user’s environment with CreateEnvironmentBlock
.CreateProcessAsUserW
to actually launch the target app in the user’s session — so the window pops up for them and not just in the service context.HandleGuard
.is_running_in_session_zero()
returns false, or any of this fails, the code fall back to the regular CreateProcessW
approach.TL;DR: Even if this code runs as a background service, whatever I spawn actually shows up for the user — no more ghost apps lost in Session 0.
/claim #231
six
@maincharacterenergy
screenpi.pe
@mediar-ai