This is my old implementation to get a Unique DeviceID for Windows Universal 8.1 but the type HardwareIdentification does not exist anymore.
private static string GetId()
{
var token = HardwareIdentification.GetPackageSpecificToken(null);
var hardwareId = token.Id;
var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);
byte[] bytes = new byte[hardwareId.Length];
dataReader.ReadBytes(bytes);
return BitConverter.ToString(bytes).Replace("-", "");
}
That is the complete solution for Windows Desktop:
Use this Code to get the HardwareId:
Update for Windows 1609 ("Anniversary Update")
See this Q&A for a much better way to get an ID.
Old info for older OS builds
You need to add a reference to the Desktop and / or Mobile SDKs to build against the Hardware Token. At runtime you should use the
ApiInformation
type to query if the API is present before using it (other device families like Xbox don't have it).That said, many times when people ask for the device ID that's not actually the best solution for their problem -- are you sure you need to identify the physical device across its entire lifespan, even if ownership changes?
It seems that
is doing the magic, refering to EasClientDeviceInformation it provides a unique Id.
BUT it only works for Windows Store Apps... so there have to be another solution.
EasClientDeviceInformation does not work for Windows 10 mobile. The device id is just the same for every phone (all our win10m customers gets registered with the same GUID) We need the id for sending push messages to the right phone.