OpenThreadToken returns an access token for the specific thread.

OpenThreadToken will fail with ERROR_NO_TOKEN if the thread is not impersonated. If you want to get the thread token regardless if the thread is impersonated or not, you should catch this error, and fall back to OpenProcessToken to get the process token.