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;
 }
ahmetertem
4341 gold badge5 silver badges19 bronze badges
asked Apr 10, 2016 at 7:57
2
  • 1
    What language are you using? Commented Apr 10, 2016 at 8:28
  • it's C#.Net @v7d8dpo4 Commented 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;
 }
answered Apr 11, 2016 at 11:12
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();
answered Apr 10, 2016 at 9:49
2
  • Thanks for your reply, but sadly the lines you mentioned are not useful for an UWP app. Commented Apr 11, 2016 at 5:20
  • Updated my entry. Tried on Windows 10 and gave my machine name. You may also look another properties of EasClientDeviceInformation msdn.microsoft.com/en-us/library/windows/apps/… Commented Apr 11, 2016 at 6:18

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.