Getting the Device GUID

时间:2021-04-21 22:45:07
Sometime you may want to uniquely identify a Windows Phone, such as when you are implementing push notifications. The best way to identify a unique Windows Phone is through its device GUID.
 
The following code snippet shows how to obtain the GUID of a Windows Phone device:
 
using Microsoft.Phone.Info;
 
    public static byte[] DeviceId()
    {
        object uniqueId;
        if (DeviceExtendedProperties.TryGetValue(
        "DeviceUniqueId", out uniqueId))
        {
            return (byte[])uniqueId;
        }
        return null;
    }
    ...
    ...
 
    byte[] guid = DeviceId();           
    MessageBox.Show("Device GUID - " +
        Convert.ToBase64String(guid));

For the code above to work, you need to check the ID_CAP_IDENTITY_DEVICE setting in your WMAppManifest.xml file.