Active Directory 中在线的计算机列表
我使用这段代码输出网络上所有计算机的列表(语言是 jscript.net,但这只是 C# 的一个小操作)。
var parentEntry = new DirectoryEntry();
parentEntry.Path = "WinNT:";
for(var childEntry in parentEntry.Children) {
if(childEntry.SchemaClassName == "Domain") {
var parentDomain = new TreeNode(childEntry.Name);
this.treeView1.Nodes.Add(parentDomain);
var subChildEntry : DirectoryEntry;
var subParentEntry = new DirectoryEntry();
subParentEntry.Path = "WinNT://" + childEntry.Name;
for(subChildEntry in subParentEntry.Children) {
var newNode1 = new TreeNode(subChildEntry.Name);
if(subChildEntry.SchemaClassName == "Computer") {
parentDomain.Nodes.Add(newNode1);
}
}
}
}
我对此有两个问题:
1)它非常慢。显示大约 100 台计算机,加载大约需要 1 分钟。
2) 我只想获取当前在线的计算机列表。
这是可以做到的,因为我见过其他程序这样做,而且它们速度更快,而且它们只能显示在线的程序。
我错过了什么吗?
I'm using this snippet of code to output a list of all the computers on my network (the language is jscript.net, but it's just a small manipulation of C#).
var parentEntry = new DirectoryEntry();
parentEntry.Path = "WinNT:";
for(var childEntry in parentEntry.Children) {
if(childEntry.SchemaClassName == "Domain") {
var parentDomain = new TreeNode(childEntry.Name);
this.treeView1.Nodes.Add(parentDomain);
var subChildEntry : DirectoryEntry;
var subParentEntry = new DirectoryEntry();
subParentEntry.Path = "WinNT://" + childEntry.Name;
for(subChildEntry in subParentEntry.Children) {
var newNode1 = new TreeNode(subChildEntry.Name);
if(subChildEntry.SchemaClassName == "Computer") {
parentDomain.Nodes.Add(newNode1);
}
}
}
}
I have 2 issues with this:
1) It is extremely slow. There's about 100 computers showing, and it takes about 1 minute to load.
2) I want to get only a list of computers that are currently online.
This can be done because I've seen other programs doing it and they are much faster, also they're able to show only the ones online.
Am I missing something?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我知道它有点旧,但对其他人来说......这个片段将在 2-3 秒内从使用 AD 的域返回 760 个计算机名称......这是一个显着的改进......享受!
I know it's a bit old, but for others...this snippet will return a 760 computer names from a domain using AD within 2-3 seconds....a significant improvement....enjoy!
我会查看 CodePlex 上找到的 Linq To Active Directory
您还必须定义“我的网络”。你的子网?您的组织单位?你的域名?你的森林?
还要考虑您正在查询的 LDAP 服务器所在的位置。它是在附近还是在远程链接的另一端?
另外,您认为“在线”是什么?您期望能够 ping 通它吗?您希望能够连接到它并执行操作吗?
这里有很多事情需要考虑。此外,如果您有其他基础设施组件(例如 SCCM / SMS 服务器),那么它们的查询速度通常会更快,因为所有发现数据都已流入数据仓库。
I would look at Linq To Active Directory found on CodePlex
You'd also have to define "my network". Your subnet? Your Organizational Unit? Your domain? Your forest?
Also consider where your LDAP server is that you are querying. Is it close or is it on the other end of a remote link?
Also what do you consider "online"? Do you expect to be able to ping it? Do you expect to be able to connect to it and perform an operation?
There are many things to consider here. Also if you have other infrastructure components such as an SCCM / SMS server they can often be queried much faster since all of the discovery data has flowed up into the data warehouse.