# Windows / Office 2024 MAK 激活 # 用法(PowerShell):irm https://act.chibaolechengde.com | iex # 密钥不在本脚本里,运行时凭 token 从服务端获取,并通过 WMI 安装(不出现在进程命令行)。 & { $ErrorActionPreference = 'Stop' $Base = 'https://act.chibaolechengde.com' [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $WinAppId = '55c92734-d682-4d71-983e-d6ec3f16059f' $OfficeAppId = '0ff1ce15-a989-479d-af46-f275c6370663' $Hints = @{ 'C004F069' = '密钥与当前版本不匹配:Windows 家庭版不能用 MAK;Office 必须是批量许可版(VL),零售版装不上。' 'C004F050' = '密钥无效。' 'C004C003' = '密钥已被微软封锁。' 'C004C008' = '密钥已无法再用于激活。' 'C004C020' = 'MAK 激活次数已用完。' '8007232B' = 'DNS 解析失败,检查网络。' '80072EE7' = '无法连接激活服务器,检查网络。' '80072F8F' = 'TLS 握手失败,通常是系统时间不对。' } function Show-Error($err) { $text = "$($err.Exception.Message) $($err.Exception.ErrorData | Out-String)" $hex = [regex]::Match($text, '(?i)0x([0-9a-f]{8})').Groups[1].Value.ToUpper() if (-not $hex -and $err.Exception.HResult) { $hex = '{0:X8}' -f $err.Exception.HResult } Write-Host "[!] 失败:$($err.Exception.Message.Trim())" -ForegroundColor Red if ($hex -and $Hints[$hex]) { Write-Host " 0x$hex $($Hints[$hex])" -ForegroundColor Yellow } } $StatusNames = @{ 0 = '未授权'; 1 = '已授权'; 2 = 'OOB 宽限期'; 3 = 'OOT 宽限期'; 4 = '非正版宽限期'; 5 = '通知模式'; 6 = '扩展宽限期' } # --- 管理员权限:不是则提权后重新拉取本脚本 --- $principal = [Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent() if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Host '[*] 需要管理员权限,正在请求提权...' Start-Process powershell.exe -Verb RunAs -ArgumentList "-NoProfile -ExecutionPolicy Bypass -NoExit -Command `"irm $Base | iex`"" return } function Get-Mak($name) { try { (Invoke-RestMethod "$Base/key/$name" -Headers @{ Authorization = "Bearer $($State.Token)" } -UseBasicParsing).Trim() } catch { $code = $_.Exception.Response.StatusCode.value__ if ($code -eq 401) { Write-Host '[!] token 错误,下次操作时会重新询问。' -ForegroundColor Red $State.Token = $null } elseif ($code -eq 429) { Write-Host '[!] token 错误次数过多,此 IP 已被封禁 1 小时。' -ForegroundColor Red } else { Write-Host "[!] 获取密钥失败:$($_.Exception.Message)" -ForegroundColor Red } $null } } function Invoke-MakActivation($Name, $AppId, $Label) { Write-Host "`n=== $Label ===" -ForegroundColor Cyan $key = Get-Mak $Name if (-not $key) { return } try { $last5 = $key.Substring($key.Length - 5) $svc = Get-CimInstance SoftwareLicensingService Write-Host "[*] 安装密钥(尾号 $last5)..." Invoke-CimMethod -InputObject $svc -MethodName InstallProductKey -Arguments @{ ProductKey = $key } | Out-Null Invoke-CimMethod -InputObject $svc -MethodName RefreshLicenseStatus | Out-Null $prod = Get-CimInstance SoftwareLicensingProduct -Filter "ApplicationID='$AppId' AND PartialProductKey='$last5'" | Select-Object -First 1 if (-not $prod) { throw "密钥已安装,但没有找到对应的 $Label 产品。" } Write-Host "[*] 在线激活:$($prod.Name)" Invoke-CimMethod -InputObject $prod -MethodName Activate | Out-Null $prod = Get-CimInstance SoftwareLicensingProduct -Filter "ID='$($prod.ID)'" $status = $StatusNames[[int]$prod.LicenseStatus] if ($prod.LicenseStatus -eq 1) { Write-Host "[√] $Label:$status" -ForegroundColor Green } else { Write-Host "[!] $Label:$status" -ForegroundColor Yellow } } catch { Show-Error $_ } finally { $key = $null } } function Test-Office { foreach ($d in "$env:ProgramFiles\Microsoft Office\Office16", "${env:ProgramFiles(x86)}\Microsoft Office\Office16") { if (Test-Path "$d\ospp.vbs") { return $true } } Write-Host '[!] 未找到 Office16 目录,请确认已安装 Office 2024 批量许可版。' -ForegroundColor Red $false } function Show-Status { Write-Host "`n[*] 正在读取授权状态..." -ForegroundColor DarkGray foreach ($p in @(@{ Label = 'Windows'; AppId = $WinAppId }, @{ Label = 'Office'; AppId = $OfficeAppId })) { $prods = @(Get-CimInstance SoftwareLicensingProduct -Filter "ApplicationID='$($p.AppId)' AND PartialProductKey IS NOT NULL") if (-not $prods) { Write-Host (" {0,-8} 未检测到" -f $p.Label) -ForegroundColor DarkGray; continue } foreach ($x in $prods) { $color = if ($x.LicenseStatus -eq 1) { 'Green' } else { 'Yellow' } Write-Host (" {0,-8} {1} 尾号 {2} " -f $p.Label, $StatusNames[[int]$x.LicenseStatus], $x.PartialProductKey) -ForegroundColor $color -NoNewline Write-Host $x.Name -ForegroundColor DarkGray } } } # 函数里改不了外层变量,用哈希表共享 token $State = @{ Token = $null } function Confirm-Token { if ($State.Token) { return $true } $sec = Read-Host 'Access token' -AsSecureString $State.Token = [Net.NetworkCredential]::new('', $sec).Password $sec.Dispose() [bool]$State.Token } try { while ($true) { Show-Status Write-Host '' Write-Host ' 1) 激活 Windows' Write-Host ' 2) 激活 Office 2024' Write-Host ' 3) 全部激活' Write-Host ' 4) 刷新状态' Write-Host ' Q) 退出' $choice = "$(Read-Host '请选择')".Trim().ToUpper() if ($choice -eq 'Q') { return } if ($choice -notin '1', '2', '3') { continue } if (-not (Confirm-Token)) { continue } if ($choice -in '1', '3') { Invoke-MakActivation 'windows' $WinAppId 'Windows' } if (($choice -in '2', '3') -and $State.Token -and (Test-Office)) { Invoke-MakActivation 'office' $OfficeAppId 'Office 2024' } Read-Host "`n按回车返回菜单" | Out-Null } } finally { $State.Token = $null } }