public static void DemonstrateWindowsBuiltInRoleEnum ( ) {
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 ( Exception ) {
Console.WriteLine ( "{0}: Could not obtain role for this RID.", roleName );
}
}
}
Public Shared Sub DemonstrateWindowsBuiltInRoleEnum ( )
Dim myDomain As AppDomain = Thread.GetDomain ( )
myDomain.SetPrincipalPolicy ( PrincipalPolicy.WindowsPrincipal )
Dim myPrincipal As WindowsPrincipal = CType ( Thread.CurrentPrincipal, WindowsPrincipal )
Console.WriteLine ( "{0} belongs to: ", myPrincipal.Identity.Name.ToString ( ) )
Dim wbirFields As Array = [ Enum ].GetValues ( GetType ( WindowsBuiltInRole ) )
Dim roleName As Object
For Each roleName In wbirFields
Try
Console.WriteLine ( "{0}? {1}.", roleName, _
myPrincipal.IsInRole ( CType ( roleName, WindowsBuiltInRole ) ) )
Catch
Console.WriteLine ( "{0}: Could not obtain the role for this RID.", roleName )
End Try
Next roleName
End Sub 'DemonstrateWindowsBuiltInRoleEnum |