Tech Off Thread

4 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Computer names on network c#?

Back to Forum: Tech Off
  • User profile image
    lesmemphis

    How do I get all the Computer names (or details) on a local network or on the same workgroup via C#? I've Googled all over the place and have found nothing that works! Thanks in advance! Smiley

  • User profile image
    xgamer

    This is the one of the ways you can try to find list of computers .... in a managed code  .. there are other ways also ... pls google/bing with correct keywords ...

     

    public List<String> ListNetworkComputers()
            {
                    List<String> _ComputerNames = new List<String>();
                    String _ComputerSchema="Computer";
                    System.DirectoryServices.DirectoryEntry _WinNTDirectoryEntries = new System.DirectoryServices.DirectoryEntry("WinNT:");
                    foreach (System.DirectoryServices.DirectoryEntry _AvailDomains in _WinNTDirectoryEntries.Children)
                    {
                        foreach (System.DirectoryServices.DirectoryEntry _PCNameEntry in _AvailDomains.Children)
                        {
                            if (_PCNameEntry.SchemaClassName.ToLower().Contains(_ComputerSchema.ToLower()))
                            {
                                _ComputerNames.Add(_PCNameEntry.Name);
                            }
                        }
                    }
                return _ComputerNames;
            }

  • User profile image
    lesmemphis

    @xgamer: hey, I've found a lot of entries similar to what you've just given me, but none of them return anything. What I assume is, is that for this code to work, I need a domain set up, but I'm trying to get the computer names in a normal workgroup.

    I've tried your code * well, but no luck. Sad

  • User profile image
    lesmemphis

    Hey, I got it working, was very close to your example:

    ArrayList nets = new ArrayList();
    
    DirectoryEntry entryPC;
    entryPC = new DirectoryEntry();
    entryPC.Path = "WinNT://domainName";
    
    foreach (DirectoryEntry child in entryPC.Children)
    {
       if (child.Name != "Schema")
       nets.Add(child.Name);
      }
    
    return nets;

     

    (obviously using System.DirectoryServices)

    Thanks!

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.