如何获取本地网络计算机列表? [英] How get list of local network computers?

查看:35
本文介绍了如何获取本地网络计算机列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取本地网络计算机的列表.我尝试使用 NetServerEnumWNetOpenEnum API,但两个 API 都返回错误代码 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#:你可以使用 Gong Solutions Shell 库

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屋!

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