Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get list of local network computers?

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.

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

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

like image 333
KindDragon Avatar asked Apr 01 '10 01:04

KindDragon


People also ask

How do I get a list of computers on my network?

Find computers in network using File ExplorerOpen File Explorer on Windows 10. Click on Network from the left pane. See computers available in the local network. Double-click the device to access its shared resources, such as shared folders or shared printers.

How do I find computers on my network Windows?

Select the Start button, then type settings. Select Settings > Network & internet. The status of your network connection will appear at the top. Windows 10 lets you quickly check your network connection status.


2 Answers

You will need to use the System.DirectoryServices namespace and try the following:

DirectoryEntry root = new DirectoryEntry("WinNT:");

foreach (DirectoryEntry computers in root.Children)
{
    foreach (DirectoryEntry computer in computers.Children)
    {
        if (computer.Name != "Schema")
        {
             textBox1.Text += computer.Name + "\r\n";
        }
    }
}

It worked for me.

like image 112
Cynfeal Avatar answered Sep 17 '22 23:09

Cynfeal


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

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }
    }
like image 37
KindDragon Avatar answered Sep 18 '22 23:09

KindDragon