如何判断当前线程是否正在模拟? [英] How to tell if current thread is impersonating?

查看:156
本文介绍了如何判断当前线程是否正在模拟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个c ++应用程序,其中线程可以模拟使用LogonUser / ImpersonateLoggedOnUser,然后使用RevertToSelf恢复模拟。我碰到了错误,导致线程模仿这种方式两次。我想通过测试当前线程是否已经是模拟,并抛出异常,如果它是防止这种情况。有没有办法判断当前线程是否已经模拟?

I have a c++ application in which threads could impersonate using LogonUser/ImpersonateLoggedOnUser, and then revert impersonation using RevertToSelf. I ran across the bug which caused thread to impersonate this way twice. I want to prevent this by testing if current thread is already impersonating and throw exception if it is. Is there a way to tell if current thread is impersonating already?

推荐答案

可以使用OpenThreadToken。如果一个线程有一个令牌,那么它是模拟;如果没有令牌,那么它不是模拟。

You can use OpenThreadToken. If a thread has a token then it is impersonating; if it doesn't have a token then it is not impersonating.

这篇关于如何判断当前线程是否正在模拟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆