# ========================================================= # MAX Windows Toolkit - KMS 激活 # ========================================================= $Common = "C:\Setup\windows\lib\common.ps1" if (Test-Path $Common) { . $Common } Show-AdminWarn Write-Header "KMS 激活" $KmsServer = "kms.unvmax.com" $KmsPort = "1688" function Get-WindowsEditionInfo { $Reg = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" return @{ ProductName = $Reg.ProductName EditionID = $Reg.EditionID } } function Get-KmsClientKeyByEdition { param ( [string]$EditionID ) # Windows 10/11 KMS 客户端安装密钥 $KmsKeys = @{ "Professional" = "W269N-WFGWX-YVC9B-4J6C9-T83GX" "ProfessionalN" = "MH37W-N47XK-V7XM9-C7227-GCQG9" "ProfessionalWorkstation" = "NRG8B-VKK3Q-CXVCJ-9G2XF-6Q84J" "ProfessionalWorkstationN" = "9FNHH-K3HBT-3W4TD-6383H-6XYWF" "ProfessionalEducation" = "6TP4R-GNPTD-KYYHQ-7B7DP-J447Y" "ProfessionalEducationN" = "YVWGF-BXNMC-HTQYQ-CPQ99-66QFC" "Education" = "NW6C2-QMPVW-D7KKK-3GKT6-VCFB2" "EducationN" = "2WH4N-8QGBV-H22JP-CT43Q-MDWWJ" "Enterprise" = "NPPR9-FWDCX-D2C8J-H872K-2YT43" "EnterpriseN" = "DPH2V-TTNVB-4X9Q3-TJR4H-KHJW4" "EnterpriseG" = "YYVX9-NTFWV-6MDM3-9PT4T-4M68B" } if ($KmsKeys.ContainsKey($EditionID)) { return $KmsKeys[$EditionID] } return $null } $WinInfo = Get-WindowsEditionInfo $ProductName = $WinInfo.ProductName $EditionID = $WinInfo.EditionID Write-Info "产品名称: $ProductName" Write-Info "版本 ID : $EditionID" Write-Line $KmsKey = Get-KmsClientKeyByEdition -EditionID $EditionID if ([string]::IsNullOrWhiteSpace($KmsKey)) { Write-Err "未找到匹配此 Windows 版本的 KMS 客户端密钥" Write-Warn "常见不支持版本:" Write-Muted "Windows 家庭版 / Core" Write-Muted "Windows 中国家庭版" Write-Muted "部分 OEM 或特殊版本" Write-Err "已跳过激活" exit 1 } Write-OK "匹配 KMS 客户端密钥: $KmsKey" Write-Info "KMS 服务器: $KmsServer`:$KmsPort" Write-Line try { Write-Info "清除旧 KMS 服务器..." cscript //nologo "$env:windir\system32\slmgr.vbs" /ckms Write-Info "安装 KMS 客户端安装密钥..." cscript //nologo "$env:windir\system32\slmgr.vbs" /ipk $KmsKey Write-Info "设置 KMS 服务器..." cscript //nologo "$env:windir\system32\slmgr.vbs" /skms "$KmsServer`:$KmsPort" Write-Info "正在激活 Windows..." cscript //nologo "$env:windir\system32\slmgr.vbs" /ato Write-Info "检查激活状态..." cscript //nologo "$env:windir\system32\slmgr.vbs" /xpr Write-Line Write-OK "Windows 激活完成" } catch { Write-Line Write-Err "Windows 激活失败" Write-Muted $_.Exception.Message Write-Warn "详细授权信息:" cscript //nologo "$env:windir\system32\slmgr.vbs" /dlv }