Reputation: 823
Is it possible to determine if a given SID is User or Group using .NET? I have a list of SIDs which I need to edit in a listview, so for User and Group I want to use different icons
Upvotes: 2
Views: 3690
Reputation: 873
LookupAccountSid() function returns SID_NAME_USE value that indicates the type of the account.
Upvotes: 0
Reputation: 10386
You can try it by using 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;
You can find similar question (and answer) here: How to get the groups of a user in Active Directory? (c#, asp.net)
Upvotes: 1