这应该也可以,但是我没有要测试的 Windows 8...
private string GetHardwareId()
{
return BitConverter.ToString(Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null).Id.ToArray());
}
如果你不止一次调用它,你可能想把它放在一个Lazy<T>
private static Lazy<string> _hardwareId = new Lazy<string>(() => BitConverter.ToString(Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null).Id.ToArray()), true);
public string HardwareId()
{
return _hardwareId.Value;
}
或者如果你知道它总是会被调用,就让它成为静态的:
public static readonly string HardwareId = BitConverter.ToString(Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null).Id.ToArray()));