Advertisement

How to get Microsoft Office product key without using third party software

If you have lost your Microsoft Office product key or forgotten where you had stored it and can no longer retrieve it, do not despair. I would like to share a simple solution to extract your Office product key from the OS installed on your PC without using any third party software.

Advertisеment

  1. Open Notepad.
  2. Copy and paste the following text into the Notepad window
    function Get-MSOfficeProductKey {
        param(
        [string[]]$computerName = "."
        )
    
        $product = @()
        $hklm = 2147483650
        $path = "SOFTWARE\Microsoft\Office"
    
        foreach ($computer in $computerName) {
    
            $wmi = [WMIClass]"\\$computer\root\default:stdRegProv"
    
            $subkeys1 = $wmi.EnumKey($hklm,$path)
            foreach ($subkey1 in $subkeys1.snames) {
                $subkeys2 = $wmi.EnumKey($hklm,"$path\$subkey1")
                foreach ($subkey2 in $subkeys2.snames) {
                    $subkeys3 = $wmi.EnumKey($hklm,"$path\$subkey1\$subkey2")
                    foreach ($subkey3 in $subkeys3.snames) {
                        $subkeys4 = $wmi.EnumValues($hklm,"$path\$subkey1\$subkey2\$subkey3")
                        foreach ($subkey4 in $subkeys4.snames) {
                            if ($subkey4 -eq "digitalproductid") {
                                $temp = "" | select ComputerName,ProductName,ProductKey
                                $temp.ComputerName = $computer
                                $productName = $wmi.GetStringValue($hklm,"$path\$subkey1\$subkey2\$subkey3","productname")
                                $temp.ProductName = $productName.sValue
    
                                $data = $wmi.GetBinaryValue($hklm,"$path\$subkey1\$subkey2\$subkey3","digitalproductid")
                                $valueData = ($data.uValue)[52..66]
    
                                # decrypt base24 encoded binary data 
                                $productKey = ""
                                $chars = "BCDFGHJKMPQRTVWXY2346789"
                                for ($i = 24; $i -ge 0; $i--) { 
                                    $r = 0 
                                    for ($j = 14; $j -ge 0; $j--) { 
                                        $r = ($r * 256) -bxor $valueData[$j] 
                                        $valueData[$j] = [math]::Truncate($r / 24)
                                        $r = $r % 24 
                                    } 
                                    $productKey = $chars[$r] + $productKey 
                                    if (($i % 5) -eq 0 -and $i -ne 0) { 
                                        $productKey = "-" + $productKey 
                                    } 
                                } 
                                $temp.ProductKey = $productKey
                                $product += $temp
                            }
                        }
                    }
                }
            }
        }
        $product
    }
    
  3. Save the text above into a file with the ".ps1" extension on the Desktop.
    Bonus tip: To make sure that you save the file correctly with the ".ps1" extension, you can type its name in double quotes, for example, "office.ps1".office key
  4. Now you must determine if you have a 32-bit version of Office or 64-bit. If you have Office 2007, 2003 or earlier, then you have a 32-bit version as there was no 64-bit version released. Also, if your Windows is 32-bit, then your Office is also 32-bit because 64-bit apps cannot run on 32-bit Windows.
  5. If you have 64-bit Windows and if you run Office 2010, 2013 or 2016, it can either be 32-bit or 64-bit. To determine this, start any Office application such as Word, OneNote, Excel etc.
  6. Click File and then Help in the File menu. On the right, under the About... section, you will see it listed whether it's 32-bit or 64-bit.
  7. Now you must open Powershell as administrator. If you are running 32-bit Office, open the 32-bit version of PowerShell. If you are running 64-bit Office, open 64-bit PowerShell. Type "powershell" into the search box of the Start Menu or right on the Start Screen. On 64-bit Windows, the shortcut named 'Windows PowerShell (x86)' is the 32-bit version of PowerShell and the one without 'x86' in its name is the 64-bit PowerShell. Right click it and choose Run as administrator or select the correct shortcut with the keyboard and press CTRL+SHIFT+Enter. This will open an elevated PowerShell window.
  8. Enable the execution of local files which are not digitally signed. This can be done with the following command (you can copy-paste it):
    Set-ExecutionPolicy RemoteSigned

    Press Enter to allow the execution policy to be changed.Windows PowerShell

  9. Now you should type the following command:
    Import-Module C:\Users\Winaero\Desktop\office.ps1; Get-MSOfficeProductKey

    Note: You must change the path in the command above, including your user name folder, to correctly point to the location where you saved the office.ps1 file.

  10. Voila, your Office product key will be displayed on the screen!

Thanks to our reader "bosbigal" for sharing this script.

Support us

Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:

If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!

Advertisеment

Author: Sergey Tkachenko

Sergey Tkachenko is a software developer who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.

31 thoughts on “How to get Microsoft Office product key without using third party software”

  1. Didn’t work for me. Using Windows 7 Pro, 64-bit Office 2016, 64-bit Powershell in Admin Mode, Ran both commands, no output on second one with the key. Thanks anyway.

  2. It worked for me, but mine was in the WOW6432 folder, so I modified the code to just look at that one entry.
    Here is the resulting code:

    function Get-MSOfficeProductKey {
    $hklm = 2147483650
    $wmi = [WMIClass]”\\.\root\default:stdRegProv”
    $data = $wmi.GetBinaryValue($hklm,”SOFTWARE\WOW6432Node\Microsoft\Office\14.0\Registration\{90140000-0012-0000-0000-0000000FF1CE}”,”DigitalProductID”)
    $valueData = ($data.uValue)[52..66]
    # decrypt base24 encoded binary data
    $productKey = “”
    $chars = “BCDFGHJKMPQRTVWXY2346789”
    for ($i = 24; $i -ge 0; $i–) {
    $r = 0
    for ($j = 14; $j -ge 0; $j–) {
    $r = ($r * 256) -bxor $valueData[$j]
    $valueData[$j] = [math]::Truncate($r / 24)
    $r = $r % 24
    }
    $productKey = $chars[$r] + $productKey
    if (($i % 5) -eq 0 -and $i -ne 0) {
    $productKey = “-” + $productKey
    }
    }
    $productKey
    }

    1. Replace for ($i = 24; $i -ge 0; $i–) {

      by for ($i = 24; $i -ge 0; $i–-) {

      and replace for ($i = 24; $i -ge 0; $j–) {

      by for ($i = 24; $i -ge 0; $j-–) {

  3. I tried this method both with the original code given, as well as dan’s modified code and it just gave me varying lengths of error messages, the gist of which is:
    You must provide a value expression following the ‘-‘ operator
    The term ‘Get-MSOfficeProductKey’ is not recognized as the name of a cmdlet, function, script file, or operable program

  4. This worked for a Windows 10 computer, but it pulled my Office 2007 (wow, didn’t even know I had it!) product key. I wonder how I could modify this to find my Office 2016 key?

  5. I needed to recover a key off my other computer so I tested it on my main computer first that I know the product key for office to see if it works.

    I did get a product key display in powershell but it is not the same key that I activated my office with.

    I am using windows 10(creators update) x64 and Office 2013 x64

  6. I ran it again in powershellX86 and it yelded a key for an unknown ( blank ) ms product that i never used…

  7. Good evening,

    The script worked just fine for me. Windows 8.1 with 64 bit Office 2016 Professional. This saved my day and I’m grateful to you.

    Hope you have a great weekend.

  8. When I copy and paste Set-ExecutionPolicy RemoteSigned here’s what I get:
    PS C:\windows\system32> Set-ExecutionPolicy RemoteSigned

    Execution Policy Change
    The execution policy helps protect you from scripts that you do not trust. Changing the execution policy might expose you to the security risks described in the about_Execution_Policies help topic at
    https:/go.microsoft.com/fwlink/?LinkID=135170. Do you want to change the execution policy?
    [Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is “N”):

    [[ NOTE : The [N] No is highlighted in stead of the [Y] Yes ]]

    PS C:\windows\system32> Import-Module C:\Users\Winaero\Desktop\office.ps1; Get-MSOfficeProductKey
    Import-Module : The specified module ‘C:\Users\Winaero\Desktop\office.ps1’ was not loaded because no valid module file
    was found in any module directory.
    At line:1 char:1
    + Import-Module C:\Users\Winaero\Desktop\office.ps1; Get-MSOfficeProduc …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ResourceUnavailable: (C:\Users\Winaero\Desktop\office.ps1:String) [Import-Module], FileNo
    tFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

    Get-MSOfficeProductKey : The term ‘Get-MSOfficeProductKey’ is not recognized as the name of a cmdlet, function, script
    file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
    and try again.
    At line:1 char:52
    + … rt-Module C:\Users\Winaero\Desktop\office.ps1; Get-MSOfficeProductKey
    + ~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : ObjectNotFound: (Get-MSOfficeProductKey:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

    PS C:\windows\system32>

    What should I do?

  9. Hi all, it took me a while to get this working. Since I didn’t follow the instructions exactly and didn’t run the 32bit version of power-shell for my W10 64bit, office 2010 32bit recovery.

    Spend a lot of time messing with the WOW6432 which wasn’t necessary as it automatically searched part of the registry when I ran the 32bit version of powershell.

    Also I noticed the default execution policy was No. So pressing enter may have NOT Applied the policy.

  10. Two questions:
    1- input the right path ..if i have the file on my desktop, which are the proper words to write?
    2- how to handle this message “The term ‘Get-MSOfficeProductKey’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct”?
    Thanks

  11. Sorry but this didn’t work also for me :-( …
    Win10 64 bit
    Office 2016 32bit
    i’m not into w scripting, but, for what i understand, the script searches the registry for some
    “DigitalProductId” string/key … i have NOT found such a key in my registry
    thank you anyway, cheers

Leave a Reply

Your email address will not be published.

css.php
Using Telegram? Subscribe to the blog channel!
Hello. Add your message here.