How to get the device unique id and mode on windows 8 - ask for help urgently‏ RRS feed

  • Question

  • Nowadays, our app has some reqs as following:

    1, we wanna get the unique id of device(PC or Pad) through the windows 8 API to identify every device on which our App is running.
    2, we wanna distinguish the device as PC or Pad, if it's possible. actually we wanna exactly know the device mode(e.g. Lenovo thinkpad x200T 40xxx) through the windows 8 API to know the exact kind of device on which our App is running.

    So my question might be like this:
    1, Is it possible to get the unique id of total device on windows 8. and how to?
    2, Is it possible to get the mode of total device on windows 8, and how to?

    On Windows phone 7, we got the solution for above question 1, below is the answer, but I didn't find the same solution on win8

    byte[] id =
    uniqueID = Convert.ToBase64String(id);

    And I have done some study about relevant Api in the MSDN, but didn't find the exact answer, and don't know if on right track.
    following are some stuff I've studied.

    whatever, Thanks very much in advance.

    Best regards,
    -Luo Haibo

    Friday, March 23, 2012 12:53 PM


All replies

  • There is no such ID for Windows 8

    You can follow these suggestions however:


    The device enumeration sample will get you close to what you want, however there is no way to tell if you are running on a Tablet vs PC.


    Jeff Sanders (MSFT)

    Friday, March 23, 2012 4:23 PM
  • Hello Jeff,

    Do you have any idea whether any sort of unique device ID will be made available in the API? My company is porting our application from WP7 and this information is relatively important to us.

    Also, I tried to follow your link, but I don't think I was able to find the device enumeration sample you were referring to--it appears to just be a forum search on the keyword "UniqueId" with no relevant results.



    Wednesday, June 27, 2012 9:18 PM
  • My app requires the "UniqueId", too. In Windows Phone 7, there is the DeviceExtendedProperties.GetValue("DeviceUniqueId") could be used, but in Windows 8 Metro/Windows RT, I cannot find the corresponding property to uniquely identify the machine/device. Please help.
    Friday, August 3, 2012 8:58 PM
  • Monday, August 6, 2012 2:30 PM
  • Class for retrieving information about hardware has been added in Windows 8 RTM: Windows.System.Profile.HardwareIdentification
    Tuesday, August 7, 2012 7:11 PM
  • Can you give your source ?
    Wednesday, August 8, 2012 7:54 AM
  • public static string GetHardwareId() { var token = HardwareIdentification.GetPackageSpecificToken(null); var stream = token.Id.AsStream(); using (var reader = new BinaryReader(stream)) { var bytes = reader.ReadBytes((int)stream.Length); return BitConverter.ToString(bytes); } }

    Wednesday, August 8, 2012 10:34 AM
  • thanks ,it help me
    Thursday, August 9, 2012 7:21 AM
  • hi,

    Thanks for this information.  is it possible to obtain the device id from desktop application.

    Tuesday, August 14, 2012 8:54 AM
  • Hi,

    I copied the code and added the using 'Windows.System.Profile.HardwareIdentification'  but Visual Studio coudn't find the lib.

    You wrote '... has been added in Windows 8 RTM...'  Does that mean, that i have to write one App for the PC and the same App for RTM (Phones and Tablets)?

    I thought with Win8 there is only one Code for all devices.

    So what is wrong here?

    Tuesday, August 28, 2012 6:37 AM
  • "RTM" is the final build (9200) of Windows 8, contrasting with the earlier Developer, Consumer, and Release Preview (8400) versions.

    Windows 8 does not run on phones. Details on Windows Phone 8 have not been fully announced. See the Windows Phone blog for the information that has been announced.


    Tuesday, August 28, 2012 6:49 AM
  • Unfortunately I discovered that the token retrieved this way (HardwareIdentification.GetPackageSpecificToken) can change sometime. I found two cases: first - when the application is started just after system start-up, second - when tablet is connected to docking station. In my application I need device unique id for data encryption and "unique id" like this one, which can vary, is useless. I found another way to get some unique, device-related value:

    var profiles = NetworkInformation.GetConnectionProfiles();
    var adapter = profiles[0].NetworkAdapter;
    var uniqueId = adapter.NetworkAdapterId;
    but I am not sure if it is reliable. Does anyone know if NetworkAdapterId obtained in this way can change?

    • Edited by Maciek_WR Monday, October 15, 2012 11:32 AM
    Monday, October 15, 2012 11:27 AM
  • Sergey

    Thanks for the code. Somehow when the above code is ran, it gives compilation error on the below line - indicating AsStream() not available for Windows.Storage.Streams.IBuffer.

    var stream = token.Id.AsStream();

    Am I missing out something here?

    Monday, October 15, 2012 1:28 PM
  • AsStream is an extension method. If you search for it in Visual Studio's Object Browser you'll find it in System.Runtime.InteropServices.WindowsRuntime.WindowsRuntimeBufferExtensions

    It will be available if you add using System.Runtime.InteropServices.WindowsRuntime to the top of your source file.


    Tuesday, October 16, 2012 8:27 PM
  • Actually, I used same way(NetworkAdapterId) too.

    The "PackageSpecificToken" seems a better solution.

    but I don't why the "PackageSpecificToken" changed, are you sure for this?

    And does it change among the same values or it just changes all-around?

    Sunday, November 18, 2012 4:53 AM
  • I came from Windows Phone as well and was using the device id for user identification.

    The problem with a master device id for Windows 8 is that anybody can build a PC with any combination of parts. There is no one piece of hardware that would identify the user or their PC model with this setup.

    To address this, I generate a random 25 character 'key' when the user starts the app for the first time and save it in a local file. From that point on, they always have that key attached to them. I treat their key as their unique ID.

    It's an accurate system for normal users. However, if the user uninstalls and reinstalls the app (or somehow deletes the key file) a new key will be generated and they would be counted again (but that's an very small percentage of users).

    Wednesday, December 5, 2012 11:04 PM
  • private string GetHardwareId()
        var token = HardwareIdentification.GetPackageSpecificToken(null);
        var hardwareId = token.Id;
        var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);
        byte[] bytes = new byte[hardwareId.Length];
        return BitConverter.ToString(bytes);
    Thursday, July 18, 2013 9:11 AM