feat: fixed open_application to work in session 0 #234
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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 withWTSGetActiveConsoleSessionId
, then gets the user token usingWTSQueryUserToken
.DuplicateTokenEx
) to get a primary token, then build the user’s environment withCreateEnvironmentBlock
.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 regularCreateProcessW
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