Welcome, guest | Sign In | My Account | Store | Cart

IronPython script for retrieving MS products' keys. There is how to get Windows key in following example.

Text, 34 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from System import Array, Char, Console
from System.Collections import ArrayList
from Microsoft.Win32 import Registry

def DecodeProductKey(digitalProductID):
   map = ("BCDFGHJKMPQRTVWXY2346789").ToCharArray()
   key = Array.CreateInstance(Char, 29)
   raw = ArrayList()

   i = 52
   while i < 67:
      raw.Add(digitalProductID[i])
      i += 1
   i = 28

   while i >= 0:
      if (i + 1) % 6 == 0:
         key[i] = '-'
      else:
         k = 0
         j = 14
         while j >= 0:
            k = (k * 256) ^ raw[j]
            raw[j] = (k / 24)
            k %= 24
            key[i] = map[k]
            j -= 1
      i -= 1

   return key

reg = Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion")
val = reg.GetValue("DigitalProductId")
Console.WriteLine(DecodeProductKey(val))
Created by greg zakharov on Thu, 1 Nov 2012 (GPL3)
Text recipes (14)
greg zakharov's recipes (59)

Required Modules

  • (none specified)

Other Information and Tasks