Skip to content

Instantly share code, notes, and snippets.

@whatalnk
Created December 10, 2019 07:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whatalnk/55fe20667c8e41a7ce38884a52f13520 to your computer and use it in GitHub Desktop.
Save whatalnk/55fe20667c8e41a7ce38884a52f13520 to your computer and use it in GitHub Desktop.
find Windows Product Key
require 'win32ole'
# original vbscript is:
# https://support.lenovo.com/mx/ja/solutions/ht500032
#
def convertToKey(key)
keyOffset = 52
i = 28
chars = "BCDFGHJKMPQRTVWXY2346789"
keyOutput = ""
while i >= 0
cur = 0
x = 14
while x >= 0
cur = cur * 256
cur = key[x + keyOffset] + cur
key[x + keyOffset] = (cur / 24) & 255
cur %= 24
x -= 1
end
i -= 1
keyOutput = chars[cur] + keyOutput
if (((29 - i) % 6) == 0) && (i != -1) then
i -= 1
keyOutput = "-" + keyOutput
end
end
keyOutput
end
wsh = WIN32OLE.new('WScript.Shell')
value = wsh.RegRead 'HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId'
out = convertToKey(value)
puts out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment