2

I am using Raspberry Pi2 with Windows 10 IoT Core OS, I am developing an UWP app in that I want to get Device Name of my Raspberry Pi 2. Can any one help me how to get it?

I tried using the following code but dont know is it correct way or not

public string GetDeviceName()
    {
        List<string> IpAddress = new List<string>();
        var Hosts = Windows.Networking.Connectivity.NetworkInformation.GetHostNames().ToList();
        foreach (var Host in Hosts)
        {
            string deviceName = Host.DisplayName;
            return deviceName;
        }

        return null;

    }
2
  • 1
    What language are you using?
    – v7d8dpo4
    Apr 10, 2016 at 8:28
  • it's C#.Net @v7d8dpo4
    – ahmetertem
    Apr 10, 2016 at 10:09

2 Answers 2

2

I do it this way and it works very well:

private string GetHostName()
    {
        foreach (Windows.Networking.HostName name in Windows.Networking.Connectivity.NetworkInformation.GetHostNames())
        {
            if (Windows.Networking.HostNameType.DomainName == name.Type)
            {
                return name.DisplayName;
            }
        }
        return null;
    }
1

You may use one of these lines for getting device name. Probably last line you're searching for...

  • System.Environment.MachineName

  • HttpContext.Current.Server.MachineName

  • System.Net.Dns.GetHostName()

Update:

Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation eas = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation();
var dialog = new MessageDialog(eas.FriendlyName);
dialog.ShowAsync();
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.