windows-8 – 如何以编程方式在WinRT(Windows 8)中获取mac地址?

前端之家收集整理的这篇文章主要介绍了windows-8 – 如何以编程方式在WinRT(Windows 8)中获取mac地址?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在WinRT中寻找一个API来访问mac地址.
您不能按照说法检索MAC地址,但如果您正在尝试执行此操作,则可以检索硬件特定信息以识别计算机.

这是一篇完整的msdn文章,讨论了这个主题Guidance on using the App Specific Hardware ID (ASHWID) to implement per-device app logic (Windows)

小心只使用您需要的信息而不是完整的ID,因为它可能会根据您无用的信息(例如Dock Station字节)而改变.

这是基于几个字节(cpu ID,内存大小,磁盘设备的序列号和BIOS)的计算设备ID的代码示例:

string deviceSerial = string.Empty;
// http://msdn.microsoft.com/en-us/library/windows/apps/jj553431
Windows.System.Profile.HardwareToken hardwareToken = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
using (DataReader dataReader = DataReader.FromBuffer(hardwareToken.Id))
{
    int offset = 0;
    while (offset < hardwareToken.Id.Length)
    {
        byte[] hardwareEntry = new byte[4];
        dataReader.ReadBytes(hardwareEntry);

        // cpu ID of the processor || Size of the memory || Serial number of the disk device || BIOS
        if ((hardwareEntry[0] == 1 || hardwareEntry[0] == 2 || hardwareEntry[0] == 3 || hardwareEntry[0] == 9) && hardwareEntry[1] == 0)
        {
            if (!string.IsNullOrEmpty(deviceSerial))
            {
                deviceSerial += "|";
            }
            deviceSerial += string.Format("{0}.{1}",hardwareEntry[2],hardwareEntry[3]);
        }
        offset += 4;
    }
}

Debug.WriteLine("deviceSerial=" + deviceSerial);

猜你在找的Windows相关文章