Hi Son,
I believe you mean User Group or User Role. All that stuff is in System.Security .Principal
You can get a WindowsIdentity from the user running the code with
WindowsIdentity wi = WindowsIdentity .GetCurrent();
Then you can get all roles for that identity by using Type.InvokeMemb er, cleverly demonstrated by Joe Kaplan and translated to C# by Chris Taylor
http://dotnetjunkies.com/WebLog/chri...2/25/7945.aspx
public static string[] GetWindowsIdent ityRoles( WindowsIdentity identity )
{
object result = typeof(WindowsI dentity).Invoke Member( "_GetRoles" ,
BindingFlags.St atic | BindingFlags.In vokeMethod | BindingFlags.No nPublic,
null, identity, new object[]{identity.Token }, null );
return (string[])result;
}
You can also test if a user is a member of a specific role like BUILTIN\Adminis trators
WindowsPrincipa l wp = new WindowsPrincipa l(wi); // wi = WindowsIdentity .GetCurrent()
if(wp.IsInRole( "BUILTIN\\Admin istrators"))
// someone with administrator rights
--
Happy coding!
Morten Wennevik [C# MVP]