Active Directory에서 컴퓨터를 수집하고이를 List<>
으로 반환하는 디렉터리 서비스 방법이 있습니다.C# 디렉터리 서비스 목록에 두 번 추가
코드는 다음과 같습니다 어떤 이유
public static List<string> PCsAndAttributes(string PCName, string AttributeToRead)
{
List<string> toReturn = new List<string>();
try
{
string LdapPath = "LDAP://corp.company.com";
DirectoryEntry computer = new DirectoryEntry(LdapPath);
DirectorySearcher search = new DirectorySearcher(PCName);
string searchAtt = "Name";
search.Filter = "(" + searchAtt + "=" + PCName + ")";
search.PropertiesToLoad.Add(AttributeToRead);
SearchResultCollection results = search.FindAll();
foreach (SearchResult result in results)
{
ResultPropertyCollection PCS = result.Properties;
if (!(toReturn.Contains(Convert.ToString(PCS))))
{
toReturn.Add(Convert.ToString(PCS[AttributeToRead][0]));
}
}
return toReturn;
}
catch (Exception err)
{
toReturn.Add(err.Message);
return toReturn;
}
}
이 내 트 리뷰에있는 모든 컴퓨터의 두 만드는 것입니다. 99 % 오류가이 단계에 있다고 확신하지만 중복을 제거 할 수 없습니다. 여기
는 트 리뷰 노드 코드 :private void UpdateLists()
{
List<string> AdFinds = ProfileCleaner.smallClasses.AdClasses.PCsAndAttributes(txtComputers.Text, "Name");
lblCount.Text = "PC Count: " + AdFinds.Count();
foreach (string PC in AdFinds)
{
string online = ProfileCleaner.smallClasses.PingIt.Pingit(PC);
if (online == "Success")
{
TreeNode pNode = treePCs.Nodes.Add(PC);
pNode.Checked = true;
string OS = ProfileCleaner.smallClasses.OsVersion.GetOsVersion.OSVersion(PC);
string SubPath = null;
if (OS == "6")
{
SubPath = @"\C$\Users\";
}
else
{
SubPath = @"\C$\Documents and Settings\";
}
try
{
string[] usrs = Directory.GetDirectories(@"\\" + PC + SubPath);
foreach (string usr in usrs)
{
List<string> noAdds = new List<string>();
noAdds.Add("admin"); noAdds.Add("Administrator");
string[] lName = usr.Split('\\');
string user = Convert.ToString(lName[lName.Length - 1]);
if (!(noAdds.Contains(user)))
{
pNode.Nodes.Add(usr);
}
}
}
catch (Exception folderErr)
{
}
}
}
}
내가 Active Directory에서 모든 기계의 두 무엇입니까 왜 누군가가 말해 줄래? 를 중지하지 않는다
if (!(myList.contains(NewMachine)) { }
:
I 캡처하고, 아마 그 내 논리를 제거하지만, 같은 일을 시도하기 위해 노력했다.
귀하의 게시물을 읽 자마자 "Duh"순간이었습니다. 그래서, 고마워. –
도움이 될만한 문제가 없습니다. –