How to get Device Id in Windows 8 Metro app

烈酒焚心 提交于 2019-12-12 16:31:40

问题


How to get the unique Device in Windows Store App (Metro App)?

Can we use:

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

 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));

Network adapter Id of first Network adapter found

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();

回答1:


Yes, this is a suggested way:

   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);
    }  

Or, you have problems with this method?




回答2:


Here is an other way I found:

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

var myDeviceID = deviceInfo.Id;


来源:https://stackoverflow.com/questions/12893637/how-to-get-device-id-in-windows-8-metro-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!