积极答复者
请问Windows 8 如何获取设备的ID??

问题
答案
-
可以,用Windows.System.Profile.HardwareIdentification.getPackageSpecificToken,但是只有对 win8 RTM版的系统有效
function getDeviceId() { var _internalId = ''; if (Windows.System.Profile && Windows.System.Profile.HardwareIdentification && Windows.System.Profile.HardwareIdentification.getPackageSpecificToken) { var packageSpecificToken = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null); var hardwareId = packageSpecificToken.id; var dataReader = Windows.Storage.Streams.DataReader.fromBuffer(hardwareId); var array = new Array(hardwareId.length); dataReader.readBytes(array); for (var i = 0; i < array.length; i++) { _internalId += array[i].toString(); } } return _internalId; }
在RTM版之前的系统,没有这个API,所以最好做点判断。
另外,这个ID只是你的应用在这台机器上标识的唯一ID,假如同一机器在另外一个应用上获取是不一样的。
- 已建议为答案 Jie BaoModerator 2012年11月19日 5:37
- 已标记为答案 Kyle.Z 2012年11月19日 7:34
-
这个是WinRT的API C#/C++/JS 都是一样可用的,不会没有的:http://msdn.microsoft.com/zh-cn/library/windows/apps/windows.system.profile.hardwareidentification.getpackagespecifictoken?cs-save-lang=1&cs-lang=csharp#code-snippet-1
// nonce is an IBuffer object that would be sent from the cloud service. HardwareToken packageSpecificToken; packageSpecificToken = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(nonce); // hardware id, signature, certificate IBuffer objects // that can be accessed through properties. IBuffer hardwareId = packageSpecificToken.Id; IBuffer signature = packageSpecificToken.Signature; IBuffer certificate = packageSpecificToken.Certificate;
请你使用VS 2012 RTM 和 Win 8 RTM 版本Bob Bao [MSFT]
MSDN Community Support | Feedback to us
- 已标记为答案 Kyle.Z 2012年11月19日 7:32
全部回复
-
可以,用Windows.System.Profile.HardwareIdentification.getPackageSpecificToken,但是只有对 win8 RTM版的系统有效
function getDeviceId() { var _internalId = ''; if (Windows.System.Profile && Windows.System.Profile.HardwareIdentification && Windows.System.Profile.HardwareIdentification.getPackageSpecificToken) { var packageSpecificToken = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(null); var hardwareId = packageSpecificToken.id; var dataReader = Windows.Storage.Streams.DataReader.fromBuffer(hardwareId); var array = new Array(hardwareId.length); dataReader.readBytes(array); for (var i = 0; i < array.length; i++) { _internalId += array[i].toString(); } } return _internalId; }
在RTM版之前的系统,没有这个API,所以最好做点判断。
另外,这个ID只是你的应用在这台机器上标识的唯一ID,假如同一机器在另外一个应用上获取是不一样的。
- 已建议为答案 Jie BaoModerator 2012年11月19日 5:37
- 已标记为答案 Kyle.Z 2012年11月19日 7:34
-
谢谢mansonchor,不过这个是JS的吧?,我是用C#+XAML做的应用,Windows.System.Profile.HardwareIdentification.getPackageSpecificToken这个命名空间都没有,有没有C#获取设备ID的方法???
-
这个是WinRT的API C#/C++/JS 都是一样可用的,不会没有的:http://msdn.microsoft.com/zh-cn/library/windows/apps/windows.system.profile.hardwareidentification.getpackagespecifictoken?cs-save-lang=1&cs-lang=csharp#code-snippet-1
// nonce is an IBuffer object that would be sent from the cloud service. HardwareToken packageSpecificToken; packageSpecificToken = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(nonce); // hardware id, signature, certificate IBuffer objects // that can be accessed through properties. IBuffer hardwareId = packageSpecificToken.Id; IBuffer signature = packageSpecificToken.Signature; IBuffer certificate = packageSpecificToken.Certificate;
请你使用VS 2012 RTM 和 Win 8 RTM 版本Bob Bao [MSFT]
MSDN Community Support | Feedback to us
- 已标记为答案 Kyle.Z 2012年11月19日 7:32