Estimated Reading Time: 5 min
How to Retrieve Your Windows Product Key – Easy VBScript & PowerShell Methods
If you’ve lost your Windows product key and need to retrieve it, you’re in luck! This simple VBScript will help you extract your Windows activation key directly from your system registry. Whether you’re reinstalling Windows or just keeping a backup, this method is quick and easy.
Why You May Need Your Windows Product Key
Your Windows product key is essential for:
- Reinstalling or upgrading Windows.
- Activating Windows on a new machine.
- Ensuring compliance with Microsoft licensing.
- Troubleshooting activation issues.
Step-by-Step Guide to Retrieve Your Windows Product Key
Follow these steps to extract the product key:
Step 1: Open Notepad
- Press
Win + R
, type notepad, and hit Enter. - Copy and paste the following VBScript into Notepad:
Set WshShell = CreateObject("WScript.Shell")
MsgBox ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"))
Function ConvertToKey(Key)
Const KeyOffset = 52
i = 28
Chars = "BCDFGHJKMPQRTVWXY2346789"
Do
Cur = 0
x = 14
Do
Cur = Cur * 256
Cur = Key(x + KeyOffset) + Cur
Key(x + KeyOffset) = (Cur \ 24) And 255
Cur = Cur Mod 24
x = x -1
Loop While x >= 0
i = i -1
KeyOutput = Mid(Chars, Cur + 1, 1) & KeyOutput
If (((29 - i) Mod 6) = 0) And (i <> -1) Then
i = i -1
KeyOutput = "-" & KeyOutput
End If
Loop While i >= 0
ConvertToKey = KeyOutput
End Function
Step 2: Save the File
- Click File > Save As.
- Choose All Files as the file type.
- Name the file GetWindowsKey.vbs and save it on your desktop.
Step 3: Run the Script
- Double-click the GetWindowsKey.vbs file.
- A message box will appear, displaying your Windows product key.
Important Notes
- Administrator Rights Required: You may need to run the script as an administrator for it to work.
- Works on Older Windows Versions: This script is compatible with Windows XP, 7, 8, and some versions of Windows 10.
- Digital Licenses: If you have a digital license tied to your Microsoft account, the key may not be retrievable this way.
Conclusion
With just a few steps, you can easily retrieve your Windows product key using this VBScript. This can be extremely useful when reinstalling Windows or troubleshooting activation issues.
If you found this guide helpful, share it with others who might need it! 💻🔑
Yes! Here’s another example of a script that retrieves your Windows product key, but this time using PowerShell instead of VBScript.
Retrieve Windows Product Key Using PowerShell
If you’re looking for a quick and efficient way to find your Windows Product Key, PowerShell is another great option. Follow the simple steps below to extract your key without installing any third-party software.
How to Retrieve Windows Product Key with PowerShell
This method works by pulling the DigitalProductId from the Windows registry and decoding it into the readable XXXXX-XXXXX-XXXXX-XXXXX-XXXXX format.

Step 1: Open PowerShell
- Press
Win + X
and select Windows PowerShell (Admin) - Copy and paste the following PowerShell script:
function Get-WindowsKey {
$path = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
$DigitalProductId = (Get-ItemProperty -Path $path).DigitalProductId
$key = ConvertTo-Key $DigitalProductId
$key
}
function ConvertTo-Key ($DigitalProductId) {
$KeyOffset = 52
$Chars = "BCDFGHJKMPQRTVWXY2346789"
$Key = ""
$isN = ($DigitalProductId[66] \ 6) -band 1
$DigitalProductId[66] = ($DigitalProductId[66] -band 247) -bor (($isN -band 2) * 4)
$j = 24
do {
$Current = 0
$i = 14
do {
$Current = $Current * 256
$Current = $DigitalProductId[$i + $KeyOffset] + $Current
$DigitalProductId[$i + $KeyOffset] = [math]::Floor($Current / 24)
$Current = $Current % 24
$i--
} while ($i -ge 0)
$j--
$Key = $Chars[$Current] + $Key
if (($j % 5) -eq 0 -and $j -ne 0) {
$Key = "-" + $Key
}
} while ($j -ge 0)
return $Key
}
Get-WindowsKey
Step 2: Run the Script
- After pasting the script, press
Enter
. - Your Windows Product Key will be displayed in the PowerShell window.
Why Use PowerShell Instead of VBScript?
✅ More Secure: PowerShell is more modern and widely used for automation.
✅ Faster Execution: PowerShell scripts execute faster than VBScript.
✅ More Control: You can easily modify and expand PowerShell scripts.
Limitations
- This method may not work on systems that use digital licenses instead of traditional product keys.
- If your key is stored in the BIOS/UEFI, this script may not retrieve it.
Final Thoughts
Using PowerShell to find your Windows product key is a simple and efficient method. Whether you’re troubleshooting activation issues or reinstalling Windows, this script ensures you can access your key whenever needed.
If the PowerShell script isn’t working for you, let’s try an alternative approach that should work on most Windows versions. We’ll retrieve the Windows Product Key from BIOS/UEFI using a different PowerShell command.
Alternative PowerShell Method to Retrieve Windows Product Key
If the previous script didn’t work, your Windows key might be stored in BIOS/UEFI instead of the registry. Try this method:
Step 1: Open PowerShell
- Press
Win + X
and select Windows PowerShell (Admin).
Step 2: Run This Simple Command
Copy and paste the following command into PowerShell and press Enter:
(Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey
Step 3: View Your Product Key
- If your Windows key is embedded in BIOS/UEFI, it will be displayed in the PowerShell window.
- If nothing appears, your key may not be stored in BIOS, or your system uses digital licensing (linked to a Microsoft account).
Additional Troubleshooting
- Check If Your Windows Uses a Digital License
- Open Settings → Update & Security → Activation.
- If it says “Windows is activated with a digital license”, then there is no retrievable product key.
- Check Your Windows Edition
- The key retrieval may not work on OEM or Volume Licensing versions.
- Run this command to check your license type:
slmgr /dli
- Try Another WMI Command
- If the first command doesn’t work, try this:
wmic path softwarelicensingservice get OA3xOriginalProductKey
- If the first command doesn’t work, try this:
Conclusion
- If your key is stored in BIOS, the WMI method should retrieve it.
- If you have a digital license, there is no retrievable key (your activation is linked to your Microsoft account).
- If you’re using a Volume License (like in businesses or schools), your key is typically managed by IT admins.