2015-01-20 13 views
0

Active Directory의 사용자 개체에 대한 다양한 속성에 액세스하고 있습니다. 나는 아래에 내가 쓴 방법을 가지고있다.UserPrincipal AccountLockoutTime always null

항상 null로 돌아 오는 AccountLockoutTime을 제외한 모든 속성에서 작동하는 It.

public IEnumerable<ActiveDirectoryAccount> GetUserAccounts(string samAccountName) 
{ 
    PrincipalContext pricipalContext = new PrincipalContext(ContextType.Domain, "domainname.co.za:3268"); 
    UserPrincipal userPrincipal = new UserPrincipal(pricipalContext); 

    userPrincipal.SamAccountName = "*" + samAccountName + "*"; 

    PrincipalSearcher principalSearcher = new PrincipalSearcher(userPrincipal); 

    ICollection<ActiveDirectoryAccount> result = new List<ActiveDirectoryAccount>(); 

    foreach (UserPrincipal userSearchResult in principalSearcher.FindAll()) 
    { 
     ActiveDirectoryAccount account = new ActiveDirectoryAccount() 
     { 
      AccountLockedOut = userSearchResult.IsAccountLockedOut(), 
      DistinguishedName = userSearchResult.DistinguishedName, 
      Description = userSearchResult.Description, 
      Enabled = userSearchResult.Enabled, 
      GUID = userSearchResult.Guid, 
      LastLogon = userSearchResult.LastLogon, 
      LastPasswordSet = userSearchResult.LastPasswordSet, 
      // The below line always comes back as null 
      LockoutTime = userSearchResult.AccountLockoutTime, 
      PasswordNeverExpires = userSearchResult.PasswordNeverExpires, 
      SAMAccountName = userSearchResult.SamAccountName, 
      SmartcardLogonRequired = userSearchResult.SmartcardLogonRequired, 
      UserCannotChangePassword = userSearchResult.UserCannotChangePassword, 
      UserPrincipalName = userSearchResult.UserPrincipalName 
     }; 

     if (userSearchResult.GetUnderlyingObjectType() == typeof(DirectoryEntry)) 
     { 
      using (DirectoryEntry entry = (DirectoryEntry)userSearchResult.GetUnderlyingObject()) 
      { 
       account.WhenChanged = (DateTime)entry.Properties["whenChanged"].Value; 
       account.WhenCreated = (DateTime)entry.Properties["whenCreated"].Value; 

       // Tried the below to get the data as well but no luck. 
       if (userSearchResult.IsAccountLockedOut()) 
       { 
        if (entry.Properties["lockoutTime"].Value != null) 
        { 
         account.Test = (string)entry.Properties["lockoutTime"].Value; 
        } 
       } 
      } 
     } 

     result.Add(account); 
    } 

    principalSearcher.Dispose(); 
    return result.ToList(); 
} 

위의 코드가 IsAccountLockedOut을 읽을 수 있는지 확인하기 위해 계정을 잠갔습니다. 그것은 사실을 반환 할 수 있습니다. userSearchResult.AccountLockoutTime 또는 (string) entry.Properties [ "lockoutTime"]에 대해 항상 null을 반환합니다. 값;

Active Directory에서 lockoutTime 속성을 확인했으며 계정을 잠그면 사용자 계정에 대한 채워집니다.

어떤 아이디어가 잘못 되었나요?

미리 감사드립니다. entry.Properties["lockoutTime"].Value을 통해 얻은 경우 :

크리스

답변

0

는에서 lockoutTime 속성은 IADsLargeInteger 인터페이스를 지원하는 COM 개체입니다.

당신은 그 값을 얻기 위해 여기에 코드를 사용할 수 있습니다 :

[ 
ComImport, 
InterfaceType(ComInterfaceType.InterfaceIsIDispatch), 
Guid("9068270B-0939-11D1-8BE1-00C04FD8D503") 
] 
public interface IADsLargeInteger 
{ 
    int HighPart{get;set;} 
    int LowPart{get;set;} 
} 

private DateTime? GetLockoutTime(DirectoryEntry de) 
{ 
    DateTime? ret = null; 

    IADsLargeInteger largeInt = de.Properties["lockoutTime"].Value as IADsLargeInteger; 
    if (largeInt != null) 
    { 
     long ticks = (long)largeInt.HighPart << 32 | largeInt.LowPart; 

     // 0 means not lockout 
     if (ticks != 0) 
     { 
      ret = DateTime.FromFileTimeUtc(ticks.Value); 
     } 
    } 

    return ret; 
} 

는에서 lockoutTime의 값이 계정이 잠겨 된 시간이 있습니다,하지만 시간 "까지 잠겨"없습니다.