加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-13 20:29:25 所属栏目:Windows 来源:网络整理
导读:我在WinRT中寻找一个API来访问mac地址. 您不能按照说法检索MAC地址,但如果您正在尝试执行此操作,则可以检索硬件特定信息以识别计算机. 这是一篇完整的msdn文章,讨论了这个主题:Guidance on using the App Specific Hardware ID (ASHWID) to implement per-d
我在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);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读