Getting a list of computers on a network

I'm writing an application that needs to get a list of computers (their names) on a network. The examples I've found all seem to query an ActiveDirectory on a server, which is not what I need.

Is there a way to get a list of computers on a server-less network using the .net 2.0 classes I've done this before in VB6 using API's, so would I have to do that in C# 2005 using System.Runtime.InteropServices, or can it be done with System.DirectoryServices

Thanks for any help with this.



Answer this question

Getting a list of computers on a network

  • Jelle O

    Im not sure if this is what you are looking for but this code should get a list of computers on a given domain and put their names into an ArrayList:

    string domain = "Whatever your domain is"; //--- u can also have that searched and found for you

    ArrayList ALLCPU = new ArrayList ALLCPU();

    DirectoryEntry de = new DirectoryEntry(domain);

    //Iterate through entries to find the Computer names

    foreach (DirectoryEntry child in de.Children)

    {

    if (child.SchemaClassName == "Computer")

    {

    AllCPU.Add(child.Name);

    // Or whatever else you want to do with them

    }

    }


  • James Ernst

  • Gavan

    Any ideas
  • Matthew Yang

    You can see a great sample to do it in: http://www.codeproject.com/csharp/comppickerlib.asp
  • Karl Tarbet

     Yeshia wrote:

    Im not sure if this is what you are looking for but this code should get a list of computers on a given domain and put their names into an ArrayList:

    I was looking for a way to list the names of the computers on a network of any type, ie, not just ones on a domain, but also if the network is a plain Workgroup.

    Couldn't get this one to work. Maybe because I don't have a domain, I'm on a normal home workgroup.

    The other two had examples that I can use.

    Thank you to you all for your help.


  • Getting a list of computers on a network