Demonstrates determining group identity

/*
Mastering Visual C# .NET
by Jason Price, Mike Gunderloy
Publisher: Sybex;
ISBN: 0782129110
*/
/*
Example19_7.cs demonstrates determining group identity
*/
using System;
using System.Security.Principal;
public class Example19_6a
{
public static void Main()
{
// get the current identity
WindowsIdentity wi = WindowsIdentity.GetCurrent();
// get the associated principal
WindowsPrincipal prin = new WindowsPrincipal(wi);
if (prin.IsInRole(WindowsBuiltInRole.PowerUser))
{
Console.WriteLine("You are a member of the Power User group");
}
else
{
Console.WriteLine("You are not a member of the Power User group");
}
}
}
Related examples in the same category