如何获得本地网络上的计算机列表? [英] How get list of local network computers?
问题描述
我想获得的本地网络上的计算机列表。我试图用 NetServerEnum
和 WNetOpenEnum
API,但两者API返回的错误code 6118(ERROR_NO_BROWSER_SERVERS_FOUND)
。本地网络中的Active Directory中不使用。
I am trying to get a list of local network computers. I tried to use NetServerEnum
and WNetOpenEnum
API, but both API return error code 6118 (ERROR_NO_BROWSER_SERVERS_FOUND)
. Active Directory in the local network is not used.
最奇怪的Windows资源管理器将显示所有本地计算机没有任何问题。
Most odd Windows Explorer shows all local computers without any problems.
还有没有其他的方式来获得在局域网中的计算机列表?
Are there other ways to get a list of computers in the LAN?
推荐答案
我找到的解决方案使用的界面与的IShellItem CSIDL_NETWORK。我得到的所有网络PC。
I found solution using interface IShellItem with CSIDL_NETWORK. I get all network PC.
C ++:使用方法的IShellFolder :: EnumObjects
C++: use method IShellFolder::EnumObjects
C#:您可以使用龚解决方案壳牌图书馆
using System.Collections;
using System.Collections.Generic;
using GongSolutions.Shell;
using GongSolutions.Shell.Interop;
public sealed class ShellNetworkComputers : IEnumerable<string>
{
public IEnumerator<string> GetEnumerator()
{
ShellItem folder = new ShellItem((Environment.SpecialFolder)CSIDL.NETWORK);
IEnumerator<ShellItem> e = folder.GetEnumerator(SHCONTF.FOLDERS);
while (e.MoveNext())
{
Debug.Print(e.Current.ParsingName);
yield return e.Current.ParsingName;
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
这篇关于如何获得本地网络上的计算机列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!