You need to use NetworkInformation.GetHostNames .
var hostNames = Windows.Networking.Connectivity.NetworkInformation.GetHostNames();
But note that this method will return multiple HostName s.
In my case, it returns four HostName , of which DisplayName is MyComputerName, MyComputerName.local plus two IP addresses.
So it's probably safe to do this -
using Windows.Networking; using Windows.Networking.Connectivity; var hostNames = NetworkInformation.GetHostNames(); var hostName = hostNames.FirstOrDefault(name => name.Type == HostNameType.DomainName)?.DisplayName ?? "???";
Justin xl
source share