Making apps pop up for the user by bypassing Session 0

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:

  • Was created the function is_running_in_session_zero() which checks if the current process is running in Session 0.
  • If that returns true, I call launch_process_in_user_session() function. This grabs the active user’s session id with WTSGetActiveConsoleSessionId, then gets the user token using WTSQueryUserToken.
  • Then that token is duplicated (DuplicateTokenEx) to get a primary token, then build the user’s environment with CreateEnvironmentBlock.
  • Using all that, one call for 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.
  • All the handle cleanup and error handling is done with helpers like HandleGuard.
  • If 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

Claim

Total prize pool $100
Total paid $0
Status Pending
Submitted July 25, 2025
Last updated July 25, 2025

Contributors

SI

six

@maincharacterenergy

100%

Sponsors

SC

screenpi.pe

@mediar-ai

$100