How get list of local network computers?

前端 未结 6 448
甜味超标
甜味超标 2020-12-01 04:47

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

6条回答
  •  [愿得一人]
    2020-12-01 05:23

    Here a property that uses a LINQ query

    private List NetworkHosts
        {
            get
            {
                var result = new List();
    
                var root = new DirectoryEntry("WinNT:");
                foreach (DirectoryEntry computers in root.Children)
                {
                    result.AddRange(from DirectoryEntry computer in computers.Children where computer.Name != "Schema" select computer.Name);
                }
                return result;
            }
        }
    

提交回复
热议问题