【发布时间】:2013-04-02 19:51:42
【问题描述】:
我正在尝试以 Windows 形式将代码从 VB 改编为 C#。我仍在尝试总体上了解 DFS 的想法,以及如何从 Windows 窗体中操作它。
VB 使用GetObject("LDAP://RootDSE") 函数在Active Directory 中搜索使用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 对象以获取目录或其他内容。
【问题讨论】:
标签: c# winforms active-directory microsoft-distributed-file-system