从我的网络位置获取计算机名称 [英] Getting computer names from my network places

查看:19
本文介绍了从我的网络位置获取计算机名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有办法使用 C# 获取在我的网络位置中显示的所有计算机名称.

I was wondering if there is a way to get all the computer names that show up in my network places using C#.

推荐答案

您将需要使用 NetServerEnum() API.我不相信在基本的 .NET 库中有一个托管包装器,但我能够通过快速谷歌搜索找到它:http://www.codeproject.com/Articles/16113/Retreiving-a-list-of-network-computer-names-using

You will want to use the NetServerEnum() API. I dont believe there is a managed wrapper for this in the base .NET libraries but I was able to find this with a quick google search: http://www.codeproject.com/Articles/16113/Retreiving-a-list-of-network-computer-names-using

注意:我没有测试或彻底审查过 codeproject 代码,但如果有任何问题,它应该足以作为您需要的起点.

NOTE: I haven't tested or thoroughly reviewed the codeproject code but it should be enough of a starting point for what you need if there are any issues.

除非您确定域环境,否则不要使用 DirectoryServices.System.DirectoryServices 类是一个 ADSI 包装器,它在没有要查询的 Active Directory 的情况下也能正常工作.NetServerEnum() 适用于工作组和域,但不保证最可靠的数据(并非所有机器都可能出现).它依赖于计算机浏览器服务.

Do not use DirectoryServices unless your sure of a domain environment. The System.DirectoryServices class is an ADSI wrapper that dosent work without an Active Directory to query against. NetServerEnum() works on workgroups and domains but dosen't guarantee the most reliable data (not all machines may show up). It relies on the Computer Browser service.

最好的解决方案可能是一个包含两种可能性并合并结果的类:/

The best solution would probably be a class that wraps both possibilities and merges the results :/

这篇关于从我的网络位置获取计算机名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆