In C# how do I get the list of local computer names like what one gets viewing the Network in windows explorer

前端 未结 4 1056
甜味超标
甜味超标 2020-12-01 22:12

There are a lot of questions about getting the name and IP addresses of the local machine and several about getting IP addresses of other machines on the LAN (not all answer

4条回答
  •  春和景丽
    2020-12-01 22:26

    public List ListNetworkComputers()
    {
        List _ComputerNames = new List();
        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;
    }
    

提交回复
热议问题