S
Scott
I need to be able to verify group membership in my C#
application. All the examples I seem to find show how to
query the BUILTIN groups. I need to be able to query the
DOMAIN groups. Can I have code examples on how to
accomplish this. I tried the following code (in a test
Console Application) and all it returns
is "DOMAIN\MYUSERNAME belongs to: " and then nothing.
Any help would be appreciated. Thank you.
public static void DemonstrateWindowsBuildInRoleEnum()
{
AppDomain myDomain = Thread.GetDomain();
myDomain.SetPrincipalPolicy
(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal myPrincipal = (WindowsPrincipal)
Thread.CurrentPrincipal;
Console.WriteLine("{0} belongs to: ",
myPrincipal.Identity.Name.ToString());
Array wbirFields = Enum.GetValues(typeof
(WindowsBuiltInRole));
foreach (object roleName in wbirFields)
{
try
{
Console.WriteLine("{0}? {1}.", roleName,
myPrincipal.IsInRole((WindowsBuiltInRole)roleName));
}
catch
{
Console.WriteLine("{0}: Could not obtian role for this
RID.", roleName);
}
finally
{
Console.WriteLine("{0}? {1}. (finally) ", roleName,
myPrincipal.IsInRole((WindowsBuiltInRole)roleName));
}
}
}
application. All the examples I seem to find show how to
query the BUILTIN groups. I need to be able to query the
DOMAIN groups. Can I have code examples on how to
accomplish this. I tried the following code (in a test
Console Application) and all it returns
is "DOMAIN\MYUSERNAME belongs to: " and then nothing.
Any help would be appreciated. Thank you.
public static void DemonstrateWindowsBuildInRoleEnum()
{
AppDomain myDomain = Thread.GetDomain();
myDomain.SetPrincipalPolicy
(PrincipalPolicy.WindowsPrincipal);
WindowsPrincipal myPrincipal = (WindowsPrincipal)
Thread.CurrentPrincipal;
Console.WriteLine("{0} belongs to: ",
myPrincipal.Identity.Name.ToString());
Array wbirFields = Enum.GetValues(typeof
(WindowsBuiltInRole));
foreach (object roleName in wbirFields)
{
try
{
Console.WriteLine("{0}? {1}.", roleName,
myPrincipal.IsInRole((WindowsBuiltInRole)roleName));
}
catch
{
Console.WriteLine("{0}: Could not obtian role for this
RID.", roleName);
}
finally
{
Console.WriteLine("{0}? {1}. (finally) ", roleName,
myPrincipal.IsInRole((WindowsBuiltInRole)roleName));
}
}
}