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
Solution with LINQ lambda syntax and unmanaged resource resolver
public List GetNetworkHostNames()
{
using (var directoryEntry = new DirectoryEntry("WinNT:"))
{
return directoryEntry
.Children
.Cast()
.SelectMany(x=>x.Children.Cast())
.Where(c => c.SchemaClassName == "Computer")
.Select(c => c.Name)
.ToList();
}
}