WindowsIdentity.Groups
WindowsIdentity.Groups can be used to display the list of groups that an account belongs to. The following code enumerates the group list and displays both the group name and SID.
WindowsIdentity wi = WindowsIdentity.GetCurrent();
foreach (IdentityReference id in wi.Groups)
{
Console.WriteLine(@" {0}, {1}",
((NTAccount)((SecurityIdentifier)id).Translate(typeof(NTAccount))).Value,
id.Value);
}
However, this property is buggy. So be cautious to use it. I found strange (wrong) behaves.
- If you list the groups that Network Service or Local Service belongs to, you get two Users groups with the same SID.
- If you create a local normal user named tmpUser and then remove it from the Users group, then you log out and relog in your system, and then launch your app under the tmpUser account to display the list of groups that it belongs to. You'll find that the Users group still shows up in the list!
5 Comments:
Good day! Would you mind if I share your blog with my twitter group?
There's a lot of people that I think would really appreciate your content. Please let me know. Thank you
My blog post ... http://topvakantiehuizenfrankrijk.wordpress.com
Spot on with this write-up, I really believe that this amazing site needs far more attention.
I'll probably be returning to read more, thanks for the advice!
Also visit my website ... vakantiehuisjes frankrijk
Very nice post. I just stumbled upon your blog and wanted to say that I have
really enjoyed browsing your blog posts. In any case I will be subscribing to your rss feed and I
hope you write again very soon!
my webpage - francesca battistelli this is the stuff
If you are going for finest contents like me, only pay a visit this site
every day since it presents quality contents, thanks
My blog post ... luxe vakantiehuizen [wordpress.com]
electronic cigarette starter kit, smokeless cigarettes, ecigarette, e cigarette, electronic cigarette, electronic cigarette
Post a Comment
<< Home