c++windowswinapiprocesssession-0-isolation

How to check if a Windows executable is running in a Session 0 process?


I am running into http://msdn.microsoft.com/en-us/library/windows/desktop/hh404562(v=vs.85).aspx#use_direct3d_in_session_0_processes.

I use a few of the processes documented, and I am running into HRESULT values that suggest my executable is, in fact, running under Session 0.

How can I programmatically deduce if I am running under Session 0? I would rather gracefully exit than drop out with a mysterious error code.


Solution

  • GetCurrentProcessId and ProcessIdToSessionId are your friends.