次の方法で共有


Find the User Account

Search for the user account in the directory to make sure that it exists before performing any other operations. The FindByIdentity overload method on the user principal object locates the user object.

        internal static bool FindTheUser(string user)
        {
            // Creating the PrincipalContext
            PrincipalContext principalContext = null;
            try
            {
                principalContext = new PrincipalContext(ContextType.Domain, "fabrikam", "DC=fabrikam,DC=com");
            }
            catch (Exception e)
            {
                MessageBox.Show("Failed to create PrincipalContext. Exception: " + e);
                Application.Exit();
            }

            //Retrieving the user
            UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(principalContext, user);
            if (userPrincipal != null)
                return true;
            else
                return false;

        }

See Also

Reference

System.DirectoryServices.AccountManagement

Concepts

About System.DirectoryServices.AccountManagement
Using System.DirectoryServices.AccountManagement

Send comments about this topic to Microsoft.

Copyright © 2008 by Microsoft Corporation. All rights reserved.