Getting computer names from my network places

后端 未结 3 1606
予麋鹿
予麋鹿 2020-12-06 21:39

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

3条回答
  •  死守一世寂寞
    2020-12-06 21:51

    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

    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.

    EDIT: 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 :/

提交回复
热议问题