먼저 올바른 용어를 사용하지 않으면 용서해주세요. 잘못된 용어를 사용하는 곳이면 어디든지 수정하십시오.여러 도메인 서버에서 사용자의 lastLogon 속성 검색
목적은 프로그래밍 방식으로 주어진 사용자 이름의 lastLogon
날짜를 검색하는 것입니다.
우리는 내가 숲이라고 믿는 것을 가지고 있습니다. - adserver01.aa.mycompany.com
과 adserver02.aa.mycompany.com
과 같은 두 개의 AD 서버 Microsoft의 ADExplorer를 사용하여 개체를 검사하는 제 3의 컴퓨터에서이 서버에 연결되었습니다. lastLogon 날짜가 adserver01
인 사용자가 있지만 adserver02
은 볼 수 없습니다. 예를 들어, lastLogon의 값은 adserver02
에서 0x0이며 일부 사용자의 경우 유효한 날짜 인 adserver01
입니다.
Windows Forms 응용 프로그램까지 개발 한 코드는 하나의 AD 서버 만 있으면 잘 작동합니다. lastLogon 날짜 속성에 대해 두 서버를 모두 확인하고 사용 가능한 경우 0이 아닌 값을 반환하려면 어떻게합니까?
private static string GetLastActivityDate(string UserName)
{
string domainAndUserName = String.Format(@"LDAP://aa.mycompany.com/CN={0},OU=CLIENT_PROD,OU=clients.mycompany.com,DC=aa,DC=mycompany,DC=com", UserName);
string OUAdminUserName = "abc";
string OUAdminPassword = "xyz";
AuthenticationTypes at = AuthenticationTypes.Secure;
DateTime lastActivityDate;
string returnvalue;
long lastLogonDateAsLong;
using (DirectoryEntry entryUser = new DirectoryEntry(domainAndUserName, OUAdminUserName, OUAdminPassword, at))
using (DirectorySearcher mysearcher = new DirectorySearcher(entryUser))
try
{
using (SearchResultCollection results = mysearcher.FindAll())
{
if (results.Count >= 1)
{
DirectoryEntry de = results[0].GetDirectoryEntry();
lastLogonDateAsLong = GetInt64(de, "lastLogon");
try
{
if (lastLogonDateAsLong != -1)
{
lastActivityDate = DateTime.FromFileTime(lastLogonDateAsLong);
returnvalue = lastActivityDate.ToString();
}
else
{
returnvalue = "-Not available-";
}
}
catch (System.ArgumentOutOfRangeException aore)
{
returnvalue = "Not available";
}
}
else
{
returnvalue = string.Empty;
}
}
}
catch (System.DirectoryServices.DirectoryServicesCOMException dsce)
{
returnvalue = "- Not available -";
}
return returnvalue;
}
감사합니다.
편집이 :
private static Int64 GetInt64(DirectoryEntry entry, string attr)
{
DirectorySearcher ds = new DirectorySearcher(
entry,
String.Format("({0}=*)", attr),
new string[] { attr },
SearchScope.Base
);
SearchResult sr = ds.FindOne();
if (sr != null)
{
if (sr.Properties.Contains(attr))
{
return (Int64)sr.Properties[attr][0];
}
}
return -1;
}
가 언급하는 것을 잊었다는 AD 스키마, 구조 등, 두 서버에 정확히 비슷하게 보인다.
는 도메인이나 URL에서 구문 분석 당신이 중 하나 .config 파일에서 읽거나 그이 전달 될 수있는 변수 /를 사용하여 하드 코딩 LDAP 연결 고통을 교체 ... 또는 기본적으로이 ..then 하나 잘 작동하는 경우 목록을 입력하고 해당 목록 개체를 매개 변수로 메서드에 전달하고 for 루프 내에서 매개 변수 –
MethodMan