pGina.Plugin.LocalMachine.LocalAccount.GetUserDirectoryEntry C# (CSharp) Method

GetUserDirectoryEntry() public static method

public static GetUserDirectoryEntry ( string username ) : System.DirectoryServices.DirectoryEntry
username string
return System.DirectoryServices.DirectoryEntry
        public static DirectoryEntry GetUserDirectoryEntry(string username)
        {
            return m_sam.Children.Find(username, "User");
        }

Usage Example

コード例 #1
0
 /// <summary>
 /// This is a faster technique for determining whether or not a user exists on the local
 /// machine.  UserPrincipal.FindByIdentity tends to be quite slow in general, so if
 /// you only need to know whether or not the account exists, this method is much
 /// faster.
 /// </summary>
 /// <param name="strUserName">The user name</param>
 /// <returns>Whether or not the account with the given user name exists on the system</returns>
 public static bool UserExists(string strUserName)
 {
     try
     {
         using (DirectoryEntry userEntry = LocalAccount.GetUserDirectoryEntry(strUserName))
         {
             return(userEntry != null);
         }
     }
     catch (Exception)
     {
         return(false);
     }
 }