Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I uniquely identify a device in Windows 10/Windows 8/WinRT

Is there any mechanism to identify a device uniquely (even if it is anonymous)?

To be clear, by "device" I mean the computer/slate/pc.

Windows 8.x

http://codepaste.net/ybt893

string HardwareId()
{
    var token = Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null);
    var hardwareId = token.Id;
    var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);
    var bytes = new byte[hardwareId.Length];
    dataReader.ReadBytes(bytes);
    return BitConverter.ToString(bytes);
}

Windows 10

You must add the Mobile and/or Desktop extension SDK.

string HardwareId()
{
    var token = HardwareIdentification.GetPackageSpecificToken(null);
    var hardwareId = token.Id;
    var dataReader = Windows.Storage.Streams.DataReader.FromBuffer(hardwareId);
    var bytes = new byte[hardwareId.Length];
    dataReader.ReadBytes(bytes);
    return BitConverter.ToString(bytes);
}
like image 435
Jerry Nixon Avatar asked May 10 '12 00:05

Jerry Nixon


People also ask

Is device ID in Windows 10 unique?

Each device in Windows has it's own unique identifier known as the Hardware ID. The Device ID is the identifier of the PC itself.

What is Windows device ID?

Right-click the device name and select Properties. Select the Details tab. From the Property drop-down list, select Device Instance Path. The Value box displays the device unique ID.


2 Answers

Such an ability has just been added in Windows 8 RTM:

Windows.System.Profile.HardwareIdentification.GetPackageSpecificToken(null)
like image 62
Sergey Barinov Avatar answered Sep 26 '22 02:09

Sergey Barinov


There doesn't seem to be a convenient way for Metro Style apps in Windows 8 to obtain a system-maintained unique identifier, like Windows Phone 7 provided with its Microsoft.Phone.Info.DeviceExtendedProperties.GetValue( "DeviceUniqueId" )

  • http://social.msdn.microsoft.com/Forums/en-HK/winappswithcsharp/thread/62ac2a48-be60-465c-b3b7-bbb736a67a60
  • http://social.msdn.microsoft.com/Forums/en-NZ/winappswithcsharp/thread/2ca0d5de-9db5-4349-839c-e01ff614ec6e

The best solution I've found so far is to simply generate a new guid in application local storage and use that identifier to identify the computer for the current and future launches of your app.

var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
Object value = localSettings.Values["uniqueDeviceId"];
if (!value)
{
    value = Guid.NewGuid();
    localSettings.Values["uniqueDeviceId"] = value;
}

Keep in mind that the user could delete the local storage and cause your app to forget and regenerate that value (or potentially even modify/spoof the value), so don't depend on it for any critical security purposes. Since I'm only using this technique for rough statistics and usage reporting, this is fine for my needs.

like image 27
bovine Avatar answered Sep 24 '22 02:09

bovine