Windows フォームで VB から C# にコードを適応させようとしています。私はまだ、一般的な DFS のアイデアと、それを Windows フォームから操作する方法を理解しようとしています。
VB はこのGetObject("LDAP://RootDSE")
関数を使用して、DirectorySearcher
. 同じオブジェクトを使用してユーザー 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 の (変更された) コードは次のとおりです。
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
のソースを調べてみましたがUserPrincipal
、オブジェクトを拡張してディレクトリなどを取得する方法がわかりませんでした。GroupPrincipal
ComputerPrincipal
Principal