本文介绍了我如何的Windows 10的通用内获得一个唯一标识符的设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的旧的实现得到一个独特的DeviceID为Windows 8.1的通用,但HardwareIdentification不再存在的类型。
私有静态字符串GETID()
{
VAR令牌= HardwareIdentification.GetPackageSpecificToken(NULL);
VAR硬件ID = token.Id;
变种的DataReader = Windows.Storage.Streams.DataReader.FromBuffer(硬件ID);
字节[]字节=新的字节[hardwareId.Length]
dataReader.ReadBytes(字节);
返回BitConverter.ToString(字节).Replace( - ,);
}
解决方案
这是完整的解决方案Windows桌面:
- 添加扩展引用Windows桌面扩展为UWP像彼得·托 - MSFT提到
使用此代码来获取硬件ID:使用
系统;
使用Windows.Security.ExchangeActiveSyncProvisioning;
使用Windows.System.Profile;
命名空间Tobit.Software.Device
{
公共密封类DeviceInfo
{
私有静态DeviceInfo _instance;
公共静态DeviceInfo实例
{
获得{
如果(_instance == NULL)
_instance =新DeviceInfo();
返回_instance; }
}
公共字符串ID {搞定;私人集; }
公共字符串模式{搞定;私人集; }
公共字符串Manufracturer {搞定;私人集; }
公共字符串名称{;私人集; }
公共静态字符串{OSNAME获得;组; }
私人DeviceInfo()
{
n = GETID();
变种deviceInformation =新EasClientDeviceInformation();
型= deviceInformation.SystemProductName;
Manufracturer = deviceInformation.SystemManufacturer;
名称= deviceInformation.FriendlyName;
OSNAME = deviceInformation.OperatingSystem;
}
私人静态字符串GETID()
{
如果(Windows.Foundation.Metadata.ApiInformation.IsTypePresent(Windows.System.Profile.HardwareIdentification) )
{
VAR令牌= HardwareIdentification.GetPackageSpecificToken(NULL);
VAR硬件ID = token.Id;
变种的DataReader = Windows.Storage.Streams.DataReader.FromBuffer(硬件ID);
字节[]字节=新的字节[hardwareId.Length]
dataReader.ReadBytes(字节);
返回BitConverter.ToString(字节).Replace( - ,);
}
抛出新的异常(用于设备ID目前还没有API!);
}
}
}
This is my old implementation to get a Unique DeviceID for Windows Universal 8.1 but the type HardwareIdentification does not exist anymore.
private static string GetId()
{
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).Replace("-", "");
}
解决方案
That is the complete solution for Windows Desktop:
- Add the Extension reference "Windows Desktop Extensions for the UWP" like Peter Torr - MSFT mentioned.
Use this Code to get the HardwareId:
using System;
using Windows.Security.ExchangeActiveSyncProvisioning;
using Windows.System.Profile;
namespace Tobit.Software.Device
{
public sealed class DeviceInfo
{
private static DeviceInfo _Instance;
public static DeviceInfo Instance
{
get {
if (_Instance == null)
_Instance = new DeviceInfo();
return _Instance; }
}
public string Id { get; private set; }
public string Model { get; private set; }
public string Manufracturer { get; private set; }
public string Name { get; private set; }
public static string OSName { get; set; }
private DeviceInfo()
{
Id = GetId();
var deviceInformation = new EasClientDeviceInformation();
Model = deviceInformation.SystemProductName;
Manufracturer = deviceInformation.SystemManufacturer;
Name = deviceInformation.FriendlyName;
OSName = deviceInformation.OperatingSystem;
}
private static string GetId()
{
if (Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.System.Profile.HardwareIdentification"))
{
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).Replace("-", "");
}
throw new Exception("NO API FOR DEVICE ID PRESENT!");
}
}
}
这篇关于我如何的Windows 10的通用内获得一个唯一标识符的设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!