Windows8: device identifier

六月ゝ 毕业季﹏ 提交于 2019-12-10 17:19:47

问题


I am currently trying to retrieve a unique device identifier. Here is my code:

var token = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null);
var reader = Windows.Storage.Streams.DataReader.fromBuffer(token.id);

reader.unicodeEncoding = true;
var identifier = reader.readString(reader.unconsumedBufferLength);

console.log(identifier);

But it raises following error:

The operation attempted to access data outside the valid range.

How can I retrieve the size of my token.id string? I also tried to use token.id.length, but result is the same.


回答1:


I can't try to replicate what you're doing at the moment, but you might try reading it as bytes into array like this:

var array = new Array(token.id.length);
reader.readBytes(array);

And then convert the array to a string for the identifier.

See these posts for examples:

  • http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/1e2175e3-fe07-4094-9454-b3ecf1bf0381
  • http://social.msdn.microsoft.com/Forums/en-US/winappswithhtml5/thread/cdf72b9f-b3c0-488e-b607-b4445a5039b3


来源:https://stackoverflow.com/questions/12057069/windows8-device-identifier

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