Skip to Content

How to find and retrieve Product Key in Windows 11?

Windows Product key is important if you want to activate the Windows, even though you already have an activated copy of Windows but you still need the product key in case you need to reinstall the Windows. The Windows product key is actually stored in the registry which can be retrieved using command. If you are unable to find the Windows key, use this article will show you simple steps, commands and script to find and retrieve Windows 11 product key.

How to find and retrieve Product Key in Windows 11?

Content Summary

Method 1: Use command prompt to execute SoftwareLicensingService class
Method 2: Use PowerShell to execute SoftwareLicensingService class
Method 3: Retrieve DigitalProductId Registry Key using VBScript
Method 4: Execute Get-ProductKey function with PowerShell script
Reference

Method 1: Use command prompt to execute SoftwareLicensingService class

Step 1: Click on the Search icon in the Taskbar to open Search box.

Step 2: Type cmd in the Search box.

Step 3: Click the Run as administrator to open elevated Command Prompt.

Click the Run as administrator to open elevated Command Prompt.

Step 4: The User Account Control (UAC) window will prompt. Click Yes to run the Windows Command Prompt as Administrator.

The User Account Control (UAC) window will prompt. Click Yes to run the Windows Command Prompt as Administrator.

Step 5: Type or copy-paste the following command into the elevated command prompt and press Enter:
wmic path SoftwareLicensingService get OA3xOriginalProductKey

Step 6: The Windows product key will display below OA3xOriginalProductKey.

The Windows product key will display below OA3xOriginalProductKey.

In the event that product key not displaying or showing blank result.

In the event that product key not displaying or showing blank result.

This is because your Windows copy is activated with a digital license instead of firmware-embedded activation key. This command will only works if you are using product key instead of digital license. Proceed to the next method.

Method 2: Use PowerShell to execute SoftwareLicensingService class

Step 1: Click on the Search icon in the Taskbar to open Search box.

Step 2: Type powershell in the Search box.

Step 3: Right-click on the Windows PowerShell and click on the Run as administrator option from the context menu to open elevated PowerShell.

Right-click on the Windows PowerShell and click on the Run as administrator option from the context menu to open elevated PowerShell.

Step 4: The User Account Control (UAC) window will prompt. Click Yes to run the PowerShell as Administrator.

The User Account Control (UAC) window will prompt. Click Yes to run the PowerShell as Administrator.

Step 5: Type or copy-paste the following command into the elevated command prompt and press Enter:
powershell “(Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey”

Step 6: The Windows product key will display.

The Windows product key will display.

In the event that product key not displaying or showing blank result.

In the event that product key not displaying or showing blank result.

This is because your Windows copy is activated with a digital license instead of firmware-embedded activation key. This command will only works if you are using product key instead of digital license. Proceed to the next method.

Method 3: Retrieve DigitalProductId Registry Key using VBScript

Step 1: Click on the Search icon in the Taskbar to open Search box.

Step 2: Type notepad in the Search box.

Step 3: Right-click on the Notepad and click on the Run as administrator option to open elevated Notepad.

Right-click on the Notepad and click on the Run as administrator option to open elevated Notepad.

Step 4: The User Account Control (UAC) window will prompt. Click Yes to open the Notepad as Administrator.

The User Account Control (UAC) window will prompt. Click Yes to open the Notepad as Administrator.

Step 5: Copy and paste the following code into the Notepad.

Option Explicit

Dim objshell,path,DigitalID, Result
Set objshell = CreateObject("WScript.Shell")
'Set registry key path
Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
'Registry key value
DigitalID = objshell.RegRead(Path & "DigitalProductId")
Dim ProductName,ProductID,ProductKey,ProductData
'Get ProductName, ProductID, ProductKey
ProductName = "Product Name: " & objshell.RegRead(Path & "ProductName")
ProductID = "Product ID: " & objshell.RegRead(Path & "ProductID")
ProductKey = "Installed Key: " & ConvertToKey(DigitalID)
ProductData = ProductName  & vbNewLine & ProductID  & vbNewLine & ProductKey
'Show messbox if save to a file
If vbYes = MsgBox(ProductData  & vblf & vblf & "Save to a file?", vbYesNo + vbQuestion, "BackUp Windows Key Information") then
   Save ProductData
End If



'Convert binary to chars
Function ConvertToKey(Key)
    Const KeyOffset = 52
    Dim isWin8, Maps, i, j, Current, KeyOutput, Last, keypart1, insert
    'Check if OS is Windows 8
    isWin8 = (Key(66) \ 6) And 1
    Key(66) = (Key(66) And &HF7) Or ((isWin8 And 2) * 4)
    i = 24
    Maps = "BCDFGHJKMPQRTVWXY2346789"
    Do
           Current= 0
        j = 14
        Do
           Current = Current* 256
           Current = Key(j + KeyOffset) + Current
           Key(j + KeyOffset) = (Current \ 24)
           Current=Current Mod 24
            j = j -1
        Loop While j >= 0
        i = i -1
        KeyOutput = Mid(Maps,Current+ 1, 1) & KeyOutput
        Last = Current
    Loop While i >= 0
    keypart1 = Mid(KeyOutput, 2, Last)
    insert = "N"
    KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
    If Last = 0 Then KeyOutput = insert & KeyOutput
    ConvertToKey = Mid(KeyOutput, 1, 5) & "-" & Mid(KeyOutput, 6, 5) & "-" & Mid(KeyOutput, 11, 5) & "-" & Mid(KeyOutput, 16, 5) & "-" & Mid(KeyOutput, 21, 5)
   
   
End Function
'Save data to a file
Function Save(Data)
    Dim fso, fName, txt,objshell,UserName
    Set objshell = CreateObject("wscript.shell")
    'Get current user name
    UserName = objshell.ExpandEnvironmentStrings("%UserName%")
    'Create a text file on desktop
    fName = "C:\Users\" & UserName & "\Desktop\WindowsKeyInfo.txt"
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set txt = fso.CreateTextFile(fName)
    txt.Writeline Data
    txt.Close
End Function

Step 6: Click on File > Save As… option.

Click on File and Save As... option.

Step 7: Choose All Files for the Save as type, set Encoding to ANSI, and enter the file name as Non-OA3-ProductKey.vbs (with the .vbs extension).

Choose All Files for the Save as type, set Encoding to ANSI, and enter the file name as Non-OA3-ProductKey.vbs (with the .vbs extension).

Step 8: Click on the Save button.

Step 9: Locate the vbs file and then double-click on it to execute the script.

Step 10: A message box will prompt to display the Product Name, Product ID, and Installed Key. Click on Yes button to save the information into text file or click on No button to close the message box.

A message box will prompt to display the Product Name, Product ID, and Installed Key. Click on Yes button to save the information into text file or click on No button to close the message box.

Method 4: Execute Get-ProductKey function with PowerShell script

Step 1: Click on the Search icon in the Taskbar to open Search box.

Step 2: Type notepad in the Search box.

Step 3: Right-click on the Notepad and click on the Run as administrator option to open elevated Notepad.

Right-click on the Notepad and click on the Run as administrator option to open elevated Notepad.

Step 4: The User Account Control (UAC) window will prompt. Click Yes to open the Notepad as Administrator.

The User Account Control (UAC) window will prompt. Click Yes to open the Notepad as Administrator.

Step 5: Copy and paste the following code into the Notepad.

$computers = 'localhost' #comma separated list of computer names
$cred = Get-Credential #domain administrator credentials in domain\user format
Invoke-Command -Credential $cred -ComputerName $computers -ScriptBlock {
function Get-ProductKey {
<#
.SYNOPSIS
Retrieves the product key and OS information from a local or remote system/s.

.DESCRIPTION
Retrieves the product key and OS information from a local or remote system/s. Queries of 64bit OS from a 32bit OS will result in
inaccurate data being returned for the Product Key. You must query a 64bit OS from a system running a 64bit OS.

.PARAMETER Computername
Name of the local or remote system/s.

.NOTES
Author: Boe Prox
Version: 1.1
-Update of function from https://powershell.com/cs/blogs/tips/archive/2012/04/30/getting-windows-product-key.aspx
-Added capability to query more than one system
-Supports remote system query
-Supports querying 64bit OSes
-Shows OS description and Version in output object
-Error Handling

.EXAMPLE
Get-ProductKey -Computername Server1

OSDescription Computername OSVersion ProductKey
------------- ------------ --------- ----------
Microsoft(R) Windows(R) Server 2003, Enterprise Edition Server1 5.2.3790 bcdfg-hjklm-pqrtt-vwxyy-12345

Description
-----------
Retrieves the product key information from 'Server1'
#>
[cmdletbinding()]
Param (
[parameter(ValueFromPipeLine=$True,ValueFromPipeLineByPropertyName=$True)]
[Alias("CN","__Server","IPAddress","Server")]
[string[]]$Computername = $Env:Computername
)
Begin {
$map="BCDFGHJKMPQRTVWXY2346789"
}
Process {
ForEach ($Computer in $Computername) {
Write-Verbose ("{0}: Checking network availability" -f $Computer)
If (Test-Connection -ComputerName $Computer -Count 1 -Quiet) {
Try {
Write-Verbose ("{0}: Retrieving WMI OS information" -f $Computer)
$OS = Get-WmiObject -ComputerName $Computer Win32_OperatingSystem -ErrorAction Stop
} Catch {
$OS = New-Object PSObject -Property @{
Caption = $_.Exception.Message
Version = $_.Exception.Message
}
}
Try {
Write-Verbose ("{0}: Attempting remote registry access" -f $Computer)
$remoteReg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$Computer)
If ($OS.OSArchitecture -eq '64-bit') {
$value = $remoteReg.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('DigitalProductId4')[0x34..0x42]
} Else {
$value = $remoteReg.OpenSubKey("SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('DigitalProductId')[0x34..0x42]
}
$ProductKey = ""
Write-Verbose ("{0}: Translating data into product key" -f $Computer)
for ($i = 24; $i -ge 0; $i--) {
$r = 0
for ($j = 14; $j -ge 0; $j--) {
$r = ($r * 256) -bxor $value[$j]
$value[$j] = [math]::Floor([double]($r/24))
$r = $r % 24
}
$ProductKey = $map[$r] + $ProductKey
if (($i % 5) -eq 0 -and $i -ne 0) {
$ProductKey = "-" + $ProductKey
}
}
} Catch {
$ProductKey = $_.Exception.Message
}
$object = New-Object PSObject -Property @{
Computername = $Computer
ProductKey = $ProductKey
OSDescription = $os.Caption
OSVersion = $os.Version
}
$object.pstypenames.insert(0,'ProductKey.Info')
$object
} Else {
$object = New-Object PSObject -Property @{
Computername = $Computer
ProductKey = 'Unreachable'
OSDescription = 'Unreachable'
OSVersion = 'Unreachable'
}
$object.pstypenames.insert(0,'ProductKey.Info')
$object
}
}
}
}
Get-ProductKey
} | ft Computername,OSDescription,OSVersion,ProductKey

Step 6: Click on File > Save As… option.

Click on File and Save As... option.

Step 7: Choose All Files for the Save as type, set Encoding to ANSI, and enter the file name as Non-OA3-ProductKey.ps1 (with the .ps1 extension).

Choose All Files for the Save as type, set Encoding to ANSI, and enter the file name as Non-OA3-ProductKey.ps1 (with the .ps1 extension).

Step 8: Click on the Save button.

Step 9: Follow below steps to change the network profile type from Public to Private.

Step 10: Press Windows + i key on the keyboard to open the Settings app. Alternatively, you can click the Start menu and select the Settings gear icon located at the top of the menu by default.

Press Windows + i key on the keyboard to open the Settings app. Alternatively, you can click the Start menu and select the Settings gear icon located at the top of the menu by default.

Step 11: Click on the Network & internet option.

Step 12: Click on the Ethernet or Wireless, depend on how you connect to Internet.

Click on the Network and internet option then Ethernet or Wireless, depend on how you connect to Internet.

Step 13: Select the radio button for Private network profile type then close the Settings windows.

Select the radio button for Private network profile type then close the Settings windows.

Step 14: Click on the Search icon in the Taskbar to open Search box.

Step 15: Type powershell in the Search box.

Step 16: Right-click on the Windows PowerShell and click on the Run as administrator option from the context menu to open elevated PowerShell.

Right-click on the Windows PowerShell and click on the Run as administrator option from the context menu to open elevated PowerShell.

Step 17: The User Account Control (UAC) window will prompt. Click Yes to run the PowerShell as Administrator.

The User Account Control (UAC) window will prompt. Click Yes to run the PowerShell as Administrator.

Step 18: Type or copy-paste the following command into the elevated command prompt and press Enter: WinRM quickconfig

Note: WinRM has to be enabled in order to retrieve product key. Follow below steps to enable WinRM using PowerShell.

Step 19: Type y and press on Enter when the PowerShell ask whether to Make these changes.

The status show is now show:

WinRM firewall exception enabled. Configured LocalAccountTokenFilterPolicy to grant administrative rights remotely to local users.

WinRM firewall exception enabled. Configured LocalAccountTokenFilterPolicy to grant administrative rights remotely to local users.

If the following error message show:

Error number: -2144108183 0x80338169
WinRM firewall exception will not work since one of the network connection types on this machine is set to Public. Change the network connection type to either Domain or Private and try again.

Error number: -2144108183 0x80338169. WinRM firewall exception will not work since one of the network connection types on this machine is set to Public. Change the network connection type to either Domain or Private and try again.

In order to resolve this error, apply above mentioned steps to change the network profile type from Public to Private.

Step 20: Type or copy-paste the following command into the elevated command prompt and press Enter: Set-ExecutionPolicy RemoteSigned

Note: This command will allow the PowerShell to execute script.

Step 21: Type y and press on Enter when the PowerShell ask: Do you want to change the execution policy.

Type y and press on Enter when the PowerShell ask: Do you want to change the execution policy.

Step 22: Inside the PowerShell windows, navigate to folder which store the ps1 file created previously.

Step 23: Execute the script using command as below and press Enter: .\Non-OA3-ProductKey.ps1

Step 24: Enter the Administrator credential in Windows PowerShell credential request dialog box.

Enter the Administrator credential in Windows PowerShell credential request dialog box.

Step 25: The Windows product key will display.

The Windows product key will display.

If the following error message show:

cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Plicies at https:/go.microsoft.com/fwlink/?LinkID=135170.

cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Plicies at

In order to resolve this error, apply above mentioned steps to change the script execution policy.

Step 26: Close the PowerShell windows.

Reference