2012-10-15 91 views

回答

2

有沒有辦法做到這一點。 Windows應用商店應用程序API被沙盒化,對於您可以獲得的有關用戶的信息具有相當的限制性,主要是因爲隱私問題。

5

你不能檢索MAC地址,但你可以檢索硬件特定的信息來識別機器,如果這是你想要做的。

下面是一個完整的MSDN文章討論的主題:Guidance on using the App Specific Hardware ID (ASHWID) to implement per-device app logic (Windows)

小心使用你需要的信息,而不是完整的ID,因爲它可能修改是對你沒用(如碼頭信息例如站字節)。

下面是基於幾個字節(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); 
相關問題