KindDragon KindDragon - 1 year ago 237
C# Question

How get list of local network computers?

I am trying to get a list of local network computers. I tried to use

API, but both API return error code
. Active Directory in the local network is not used.

Most odd Windows Explorer shows all local computers without any problems.

Are there other ways to get a list of computers in the LAN?

Answer Source

I found solution using interface IShellItem with CSIDL_NETWORK. I get all network PC.

C++: use method IShellFolder::EnumObjects

C#: you can use Gong Solutions Shell Library

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())
                yield return e.Current.ParsingName;

        IEnumerator IEnumerable.GetEnumerator()
            return GetEnumerator();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download