Click to See Complete Forum and Search --> : Get Users from Domain


thedevkid
June 2nd, 2008, 08:28 AM
Ok...I'm stumped on this one. What Im trying to do is determine if a NT User is apart of a particular User Group.

So my application grabs the logged in user by doing the following...

AppDomain myDomain = Thread.GetDomain();
myDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);

WindowsPrincipal myPrincipal = (WindowsPrincipal)Thread.CurrentPrincipal;
WindowsIdentity myIdentity = WindowsIdentity.GetCurrent();

Works fine...then I figured I could just use the IsInRole function of Windows Principal

if (myPrincipal.IsInRole("MyDomain\\MyGroup"))
{
MessageBox.Show("Is in");
}

However this group that was created "MyGroup" cannot be found...I get success when I change MyGroup to Administrators and such but not when its "MyGroup". I've looped through the groups Im suppose to be apart of and "MyGroup" never comes up...but I know Im apart of it...

string mygroup = "";
foreach (IdentityReference irc in myIdentity.Groups)
{
mygroup = ((NTAccount)irc.Translate(typeof(NTAccount))).Value;
_groups.Add(mygroup);
}

Am I looking in the wrong place? Ofcourse no one that works in NT Services can help me...they are all "Huh, what do you mean"...all I know is that the Domain User is created...its created as a User...I figured it was a User Group of some sort...but Im not sure...

If anyone has ideas just throw them out there...i know its hard with the amount of Info I've given...but Im willing look for a piece of hay in a hay stack at this point.