前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >判断是否是Guest用户

判断是否是Guest用户

作者头像
井九
发布2024-10-12 08:14:08
810
发布2024-10-12 08:14:08
举报
文章被收录于专栏:四楼没电梯

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
复制
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
复制
WindowsIdentity identity = WindowsIdentity.GetCurrent();
if (identity != null)
    Console.WriteLine(identity.User);
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-10-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档