Check Windows Identity - CSharp System

CSharp examples for System:Windows

Description

Check Windows Identity

Demo Code


using System;// www  . ja  v a2s .c  om
using System.Security.Principal;

class MainClass
    {
        public static void Main (string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Please provide groups to check as command line arguments");
            }

            WindowsIdentity identity = WindowsIdentity.GetCurrent();

            WindowsPrincipal principal = new WindowsPrincipal(identity);

            foreach (string role in args)
            {
                Console.WriteLine("Is {0} a member of {1}? = {2}", identity.Name, role, principal.IsInRole(role));
            }
        }
    }

Result


Related Tutorials