我正在寻找 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-8 - 如何以编程方式获取 WinRT (Windows 8) 中的 mac 地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12892189/