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;
}
-
1What language are you using?v7d8dpo4– v7d8dpo42016年04月10日 08:28:37 +00:00Commented Apr 10, 2016 at 8:28
-
it's C#.Net @v7d8dpo4ahmetertem– ahmetertem2016年04月10日 10:09:25 +00:00Commented Apr 10, 2016 at 10:09
2 Answers 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;
}
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();
-
Thanks for your reply, but sadly the lines you mentioned are not useful for an UWP app.narendramacha– narendramacha2016年04月11日 05:20:06 +00:00Commented 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/…ahmetertem– ahmetertem2016年04月11日 06:18:21 +00:00Commented Apr 11, 2016 at 6:18