2

是否可以使用 .NET 确定给定的 SID 是用户还是组?我有一个需要在列表视图中编辑的 SID 列表,因此对于用户和组,我想使用不同的图标

4

2 回答 2

1

您可以使用 System.DirectoryServices.AccountManagement 进行尝试:

//Get NTAccount, to find out username and domen
NTAccount nt = (NTAccount)sid.Translate(typeof(NTAccount));
string[] fullName = nt.Value.Split(new char[] { '\\' });

//then get group principle
PrincipalContext ctx = new PrincipalContext(ContextType.Domain, fullName[0]);
GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.Name, fullName[1]);

//and check whenever this group exists
bool SidIsAGroup = grp != null;

您可以在此处找到类似的问题(和答案):如何在 Active Directory 中获取用户组?(c#, asp.net)

于 2012-06-26T08:36:41.843 回答
0

LookupAccountSid() 函数返回指示帐户类型的 SID_NAME_USE 值。

于 2013-06-25T12:04:41.487 回答