Windows8:设备标识符 [英] Windows8: device identifier

查看:38
本文介绍了Windows8:设备标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试检索唯一的设备标识符.这是我的代码:

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

但它引发了以下错误:

操作试图访问有效范围之外的数据.

The operation attempted to access data outside the valid range.

如何检索我的 token.id 字符串的大小?我也尝试使用 token.id.length,但结果是一样的.

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

推荐答案

我无法尝试复制您目前正在执行的操作,但您可以尝试将其作为字节读入数组,如下所示:

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:

这篇关于Windows8:设备标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆