Created
December 10, 2019 07:23
-
-
Save whatalnk/55fe20667c8e41a7ce38884a52f13520 to your computer and use it in GitHub Desktop.
find Windows Product Key
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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