I am struggling right now with using ubuntu and would like some help.
So right now i'm running ubuntu from a USB flash drive after Windows 7 somehow left.
How can I get my windows product key which is somewhere on my laptop hard drive, from within Ubuntu?
102 Answers
First recover your Ubuntu with going to recovery mode and running
sudo apt install --reinstall ubuntu-desktopThis answer is not written by me but by Thomas on Superuser, please vote there, if you vote here thanks
There is a great tool available for Linux called chntpw. You can get it easily on Debian/Ubuntu via:
sudo apt install chntpwTo look into the relevant registry file mount the Windows disk and open it like so:
chntpw -e /path/to/windisk/Windows/System32/config/SOFTWARENow to get the decoded DigitalProductId enter this command:
dpi \Microsoft\Windows NT\CurrentVersion\DigitalProductId
A comment from below says
9The path to the relevant registry file is /path/to/windisk/Windows/System32/config/RegBack/SOFTWARE
So for anyone wondering how this actually works.
Essentially you'll have to grab the contents of the registry key
HKLM\Software\Microsoft\Windows NT\CurrentVersion\DigitalProductIdThis is a so called REG_BINARY. Meaning it's just a collection of bytes. You could dump them via chntpw or copy them by hand.
Let's see what we have to do with those bytes in order to get our product key with the help of some pseudo code.
Once you have those in an Array, you need to extract the subset of bytes that encode the product id. In particular: the range between 52 and (52 + 14). That gives you 15 bytes.
EncodedId = DigitalProductId.Range(52, 52+14)This is still a bunch of bytes, that don't at all resemble the product key. So let us decode it.
For that you need the collection of all the characters a product key can be made of:
Characters = "BCDFGHJKMPQRTVWXY2346789"Yes this is not the whole alphabet. As it turns out a Windows product key doesn't use all of the alphanumerical symbols.
Now let's do the decoding. We'll need:
- A variable to hold the product key
- A loop over 0 to 24. For each character of our product key
- An inner loop over 0 to 14 (In reverse) For each byte in our encoded id
- Some bit fiddeling and arithmatic for the decoding process
ProductKey = ""
FOR i = 0 TO 24 c = 0 FOR j = 14 TO 0 STEP -1 # Shift the current contents of c to the left by 1 byte # and xor it with the next byte of our id c = (c * 256) XOR EncodedId[j] # Put the result of the divison back into the array EncodedId[j] = FLOOR(c / 24) # Calculate remainder of c c = c MOD 24 LOOP # Take character at position c and prepend it to the ProductKey ProductKey = Characters[c] + ProductKey
LOOPFinally we insert the "-" character into the string at the appropriate places.
FOR i = 4 TO 1 STEP -1 ProductKey = ProductKey.Insert(i * 5, "-")
LOOPAnd we're done!
... Almost:
PRINT(ProductKey)Now!
Capabilities of our pseudo code
$array.Range($from, $to)Get the contents of$arrayfrom$fromto$to$array.Insert($where, $what)Insert$whatat$whereFOR $var = $start TO $stop [STEP $step]loop the variable$varfrom$startto$stopapplying$stepon each iteration$a XOR $bCalculate bit-wise exclusive or on the numbers$aand$b$a MOD $bCalculate remainder of the division of$aand$b$array[$i]Take only the element at position$ifrom the array#bla blaIs a comment and will be ignored- Strings are just char arrays.
You can see 3 actual implementations in C#, PowerShell and Python over at Super User
2