Skip to content

Conversation

maincharacterenergy
Copy link

@maincharacterenergy maincharacterenergy commented Jul 24, 2025

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

@louis030195
Copy link
Contributor

how do i know it works?

@tribhuwan-kumar
Copy link
Contributor

how do i know it works?

recording-2025-07-26-14-23-28.webm

cc: @louis030195

@tribhuwan-kumar
Copy link
Contributor

maybe i'll open a pr tomorrow

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants