I'm working on a Metro app written in C# and need a way to uniquely identify a device. I found the ASHWID in the documentation which looks great. The code suggested is as follows:
HardwareToken token = HardwareIdentification.GetPackageSpecificToken(null);
IBuffer hardwareId = token.Id;
IBuffer signature = token.Signature;
IBuffer certificate = token.Certificate;
The problem is, how do I turn that IBuffer into a string which I can use?
After a lot of hunting through suggestions which were actually in JS or C++ I finally found an answer!
Thanks go to this blog - http://bartwullems.blogspot.co.uk/2012/09/windows-8-uniquely-identifying-device.html
For a guid id you can do the following as an extension to the above answer
This should work as well, but I don't have Windows 8 to test with...
And if you call it more than once, you might want to stick it in a
Lazy<T>
Or just make it static if you know it will always be called:
You can use
HardwareIdentification.GetPackageSpecificToken(null)
, see http://msdn.microsoft.com/en-us/library/windows/apps/jj553431.aspxThat function gives you a lot of information, that you can filter as you like. For example:
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.