Posts How to get a unique Device ID in WinRT (C#)

How to get a unique Device ID in WinRT (C#)

In a project I’m working on I needed to get an ID that uniquely identifies the device that is running the app.

WinRT provides an API for HardwareIdentification
but you should be aware that the call to GetPackageSpecificToken method will produce different value for each app that calls it.
And if you have several applications that needs to interact with a websevice and pass the device id you can’t rely on it for identification.
Another approach you can use is taking the NetworkAdapterId , which is like using the MAC address (WinRT doesn’t give an API to take the MAC itself).
Here is a code snippet to help you (assuming the device has at least one network adapter):

var networkProfiles = Windows.Networking.Connectivity.NetworkInformation.GetConnectionProfiles();
var adapter = networkProfiles.First<Windows.Networking.Connectivity.ConnectionProfile>().NetworkAdapter;//takes the first network adapter
string networkAdapterId = adapter.NetworkAdapterId.ToString();//produces a string in the format: 90de0377-d988-4e1b-b89b-475bbca46e1d


Note: just like MAC address, if the user changes the network adapter (or hacking into it) the value will be replaced so you should only use it in a given session and between sessions.

This post is licensed under CC BY 4.0 by Tamir Dresher.

Trending Tags