Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            User n = new User();
            Console.WriteLine("Would you like to query the current domain? Y or N");
            string a = Console.ReadLine();
            if (a=="Y" || a=="y")
            {
            n.username= Environment.UserName;
            Console.WriteLine("What is your password?");
            n.password = Console.ReadLine();
            n.domain = Environment.UserDomainName.ToString().ToLower();
            Console.WriteLine(n.domain);
            Console.WriteLine("Please enter username to query: ");
            n.name = Console.ReadLine();
            try
            {
                n.ConnectionStatus();
                Console.ReadKey();
            }
                catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            }
            else {
                    runtime r = new runtime();
                    r.Start();
            }
        }
Ejemplo n.º 2
0
        public void ConnectionStatus()
        {
            try
            {

                DirectoryEntry entry = createDirectoryEntry(username, password);
            DirectorySearcher srch = new DirectorySearcher(entry);
            srch.Filter = "(sAMAccountName=" + name + ")";
            string[] requiredProperties = new string[] {"sAMAccountName", "displayname", "userPassword", "accountExpires", "memberOf", "canonicalName", "ou", "distinguishedName", "groupMembershipSAM" };

                foreach (string property in requiredProperties)
                        srch.PropertiesToLoad.Add(property);
                SearchResult result = srch.FindOne();

            if (result != null)
            {
                Console.WriteLine("==========================");
                Console.WriteLine("AD User information");
                Console.WriteLine("===========================");

                foreach (string property in requiredProperties)
                    foreach (object myCollection in result.Properties[property])
                    Console.WriteLine(string.Format("{0,-20} : {1}",
                        property, myCollection.ToString()));

                PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

                UserPrincipal lanID = UserPrincipal.FindByIdentity(ctx, "sAMAccountName");
                //if (lanID.IsAccountLockedOut()==false)
                //{
                //    Console.WriteLine("Account Active : Yes");
                //}
                //else
                //{
                //    Console.WriteLine("Account Active : No");
                //}
            }
             else
            {
               // user does not exist
               Console.WriteLine("User not found! Please enter another username:"******"Exception caught:\n\n" + e.ToString());
            runtime r = new runtime();
            r.Start();
             }
        }