How to read product keys and licences under Windows

It is not easy to get the product key of Office. Especially if you want to do without third-party programmes and you have to face the fact that you can’t achieve anything via command prompt (cmd). Instead, we have to use the new PowerShell. For the readout process, the normal editor must first be opened. You can easily find it using the Windows search function. Copy the following source code into the editor window:

[code lang="php"]

function Get - MSOfficeProductKey
{
    param([string[]]$computerName = ".") $product = @() $hklm = 2147483650$path = "SOFTWAREMicrosoftOffice "foreach ($computerin $computerName)
    {
        $wmi = [WMIClass]"\$computerrootdefault:stdRegProv"$subkeys1 = $wmi . EnumKey($hklm, $path) foreach ($subkey1in $subkeys1 . snames)
        {
            $subkeys2 = $wmi . EnumKey($hklm, "$path$subkey1") foreach ($subkey2in $subkeys2 . snames)
            {
                $subkeys3 = $wmi . EnumKey($hklm, "$path$subkey1$subkey2") foreach ($subkey3in $subkeys3 . snames)
                {
                    $subkeys4 = $wmi . EnumValues($hklm, "$path$subkey1$subkey2$subkey3") foreach ($subkey4in $subkeys4 . snames)
                    {
                        if ($subkey4 - eq "digitalproductid")
                        {
                            $temp = "" | selectComputerName, 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 - ge0;$i--)
                            {
                                $r = 0for ($j = 14;$j - ge0;$j--)
                                {
                                    $r = ($r * 256) - bxor $valueData[$j]$valueData[$j] = [math]::Truncate($r / 24) $r = $r % 24
                                }
                                $productKey = $chars[$r] + $productKeyif (($i % 5) - eq0 - and $i - ne0)
                                {
                                    $productKey = "-" + $productKey
                                }
                            }
                            $temp . ProductKey = $productKey$product += $temp
                        }
                    }
                }
            }
        }
    }
    $product
}

[/code]

Now you have to save the file as office.ps1 on the desktop. Small tip: Put the file name in inverted commas in the save dialogue, i.e. „office.ps1“. This way no unwanted .txt will be appended. Next you need the bit version of your Office. If you don’t know it, open Word, for example, click on File in the top left-hand corner, then on Account and then on Info about Word (for Office 2013). This path may differ depending on the Office version. In the upper part of the window that appears, you should be able to see whether it is a 32-bit or 64-bit Office. Then search for powershell using the Windows search function. For a 64-bit Office, right-click on the Windows PowerShell entry and select Run as administrator. For a 32-bit office, select the Windows PowerShell (x86) entry and start it as administrator. Now enter the following command in the blue window that appears: Set-ExecutionPolicy RemoteSigned Then call the saved script with the following command. Note that you have to use your own user name (e.g. Lisa) instead of %User% (e.g. C:UsersLisaDesktop…). Import-Module C:Users%User%Desktopoffice.ps1; Get-MSOfficeProductKey
Congratulations! The product key should now be displayed.

Header image: © dennizn, stock.adobe.com