admin管理员组文章数量:1794759
判断是否是Guest用户
In Win32, call GetTokenInformation, passing a token handle and the TokenUser constant. It will fill in aTOKEN_USER structure for you. One of the elements in there is the user's SID. It's a BLOB (binary), but you can turn it into a string by using ConvertSidToStringSid.
To get hold of the current token handle, use OpenThreadToken or OpenProcessToken.
If you prefer ATL, it has the CAccessToken class, which has all sorts of interesting things in it.
.NET has the Thread.CurrentPrinciple property, which returns an IPrincipal reference. You can get the SID:
代码语言:javascript代码运行次数:0运行复制IPrincipal principal = Thread.CurrentPrincipal;
WindowsIdentity identity = principal.Identity as WindowsIdentity;
if (identity != null)
Console.WriteLine(identity.User);
Also in .NET, you can use WindowsIdentity.GetCurrent(), which returns the current user ID:
代码语言:javascript代码运行次数:0运行复制WindowsIdentity identity = WindowsIdentity.GetCurrent();
if (identity != null)
Console.WriteLine(identity.User);
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2024-10-11,如有侵权请联系 cloudcommunity@tencent 删除itthreadtokenconsoleidentity本文标签: 判断是否是Guest用户
版权声明:本文标题:判断是否是Guest用户 内容由林淑君副主任自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.xiehuijuan.com/baike/1754905454a1708018.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论