首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >判断是否是Guest用户

判断是否是Guest用户

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

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 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档