Windows Key Key Finder and the other solutions mentioned here by Erij J. and others only work for Windows XP and Windows 7. Microsoft has changed the key encryption algorithm from Windows 8.
I found a solution for Windows 8 and on blogpost here: http://winaero.com/blog/how-to-view-your-product-key-in-windows-10-windows-8-and-windows-7/
However, it is written in VBS, so I rewrote it in C #.
You can check out the full project on GitHub: https://github.com/mrpeardotnet/WinProdKeyFinder
Here is the code on how to decode a product key in Windows 8 and above:
public static string DecodeProductKeyWin8AndUp(byte[] digitalProductId) { var key = String.Empty; const int keyOffset = 52; var isWin8 = (byte)((digitalProductId[66] / 6) & 1); digitalProductId[66] = (byte)((digitalProductId[66] & 0xf7) | (isWin8 & 2) * 4); // Possible alpha-numeric characters in product key. const string digits = "BCDFGHJKMPQRTVWXY2346789"; int last = 0; for (var i = 24; i >= 0; i--) { var current = 0; for (var j = 14; j >= 0; j--) { current = current*256; current = digitalProductId[j + keyOffset] + current; digitalProductId[j + keyOffset] = (byte)(current/24); current = current%24; last = current; } key = digits[current] + key; } var keypart1 = key.Substring(1, last); const string insert = "N"; key = key.Substring(1).Replace(keypart1, keypart1 + insert); if (last == 0) key = insert + key; for (var i = 5; i < key.Length; i += 6) { key = key.Insert(i, "-"); } return key; }
To check the version of Windows and force digitalProductId to use the wrapper method as follows:
public static string GetWindowsProductKey() { var key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Default); const string keyPath = @"Software\Microsoft\Windows NT\CurrentVersion"; var digitalProductId = (byte[])key.OpenSubKey(keyPath).GetValue("DigitalProductId"); var isWin8OrUp = (Environment.OSVersion.Version.Major == 6 && System.Environment.OSVersion.Version.Minor >= 2) || (Environment.OSVersion.Version.Major > 6); var productKey = isWin8OrUp ? DecodeProductKeyWin8AndUp(digitalProductId) : DecodeProductKey(digitalProductId); return productKey; }
I tested it on several machines and it gave me the correct results. Even in Windows 10, I managed to get the generic Windows 10 code (on the updated system).
Note. For me, the original vbs script returned the wrong Win7 keys, despite the fact that the source blog indicated that the code works for Win7 and higher. Therefore, I always abandon the well-known old method for Win7 and below.
Hope this helps.
source share