Finding the device id in Windows 8

Posted: October 12, 2012 in Programming, Windows 8
Tags:

One of many questions about Windows 8 is how to get the device ID, believe or not is not straightforward and for a long time i even ear many times that this wasn’t even possible. Apparently after RTM this becomes possible.

Many times you need this to grant:

-push notification correct behavior

-to grant that a authenticated app is running from some specific device (can be applied many times to bank and finance problems)

The Device ID is many times called App Specific Hardware ID or ASHWID in windows 8 language.

 

Today digging around to find the answer i found this great post of Wade Wegner that show us how to get this information in C#, you can read the article here http://www.wadewegner.com/2012/09/getting-the-application-id-and-hardware-id-in-windows-store-applications/. You can also find a more complete description on Windows 8 specification http://msdn.microsoft.com/en-us/library/windows/apps/jj553431.aspx.

 

Basically in C# what you need to do is something similar to

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];
    dataReader.ReadBytes(bytes);

    return BitConverter.ToString(bytes);
}  

In WinJS you would have something similar to

function getHardwareId(outId){
    var token = Windows.System.Profile.HardwareIdentification.getPackageSpecificToken(nonce);
    var hardwareId = packageSpecificToken.id;
    var signature = packageSpecificToken.signature;
    var certificate = packageSpecificToken.certificate;
    outId = hardwareId;

}

Hope this information can be useful for you.

 

Advertisements
Comments
  1. Mahantesh says:

    You can get device id using following class aslo:

    Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation device = new Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation();
    _MachineID = device.Id.ToByteArray();

    http://msdn.microsoft.com/en-us/library/windows/apps/windows.security.exchangeactivesyncprovisioning.easclientdeviceinformation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s