Check Windows Identity - CSharp Operating System

CSharp examples for Operating System:Windows

Description

Check Windows Identity

Demo Code


using System;/*from   w  ww . j  a  v  a 2 s  . c o  m*/
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