如何在Windows 8 Metro应用程序中获取设备ID

时间:2012-10-15 10:23:28

标签: microsoft-metro windows-runtime

如何在Windows应用商店应用(Metro App)中获取唯一设备?

我们可以使用:

Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(空);

 Windows.System.Profile.HardwareToken hToke = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
IBuffer hardwareId = hToke.Id;
IBuffer signature = hToke.Signature;
IBuffer certificate = hToke.Certificate;
DataReader reader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);
byte[] ar = new Byte[hardwareId.Length];
reader.ReadBytes(ar);
string i = ar.ToString();
string id = System.Text.Encoding.Unicode.GetString(ar, 0, ar.Length);
System.Diagnostics.Debug.WriteLine("ID" + Convert.ToBase64String(ar));

找到第一个网络适配器的网络适配器ID

IReadOnlyCollection<Windows.Networking.Connectivity.ConnectionProfile> profiles =
Windows.Networking.Connectivity.NetworkInformation.GetConnectionProfiles();
Windows.Networking.Connectivity.NetworkAdapter na = profiles.First<Windows.Networking.Connectivity.ConnectionProfile>().NetworkAdapter;
string nid =  na.NetworkAdapterId.ToString();

2 个答案:

答案 0 :(得分:6)

是的,这是suggested方式:

   private string GetHardwareId()
    {
        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);
    }  

或者,这个方法有问题吗?

答案 1 :(得分:0)

这是我发现的另一种方式:

Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation deviceInfo = 
  new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation();

var myDeviceID = deviceInfo.Id;