各位高手我如何才可以遍历出所有的Active Directory域用户

viptiger 2003-03-25 07:10:10
加精
我希望取得Active Directory域中所有的用户名称及工作组名称
希望可以通过我的程序验证他们在该域中的的身份是否是合法的。
各位大侠。我自己用了些方法,包括SQL中的扩展存储过程,但多不能达到预期的效果,各位大侠可不可以给些意见
...全文
206 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
viptiger 2003-03-28
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdirectoryserviceshierarchy.asp

是System.DirectoryServices 的命名空间结构,好好好


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdirectoryservicesdirectorysearcherclasstopic.asp

是DirectorySearcher.Filter串的写法,大家看看喽~~~~~~~~~

在此我感谢各位大侠对我的关心和帮助(*^_^*)
viptiger 2003-03-28
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdirectoryserviceshierarchy.asp

是System.DirectoryServices 的命名空间结构,好好好


http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdirectoryservicesdirectorysearcherclasstopic.asp

是DirectorySearcher.Filter串的写法,大家看看喽~~~~~~~~~

在此我感谢各位大侠对我的关心和帮助(*^_^*)
自由之眼 2003-03-28
  • 打赏
  • 举报
回复
是啊,取出就行了。
viptiger 2003-03-28
  • 打赏
  • 举报
回复
Dim RootDE As DirectoryEntry = New DirectoryEntry("LDAP://Domain Name/DC=cn,DC=Domain Name,DC=com", "UserName", "Pwd") '必须要加入用户身份认证
Dim Searcher As DirectorySearcher = New DirectorySearcher(RootDE)
Dim CollectionResult As SearchResultCollection
Dim i As Integer
CollectionResult = Nothing
Try
Searcher.Filter = "(&(objectClass=User)(mailNickname=*)(cn=用户名))" Searcher.PropertiesToLoad.Add("mailNickname")
Searcher.PropertiesToLoad.Add("ADsPath")
Searcher.PropertiesToLoad.Add("Name")
Searcher.PropertiesToLoad.Add("Mail")


Searcher.Sort.Direction = SortDirection.Ascending
MessageBox.Show(Searcher.FindAll.Count)
CollectionResult = Searcher.FindAll
Dim lop As Integer
For lop = 0 To CollectionResult.Count - 1
MessageBox.Show(CollectionResult.Item(lop).Properties.Count)
TreeView1.Nodes.Add(CollectionResult.Item(lop).Properties("Name").Item(0))
Next

对用户而言一共四个属性("mailNickname")("ADsPath")("Name")("Mail")
viptiger 2003-03-28
  • 打赏
  • 举报
回复
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdirectoryserviceshierarchy.asp
yzyun 2003-03-27
  • 打赏
  • 举报
回复
怎么样??我等着收分呢,呵呵:-)
viptiger 2003-03-27
  • 打赏
  • 举报
回复
各位高手:CollectionResult.Item(i).Properties("Description").Item(0).ToString 的运行是有问题的,各位高人是否指点一二
viptiger 2003-03-26
  • 打赏
  • 举报
回复
我也不想加班呀老大

兄弟们明天见
yzyun 2003-03-26
  • 打赏
  • 举报
回复
希望明天能够听到你的好消息.........
下班了--------------------
viptiger 2003-03-26
  • 打赏
  • 举报
回复
http://chs.gotdotnet.com/quickstart/howto/doc/ADRead.aspx

很好
谢了
viptiger 2003-03-26
  • 打赏
  • 举报
回复
LDAP://redmond/CN=Users,DC=redmond,DC=corp,DC=microsoft,DC=com redmond是域控制器的名字,要改成我的域控制器的名字,DC=redmond,DC=corp,DC=microsoft,DC=com 是域的名字,这个表示我的域为redmond.corp.microsoft.com ,不知道这种写法是不是对的
因为我这样写了,可是还是不能枚举出所有的用户。
yzyun 2003-03-26
  • 打赏
  • 举报
回复
qieyj(温馨港湾) 同学已经写了code了,而且他也放到网上了:
http://chs.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/Services/DirectoryServices/ADRead/ADRead.src

其实你现在就差一个LDAP的路径了.让你看一下CommonSelf也好,但是你看了那个又会要看其他的class(一定的),一直要下去.....,:-) .

就差一个LDAP的路径了,试试自己动手吧,那样会更有成就感.
也可以参考:
http://chs.gotdotnet.com/quickstart/howto/doc/ADRead.aspx
viptiger 2003-03-26
  • 打赏
  • 举报
回复
WINNT:----------------使我用得Path串,应该是All Domain的,可是还是条是不通
可否看一下那个CommonSelf的类
viptiger 2003-03-26
  • 打赏
  • 举报
回复
老大<<<<<:::========---------上面的程序我一直调试不通
yzyun 2003-03-26
  • 打赏
  • 举报
回复
自己写的CommonSelf()
GetSystemData是自己写的函数
获取系统的一些数据和参数,比如RootOU和DomainName
当然,如果你知道而且不介意写死的话,就写死,或者写到一个文件里面去.
viptiger 2003-03-26
  • 打赏
  • 举报
回复
可否告知CommonSelf()从哪里来的,感激不尽
yzyun 2003-03-26
  • 打赏
  • 举报
回复
把AD的信息写到tree:
Imports System.DirectoryServices
Private Sub GetADInfo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim RootPath As String "
Dim dataxtong As New CommonSelf()
RootPath = "LDAP://" + dataxtong.GetSystemData("RootOU") + "," + dataxtong.GetSystemData("DomainName")
Dim RootDE As DirectoryEntry = New DirectoryEntry(RootPath)
Dim Searcher As DirectorySearcher = New DirectorySearcher(RootDE)
Dim CollectionResult As SearchResultCollection
Dim TempNode, TempNode1 As TreeNode
Dim i As Integer
CollectionResult = Nothing
Try
Searcher.Filter = "(&(objectClass=OrganizationalUnit))" '& "(OU=" & Trim(EnterpriseName) & "))"
Searcher.PropertiesToLoad.Add("Description")
Searcher.PropertiesToLoad.Add("ADsPath")
Searcher.PropertiesToLoad.Add("Name")
Searcher.Sort.Direction = SortDirection.Ascending
CollectionResult = Searcher.FindAll()
If CollectionResult.Count <= 1 Then
MsgBox("无组织单位。")
Else
For i = 1 To CollectionResult.Count - 1
If Len(CollectionResult.Item(i).Properties("Description").Item(0).ToString) <> 13 Then
MsgBox("单位:" & CollectionResult.Item(i).Properties("Name").Item(0).ToString & "的编码有误。")
Else
If Mid(Trim(CollectionResult.Item(i).Properties("Description").Item(0).ToString), 11, 3) = "000" Then
TempNode = Me.TreeView1.Nodes.Add(CollectionResult.Item(i).Properties("Name").Item(0).ToString)
TempNode.ImageIndex = 0
TempNode.Tag = CollectionResult.Item(i).Properties("Description").Item(0).ToString & CollectionResult.Item(i).Path
Else
TempNode1 = TempNode.Nodes.Add(CollectionResult.Item(i).Properties("Name").Item(0).ToString)
TempNode1.ImageIndex = 1
TempNode1.Tag = CollectionResult.Item(i).Properties("Description").Item(0).ToString & CollectionResult.Item(i).Path
End If
End If
Next
End If
Catch
MsgBox("查询系统目录出现错误。")
Me.TreeView1.Nodes.Clear()
CollectionResult = Nothing
RootDE.Dispose()
Searcher.Dispose()
RootDE = Nothing
Searcher = Nothing
End Try
End Sub
viptiger 2003-03-26
  • 打赏
  • 举报
回复
各位大侠有没有DirectoryServices类的介绍
qieyj 2003-03-25
  • 打赏
  • 举报
回复
using System;
using System.DirectoryServices;

public class ADRead {
public static void Main(String[] args) {
if(args.Length!=1) {
Console.WriteLine("用法:" + Environment.GetCommandLineArgs()[0] + " <ad_path>");
Console.WriteLine ();
Console.WriteLine ("按 Enter 键继续...");
Console.ReadLine();
return;
}

DirectoryEntry objDirEnt=new DirectoryEntry(args[0]);
Console.WriteLine("名称 = " + objDirEnt.Name);
Console.WriteLine("路径 = " + objDirEnt.Path);
Console.WriteLine("架构类别名称 = " + objDirEnt.SchemaClassName);
Console.WriteLine("");
Console.WriteLine("属性::");

foreach(String Key in objDirEnt.Properties.PropertyNames) {
Console.Write("\t{0} = ", Key);
Console.WriteLine("");
foreach(Object objValue in objDirEnt.Properties[Key]) {
Console.WriteLine("\t\t{0}", objValue);
}
}
}
}

szch 2003-03-25
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/topic/1481/1481409.xml?temp=.729458
加载更多回复(1)

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧