VB에서 C#으로 코드를 Windows 양식으로 변환하려고합니다. 나는 여전히 DFS 아이디어를 다루기 위해 노력하고 있으며 Windows 폼에서 DFS 아이디어를 조작하는 방법을 알고있다.PrincipalSearcher를 사용하여 DFS 공유 얻기
VB는 GetObject("LDAP://RootDSE")
함수를 사용하여 DirectorySearcher
을 사용하여 공유에 대해 Active Directory를 검색합니다. 동일한 객체를 사용하는 다른 함수를 사용자 ID에서 UserPrincipal
을 반환하고 그룹이 이미 존재하는지 확인하는 것 (GroupPrincipal
사용)을 적용했습니다.
public static UserPrincipal GetUserPrincipal(string userId) {
PrincipalContext context = new PrincipalContext(ContextType.Domain);
UserPrincipal user = new UserPrincipal(context);
user.Name = userId;
PrincipalSearcher searcher = new PrincipalSearcher(user);
return searcher.FindOne() as UserPrincipal;
}
그러나, 나는 내가 사용하고있는 키워드를 가진 모든 문서를 찾을 수 없습니다,하지만 난 DFS 네임 스페이스 (내가 생각하는)있는 디렉토리의 목록을 얻기 위해 노력하고 있어요 : 다음은 일반적으로 다음과 같이 이동합니다. 여기
는 VB에서 (수정) 코드 : 나는UserPrincipal
,
GroupPrincipal
및
ComputerPrincipal
의 소스로보고 시도하지만 확장 할 것입니다 방법을 알아낼 수 없었던
Public Function GetDfsNamespaces() As List(Of String)
Dim objRootDSE = GetObject("LDAP://RootDSE")
Dim domain As String = objRootDSE.Get("DefaultNamingContext")
Dim entry As New DirectoryEntry("LDAP://CN=DFs-Configuration,CN=System," & domain)
Dim searcher As New DirectorySearcher(entry)
searcher.PropertiesToLoad.Add("cn")
searcher.Filter = "(objectClass=msDFS-NamespaceAnchor)"
searcher.SearchScope = SearchScope.Subtree
Dim results As SearchResultCollection = searcher.FindAll()
Dim strResults As New List(Of String)
For Each result In results
strResults.Add(result.Properties("cn")(0))
Next
return strResults
End Function
Principal
디렉토리 등을 얻기위한 객체.
와우, 쉬웠다. PrincipalSearcher에 대한 정보를 읽은 적이 있습니다. 더 빠르니까요. .NET 3.5에는 새로운 객체를 사용하는 방법이 있다고 생각합니까? – tedski
이들은 실제로 일반적으로 느립니다. DirectoryEntry/DirectorySearcher를 사용하십시오. –