本文介绍了我如何在C#中运行Windows 8的计算机的唯一标识符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在写在C#中的地铁应用程序,并需要一种方法来唯一地识别设备。我发现它看起来很大的文档中的ASHWID。建议的代码如下:
I'm working on a Metro app written in C# and need a way to uniquely identify a device. I found the ASHWID in the documentation which looks great. The code suggested is as follows:
HardwareToken token = HardwareIdentification.GetPackageSpecificToken(null);
IBuffer hardwareId = token.Id;
IBuffer signature = token.Signature;
IBuffer certificate = token.Certificate;
现在的问题是,我怎么把这一IBuffer到了我可以使用一个字符串?
The problem is, how do I turn that IBuffer into a string which I can use?
推荐答案
很多,通过它实际上是在JS或C的建议狩猎后++,我终于找到了答案!
After a lot of hunting through suggestions which were actually in JS or C++ I finally found an answer!
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);
}
由于去这个博客 -
这篇关于我如何在C#中运行Windows 8的计算机的唯一标识符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!