WTSQueryUserToken always throws “An attempt was made to reference a token that does not exist” on Windows 7 in C#

最后都变了- 提交于 2019-12-05 16:20:00

You must add SetLastError = true to the DllImport attribute for WTSQueryUserToken otherwise, GetLastWin32Error is not meaningful.

Also, you must be running this code in the context of the LocalSystem account as stipulated in the documentation (not just "an admin user"):

Obtains the primary access token of the logged-on user specified by the session ID. To call this function successfully, the calling application must be running within the context of the LocalSystem account and have the SE_TCB_NAME privilege.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!