Windows 11 產品金鑰重設指南:PowerShell 自動化
本篇完整指南詳細說明如何使用 PowerShell 命令來管理與重設你的 Windows 11 產品金鑰。此流程適用於需要清除現有授權資料,並套用直接從系統 BIOS 擷取的新產品金鑰,以確保正確重新啟用的使用者。
⚠️ 安全性警告: 執行這些指令碼會涉及修改系統授權元件,請務必格外謹慎。請確認你擁有系統管理員權限,並在執行前確認所使用的產品金鑰正確無誤,因為錯誤的金鑰可能會影響系統的啟用狀態。
先決條件
開始之前,請確認你已具備:
- 一套有效的 Windows 11 安裝環境,且可以存取 BIOS/UEFI 設定以檢視金鑰。
- 在 Windows 11 機器上的系統管理員權限。
1. 從 BIOS 自動擷取產品金鑰
在進行任何變更之前,務必先擷取儲存在 Windows 授權服務中的目前或原始 OEM 產品金鑰。這可能是為了日後參考或還原之用。
在提升權限的 PowerShell 工作階段中執行以下命令,以顯示金鑰:
(Get-WmiObject -query 'select * from SoftwareLicensingService').OA3xOriginalProductKey
動作: 複製主控台中顯示的輸出結果,這就是你可供參考的原始產品金鑰。
2. 手動金鑰管理步驟(供理解用)
以下步驟概述了指令碼中使用的個別命令:
A. 清除目前的授權狀態
使用此命令從 Windows 啟用服務中移除目前已安裝的產品金鑰,有效清除現行的授權狀態:
slmgr.vbs /upk
說明:/upk 參數用於解除安裝目前已安裝的產品金鑰。
B. 清除登錄檔中的金鑰(安全性措施)
為了將系統登錄檔中殘留的產品金鑰資訊降到最低,請執行以下命令:
slmgr.vbs /cpky
說明:此命令會清除儲存在系統登錄檔中殘留的產品金鑰資訊。這是一項安全性措施,可防止未經授權的使用者輕易取得授權詳細資訊。
C. 套用新產品金鑰並啟用
取得新的產品金鑰後,使用 slmgr.vbs 安裝該金鑰並立即觸發啟用程序:
slmgr.vbs /ipk YOUR_NEW_PRODUCT_KEY
slmgr.vbs /ato
請將 YOUR_NEW_PRODUCT_KEY 替換為你實際的 25 碼 Windows 產品金鑰。請勿在未變更預留位置文字的情況下執行此命令。
說明:/ipk <product-key> 會將指定的產品金鑰安裝至系統中。/ato 會嘗試使用剛安裝的金鑰立即啟用 Windows。
D. 重設啟用計時器(選用)
如果你遇到啟用試用相關問題,或希望重設任何現有的啟用計時器,請執行以下命令:
slmgr.vbs /rearm
說明:/rearm 命令會重設啟用計時器,這在你最近變更硬體或需要重設任何現有試用期問題時相當有用。
3. 完整自動化指令碼
本節詳細說明一支完整的 PowerShell 指令碼,可自動化整個流程:擷取原始金鑰、清除舊授權,並套用直接從 BIOS 擷取的新金鑰。
使用說明:
-1. 將下方提供的完整指令碼儲存為檔案(例如 Reset-Win11KeyFromBIOS.ps1)。
-2. 將 $NewProductKey 中的 YOUR_NEW_PRODUCT_KEY 預留位置替換為你想安裝的實際產品金鑰。
-3. 從提升權限的 PowerShell 視窗執行此指令碼。
-4. 指令碼會自動處理所有步驟,包括從模擬 BIOS 資料結構的系統中讀取金鑰資訊。
3.1 金鑰擷取指令碼
<#
.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 ---
# Replace this placeholder with the actual product key you want to install.
$NewProductKey = "YOUR_NEW_PRODUCT_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 {
slmgr.vbs /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 {
slmgr.vbs /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 {
if ($NewProductKey -eq "YOUR_NEW_PRODUCT_KEY") {
throw "Replace the YOUR_NEW_PRODUCT_KEY placeholder before running the activation step."
}
Write-Host "Installing key..."
slmgr.vbs /ipk $NewProductKey
Write-Host "Attempting activation..."
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..."
slmgr.vbs /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
