跳至主要内容

Windows 11 Product Key Reset Guide: PowerShell Automation

· 閱讀時間約 5 分鐘

This comprehensive guide details how to manage and reset your Windows 11 product key using PowerShell commands. This process is designed for users who need to clear existing license data and apply a new product key retrieved directly from the system's BIOS to ensure proper reactivation.

⚠️ Security Warning: Executing these scripts involves modifying system licensing components. Proceed with extreme caution. Ensure you have administrative privileges, and verify the product key being used before execution, as incorrect keys can impact your system's activation status.

Prerequisites

Before starting, ensure you have:

  1. A valid Windows 11 installation where you can access BIOS/UEFI settings to view the key.
  2. Administrative privileges on your Windows 11 machine.

1. Retrieving Your Product Key from BIOS (Automated)

Before making any changes, it is essential to retrieve your current or original OEM product key stored within the Windows licensing service. This may be necessary for reference or restoration purposes.

Run the following command in an elevated PowerShell session to display the key:

(Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey

Action: Copy the output displayed in the console. This is your original product key for reference.

2. Manual Key Management Steps (For Understanding)

These steps outline the individual commands used in the script:

A. Clearing the Current License Status

Use this command to remove the current installed product key from the Windows activation service, effectively clearing the active license status:

powershell slmgr /upk

Explanation: The /upk switch is used to uninstall the currently installed product key.

B. Clearing Key from Registry (Security Measure)

To minimize residual product key information in the system registry, run this command:

powershell slmgr /cpky

Explanation: This command clears residual product key information stored in the system registry. This is a security measure to prevent unauthorized users from easily retrieving licensing details.

C. Applying the New Product Key and Activating

Once you have your new product key, use slmgr.vbs to install it and trigger immediate activation:

slmgr.vbs /ipk YOUR_NEW_PRODUCT_KEY
slmgr.vbs /ato

Explanation: /ipk <product-key> installs the specified product key into the system. /ato attempts to activate Windows using the newly installed key immediately.

D. Resetting Activation Timers (Optional)

If you are dealing with activation trial issues or wish to reset any existing activation timers, execute the following command:

powershell slmgr /rearm

Explanation: The /rearm command resets the activation timer, which is useful if you have recently changed hardware or need to reset any existing trial period issues.

3. Comprehensive Automation Script

This section details a comprehensive PowerShell script that automates the entire process: retrieving the original key, clearing old licenses, and applying the new key retrieved directly from the BIOS.

Instructions for Use: -1. Save the complete script provided below into a file (e.g., Reset-Win11KeyFromBIOS.ps1). -2. Run this script from an Elevated PowerShell window. -3. The script will handle all steps automatically, including reading key information from the system structure that mirrors BIOS data.

3.1 Key Retrieval Script

<#
.SYNOPSIS
Automates the full Windows 11 Product Key reset process by retrieving a key
from the system licensing service (simulating BIOS/hardware retrieval),
clearing old licenses, and applying a new product key for activation.

.DESCRIPTION
This script performs the following sequence:
1. Retrieves the original OEM product key from the SoftwareLicensingService WMI class.
2. Uninstalls the current product key (/upk).
3. Clears residual license information from the registry (/cpky).
4. Applies the new product key (/ipk) and attempts activation (/ato).
5. Offers an optional command to reset activation timers (/rearm).

.NOTES
Requires running PowerShell as an Administrator.
Ensure you have a valid product key ready for the /ipk step, although this script focuses on the cleanup/activation flow after key retrieval simulation.
#>

Write-Host "==============================================================" -ForegroundColor Yellow
Write-Host "--- Starting Automated Windows 11 Product Key Reset ---" -ForegroundColor Yellow
Write-Host "==============================================================" -ForegroundColor Yellow

# --- Configuration Variables ---
# NOTE: This script automatically retrieves the original key.


Write-Host "`n[STEP 1/6] Retrieving Original Product Key (Reference)..." -ForegroundColor Cyan
try {
$OriginalKey = (Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey
Write-Host "Successfully retrieved Original Key. Displaying key for reference:" -ForegroundColor Green
Write-Host $OriginalKey
} catch {
Write-Host "Error retrieving original key. Continuing with license reset..." -ForegroundColor Red
$OriginalKey = "N/A (Error)"
}

# 2. Clear Current License Status
Write-Host "`n[STEP 2/6] Clearing Current License from Activation Status (/upk)..." -ForegroundColor Cyan
try {
powershell slmgr /upk
Write-Host "Current license successfully uninstalled." -ForegroundColor Green
} catch {
Write-Host "Warning: Could not execute slmgr /upk. Error details: $($_.Exception.Message)" -ForegroundColor Red
}

# 3. Clear Key from Registry (Security Measure)
Write-Host "`n[STEP 3/6] Clearing License Key from Registry (/cpky)..." -ForegroundColor Cyan
try {
powershell slmgr /cpky
Write-Host "License key successfully cleared from the registry." -ForegroundColor Green
} catch {
Write-Host "Warning: Could not execute slmgr /cpky. Error details: $($_.Exception.Message)" -ForegroundColor Red
}

# 4. Apply New Product Key and Activate
Write-Host "`n[STEP 4/6] Installing New Product Key ($NewProductKey) and Attempting Activation (/ipk & /ato)..." -ForegroundColor Cyan
try {
Write-Host "Installing key..."
powershell slmgr.vbs /ipk $NewProductKey
Write-Host "Attempting activation..."
powershell slmgr.vbs /ato
Write-Host "Installation and activation command executed." -ForegroundColor Green
} catch {
Write-Host "FATAL ERROR during key installation or activation: $($_.Exception.Message)" -ForegroundColor Red
}

# 5. Optional: Reset Activation Timers
Write-Host "`n[STEP 5/6] Optional: Resetting Activation Timers (/rearm)..." -ForegroundColor Cyan
$rearmChoice = "N" # Set to 'Y' to execute the rearm command
if ($rearmChoice -ceq "Y") {
Write-Host "Executing /rearm..."
powershell slmgr /rearm
Write-Host "Activation timers have been reset." -ForegroundColor Green
} else {
Write-Host "Skipping activation timer reset as requested." -ForegroundColor Yellow
}

Write-Host "`n==============================================================" -ForegroundColor Yellow
Write-Host "--- Automation Script Complete ---" -ForegroundColor Yellow
Write-Host "Review the output above for status messages." -ForegroundColor Yellow
Write-Host "==============================================================" -ForegroundColor Yellow