Several computers are connected to one wireless router. I can create a WCF service on one computer and use it from another using the computer's name as expressed in Environment.MachineName
on the service hosting computer. However, I can't seem to be able to discover that name from the other computers.
Some of the things I've tried: (These are just the pertinent parts.)
This:
Dns.GetHostName(); ... //(Just gives me this computer's name.)
And this:
PrincipalContext ctx = new PrincipalContext(ContextType.Domain) ... // "The server could not be contacted."
And also this:
DirectorySearcher searcher = new DirectorySearcher("(objectCategory=computer)", new[] { "Name" });
SearchResultCollection SRC = searcher.FindAll(); ... // "The specified domain either does not exist or could not be contacted."
And:
DirectoryEntry root = new DirectoryEntry("WinNT:");
foreach (DirectoryEntry dom in root.Children)
foreach (DirectoryEntry entry in dom.Children)
if (entry.Name != "Schema")
result += entry.Name + "\r\n"; // https://stackoverflow.com/a/5581339/939213 returns nothing.
So, how do I get the computers' names?
I'm not interested in any 3rd party library. I am aware of http://www.codeproject.com/Articles/16113/Retreiving-a-list-of-network-computer-names-using but that code is from 2006. I'm hoping there is some managed way to do this by now. And according to Getting computer names from my network places - "Do not use DirectoryServices unless your sure of a domain environment".