How do I get a unique identifier for a machine running Windows 8 in C#?(如何获取在 C# 中运行 Windows 8 的机器的唯一标识符?)
问题描述
我正在开发一个用 C# 编写的 Metro 应用程序,需要一种方法来唯一地识别设备.我在文档中找到了看起来很棒的 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);
}
感谢访问此博客 - http://bartwullems.blogspot.co.uk/2012/09/windows-8-uniquely-identifying-device.html
这篇关于如何获取在 C# 中运行 Windows 8 的机器的唯一标识符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何获取在 C# 中运行 Windows 8 的机器的唯一标识符?


基础教程推荐
- 从 VS 2017 .NET Core 项目的发布目录中排除文件 2022-01-01
- 是否可以在 asp classic 和 asp.net 之间共享会话状态 2022-01-01
- 错误“此流不支持搜索操作"在 C# 中 2022-01-01
- 在 VS2010 中的 Post Build 事件中将 bin 文件复制到物 2022-01-01
- 将事件 TextChanged 分配给表单中的所有文本框 2022-01-01
- 经典 Asp 中的 ResolveUrl/Url.Content 等效项 2022-01-01
- JSON.NET 中基于属性的类型解析 2022-01-01
- 首先创建代码,多对多,关联表中的附加字段 2022-01-01
- 如何动态获取文本框中datagridview列的总和 2022-01-01
- 全局 ASAX - 获取服务器名称 2022-01-01