.netwinapiwindows-servicespinvokesessionid

Change running process session ID and lpDesktop?


After building a service that launches an interactive processes in a user's session via CreateProcessAsUser and lpDesktop specified in STARTUPINFO -- is it possible to change the session that a process is executing in on the fly?

So if we have notepad running in Session 1 and another user logged onto the same machine in Session 2, can we change Notepad's SessionId from 1 to 2? I understand the well-followed and sane way to accomplish this is to just start notepad in Session 2, but can we use API calls to make it happen?

By the way I'm writing in C# but am entirely comfortable using pInvoke or low level languages.


Solution

  • It is not possible to move a running process from one session to another.