0

How do I uniquely identify a surface(tablet)? How do I get id of a tablet? there is a way using `HardwareIdentification.GetPackageSpecificToken(null). The problem is, it changes for simple hardware changes like disabling bluetooth. Is there a way to get unique id for a tablet which never changes?

Kris Vandermotten
  • 10,111
  • 38
  • 49
  • Did you mean to tag the question with asp.net? If so what are you trying to do? – Emond Sep 29 '14 at 09:39
  • It matters how long you need the ID to be, but for most purposes (on tablets only, not phone) you can use [`EasClientDeviceInformation.Id`](http://msdn.microsoft.com/en-US/library/windows/apps/windows.security.exchangeactivesyncprovisioning.easclientdeviceinformation.aspx). This property gives you half of a SHA256 hash of a combination of the "MachineID, User SID, and Package Family Name". This will never change (so long as your Package Family Name stays the same, which it should), but it will be different from user to user, so it will not uniquely identify a single device. – Nate Diamond Sep 29 '14 at 19:18
  • thanks @NateDiamond.is there a way to identify two tablets eventhough it is used by several users – Migara Kulasekara Sep 30 '14 at 07:47
  • i want to write a storeapp , in that i want to uniquely identify two tablets @ErnodeWeerd – Migara Kulasekara Sep 30 '14 at 08:12
  • It might help if you explain what you consider the identity of the tablet. It might also help if you explained what you are trying to accomplish. – Emond Sep 30 '14 at 08:18
  • i want to maintain details of user devices which are using my app build for tablets @ErnodeWeerd – Migara Kulasekara Sep 30 '14 at 08:26

1 Answers1

0

You can use HardwareIdentification.GetPackageSpecificToken(null), see http://msdn.microsoft.com/en-us/library/windows/apps/jj553431.aspx

That function gives you a lot of information, that you can filter as you like. For example:

using System.Runtime.InteropServices.WindowsRuntime;

public static string GetMachineId()
{
    var hardwareToken = 
        HardwareIdentification.GetPackageSpecificToken(null).Id.ToArray();
    var count = hardwareToken.Length / 4;
    ulong id = 0ul;
    for (int i = 0; i < count; i++)
    {
        switch (BitConverter.ToUInt16(hardwareToken, i * 4))
        {
            case 1:
                // processor
            case 2:
                // memory
            case 9:
                // system BIOS
                id = (id << 12) ^ BitConverter.ToUInt16(hardwareToken, i * 4 + 2);
                break;
        }
    }
    return Convert.ToBase64String(BitConverter.GetBytes(id));
}

However, bear in mind that this function, and the underlying API, cannot guarantee absolute uniqueness across all the machines connected to the internet. You would typically combine this with information about the user.

Another option is to generate and store a GUID in local (non-roaming) storage, and use that as your machine id. Depending in you exact needs, this may be a better solution.

UPDATE

The Guid method is fairly simple. Just generate a new Guid the first time the app is run using

Guid installationId = Guid.NewGuid();

Then store that in a local file using

StorageFile file = await ApplicationData.Current.LocalFolder.CreateFileAsync(
    "installationId", 
    CreationCollisionOption.FailIfExists);

using (Stream fileStream = await file.OpenStreamForWriteAsync())
{
    await fileStream.WriteAsync(installationId.ToByteArray(), 0, 16)
    await fileStream.FlushAsync();
}

On subsequent runs, you detect that the file is there and read it.

A possible disadvantage of this method is that, when the application is uninstalled and subsequently reinstalled, a new GUID will be generated.

Kris Vandermotten
  • 10,111
  • 38
  • 49
  • @KrisVandermotton .as i said in my question ,this method won't solve my problem because packagespecificToken is changes for small hardware changes like you switched off your bluetooth – Migara Kulasekara Sep 30 '14 at 08:29
  • @MigaraKulasekara As I said in my answer, you can filter that information. The function I show does not change its output when a network adapter or bluetooth connection is added or removed. – Kris Vandermotten Sep 30 '14 at 08:32
  • thanks @KrisVandermotten,Can u explain GUID method too? – Migara Kulasekara Sep 30 '14 at 08:49
  • @KrisVandermotton still my problem is not 100% solved,because GUID changes when app uninstalled and re-installed.and GetPackageSpecificToken(null) comprises of those nine components which can be changed in the life time of the software – Migara Kulasekara Sep 30 '14 at 10:06
  • @MigaraKulasekara I'm sorry to be so blunt, but what part of "a lot of information, that you can filter as you like" is it that you don't understand? The function I present in my answer only uses three components, not nine. It uses memory, CPU and BIOS information. That is pretty stable. – Kris Vandermotten Oct 01 '14 at 11:25
  • Vandermotton ,what if, is there a CPU repair ? then this value get changed? – Migara Kulasekara Oct 02 '14 at 07:26
  • @MigaraKulasekara Define repair? In any case, what happens then is not documented. You could test it, or ask Microsoft. An upgrade is a different thing: that ill change the value. You should also ask yourself if a PC remains the same PC if the CPU is upgraded, and the memory, and the motherboard. Without a good understanding of your exact requirements, and the reasons why those are required, we cannot answer that question for you. – Kris Vandermotten Oct 10 '14 at 06:30