MAS: 激活Windows & Office 使用和原理解析

tl;dr

在 Powershell 中运行以下指令:

irm https://get.activated.win | iex

这条命令会执行在https://get.activated.win上的脚本内容。

远程执行脚本会引入可能的威胁面,强烈建议完整审查脚本内容后再执行。

代码开源在 Github: massgravel/Microsoft-Activation-Scripts

命令解析

irmInvoke-RestMethod在 Powershell 中的别名,用于向远程服务器发送一个 HTTP 请求,并将获取的内容传递给Powershell。

在这条命令中,irmhttps://get.activated.win发送了一个 HTTP GET 请求,这个网址会返回一个激活脚本的内容,并通过管道符号”|”传递给下一项,即iex

iexInvoke-Expression在 Powershell 中的别名,用于执行作为字符串输入的 Powershell 脚本或者命令。

使用

按下Win+R快捷键,输入”Powershell”后回车。

在弹出的命令提示符中,输入:

irm https://get.activated.win | iex

然后回车执行。

稍等片刻,如果出现了 UAC 弹窗,点击”是”。

如果一切顺利,你会看到一个类似以下的窗口:

你可以选择适合你的激活方式,使用键盘选择:

如果按下键盘”1″,将会使用数字许可证方式永久激活 Windows,这种方法需要联网。

如果按下键盘”2″,将会通过修改一个dll文件的方式来永久激活 Office,这种方法不需要联网。

如果按下键盘”3″,将会通过 KMS 密钥管理服务器激活 Windows 到2038年,这种方式可以激活 Windows Server,并且不需要联网。

如果按下键盘”4″,将会通过在线 KMS 方式激活 Windows 和 Office。每次激活将会续期180天,到期会自动续期,这种方式可以激活 Windows Server,且需要联网。

执行原理-外层执行器

执行器执行原理分析使用2025年1月15日快照。

当你在Powershell中输入了irm https://get.activated.win | iex时,具体发生了什么?

Powershell 会向 https://get.activated.win 发送一个 HTTP GET 请求,这会返回一个字符串形式的 Powershell 脚本,并通过管道符号 “|” 传递给 iex 执行。

首先,脚本检查当前 Powershell 是否运行在完全语言模式(LanguageMode.value__ = 0):

if ($ExecutionContext.SessionState.LanguageMode.value__ -ne 0) {
    $ExecutionContext.SessionState.LanguageMode
    Write-Host "Windows PowerShell is not running in Full Language Mode."
    Write-Host "Help - https://massgrave.dev/fix_powershell" -ForegroundColor White -BackgroundColor Blue
    return
}

如果运行在受限模式(例如 ConstrainedLanguage 模式)下,脚本会中断运行,并提示用户访问一个帮助链接https://massgrave.dev/fix_powershell

设置网络通信安全协议为TLS 1.2

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

然后,尝试从多个地点下载激活脚本MAS_AIO.cmd

$URLs = @(
    'https://raw.githubusercontent.com/massgravel/Microsoft-Activation-Scripts/37ec96504a2983a5801c43e975ab78c8f9315d2a/MAS/All-In-One-Version-KL/MAS_AIO.cmd',
    'https://dev.azure.com/massgrave/Microsoft-Activation-Scripts/_apis/git/repositories/Microsoft-Activation-Scripts/items?path=/MAS/All-In-One-Version-KL/MAS_AIO.cmd&versionType=Commit&version=37ec96504a2983a5801c43e975ab78c8f9315d2a',
    'https://git.activated.win/massgrave/Microsoft-Activation-Scripts/raw/commit/37ec96504a2983a5801c43e975ab78c8f9315d2a/MAS/All-In-One-Version-KL/MAS_AIO.cmd'
)

foreach ($URL in $URLs | Sort-Object { Get-Random }) {
    try { $response = Invoke-WebRequest -Uri $URL -UseBasicParsing; break } catch {}
}

如果下载失败且当前系统使用第三方杀毒软件,提醒用户第三方杀毒软件可能会导致下载失败:

function Check3rdAV {
    $avList = Get-CimInstance -Namespace root\SecurityCenter2 -Class AntiVirusProduct | Where-Object { $_.displayName -notlike '*windows*' } | Select-Object -ExpandProperty displayName
    if ($avList) {
        Write-Host '3rd party Antivirus might be blocking the script - ' -ForegroundColor White -BackgroundColor Blue -NoNewline
        Write-Host " $($avList -join ', ')" -ForegroundColor DarkRed -BackgroundColor White
    }
}

if (-not $response) {
    Check3rdAV
    Write-Host "Failed to retrieve MAS from any of the available repositories, aborting!"
    Write-Host "Help - https://massgrave.dev/troubleshoot" -ForegroundColor White -BackgroundColor Blue
    return
}

在下载文件后,会进行完整性验证。

预定义下载脚本的哈希值:

$releaseHash = '49CE81C583C69AC739890D2DFBB908BDD67B862702DAAEBCD2D38F1DDCEE863D'

初始化内存流,将脚本内容写入内存流:

$stream = New-Object IO.MemoryStream
$writer = New-Object IO.StreamWriter $stream
$writer.Write($response)
$writer.Flush()
$stream.Position = 0

计算 SHA-256 哈希值:

$hash = [BitConverter]::ToString([Security.Cryptography.SHA256]::Create().ComputeHash($stream)) -replace '-'

如果无法匹配,警告用户并中止脚本运行:

if ($hash -ne $releaseHash) {
    Write-Warning "Hash ($hash) mismatch, aborting!`nReport this issue at https://massgrave.dev/troubleshoot"
    $response = $null
    return
}

检查 CMD(命令提示符) Autorun注册表项是否存在,这定义了 CMD 启动时需要自动执行的命令。如果存在,这可能会干扰脚本的运行。

$paths = "HKCU:\SOFTWARE\Microsoft\Command Processor", "HKLM:\SOFTWARE\Microsoft\Command Processor"
foreach ($path in $paths) { 
    if (Get-ItemProperty -Path $path -Name "Autorun" -ErrorAction SilentlyContinue) { 
        Write-Warning "Autorun registry found, CMD may crash! `nManually copy-paste the below command to fix...`nRemove-ItemProperty -Path '$path' -Name 'Autorun'"
    } 
}

脚本如果检查到有 Autorun 项目,警告用户这可能会导致脚本执行错误:

Autorun registry found, CMD may crash!
Manually copy-paste the below command to fix…
Remove-ItemProperty -Path ‘$path’ -Name ‘Autorun’

生成随机GUID,以字符串格式,这个 GUID 将会作为保存文件的文件名:

$rand = [Guid]::NewGuid().Guid

检查当前用户是否有管理员权限:

$isAdmin = [bool]([Security.Principal.WindowsIdentity]::GetCurrent().Groups -match 'S-1-5-32-544')

如果有管理员权限,将远程下载的脚本保存在”$env:SystemRoot\Temp\MAS_$rand.cmd”;否则,保存在”$env:USERPROFILE\AppData\Local\Temp\MAS_$rand.cmd”:

$FilePath = if ($isAdmin) { "$env:SystemRoot\Temp\MAS_$rand.cmd" } else { "$env:USERPROFILE\AppData\Local\Temp\MAS_$rand.cmd" }

将下载的MAS_AIO.cmd内容写入到先前定义的保存路径:

Set-Content -Path $FilePath -Value "@::: $rand `r`n$response"

检查是否成功写入,定义CheckFile函数:

function CheckFile { 
    param ([string]$FilePath) 
    if (-not (Test-Path $FilePath)) { 
        Check3rdAV
        Write-Host "Failed to create MAS file in temp folder, aborting!"
        Write-Host "Help - https://massgrave.dev/troubleshoot" -ForegroundColor White -BackgroundColor Blue
        throw 
    } 
}

CheckFile $FilePath

使用 CMD 执行保存的脚本:

$env:ComSpec = "$env:SystemRoot\system32\cmd.exe"
Start-Process -FilePath $env:ComSpec -ArgumentList "/c """"$FilePath"" $args""" -Wait
CheckFile $FilePath

最后,清除产生的临时文件:

$FilePaths = @("$env:SystemRoot\Temp\MAS.cmd", "$env:USERPROFILE\AppData\Local\Temp\MAS.cmd")
foreach ($FilePath in $FilePaths) { Get-Item $FilePath | Remove-Item }

执行原理-内层激活脚本-HWID部分

激活脚本原理分析使用2025年1月15日快照。

内层激活脚本有许多安全保护和为了防止执行环境变换导致执行失败的预定义,在研究执行原理时,我们将仅关注核心执行脚本。

检测当前系统所能使用的所有密钥并安装它:

::  Detect Key

set key=
set altkey=
set changekey=
set altapplist=
set altedition=
set notworking=

call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
if defined allapps call :hwiddata key
if not defined key (
for /f "delims=" %%a in ('%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':getactivationid\:.*';iex ($f[1])"') do (set altapplist=%%a)
if defined altapplist call :hwiddata key
)

if defined notworking call :hwidfallback
if not defined key call :hwidfallback

if defined altkey (set key=%altkey%&set changekey=1&set notworking=)

if defined notworking if defined notfoundaltactID (
call :dk_color %Red% "Checking Alternate Edition For HWID     [%altedition% Activation ID Not Found]"
)

if not defined key (
%eline%
echo [%winos% ^| %winbuild% ^| SKU:%osSKU%]
if not defined skunotfound (
echo This product does not support HWID activation.
echo Make sure you are using the latest version of the script.
echo If you are, then try KMS38 activation option.
set fixes=%fixes% %mas%
echo %mas%
) else (
echo Required license files not found in %SysPath%\spp\tokens\skus\
set fixes=%fixes% %mas%troubleshoot
call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
)
echo:
goto dk_done
)

if defined notworking set error=1

call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f 调用dk_actids为 Windows 操作系统激活对应的 App ID (即55c92734-d682-4d71-983e-d6ec3f16059f) 查找所有的可用的激活ID,并存储至allapps

::  Get all products Activation IDs

:dk_actids

set allapps=
if %_wmic% EQU 1 set "chkapp=for /f "tokens=2 delims==" %%a in ('"wmic path %spp% where (ApplicationID='%1') get ID /VALUE" %nul6%')"
if %_wmic% EQU 0 set "chkapp=for /f "tokens=2 delims==" %%a in ('%psc% "(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''%1''').Get()).ID ^| %% {echo ('ID='+$_)}" %nul6%')"
%chkapp% do (if defined allapps (call set "allapps=!allapps! %%a") else (call set "allapps=%%a"))

::  Check potential script crash issue when user manually installs way too many licenses for Office (length limit in variable)

if defined allapps if %1==0ff1ce15-a989-479d-af46-f275c6370663 (
set len=0
echo:!allapps!> %SystemRoot%\Temp\chklen
for %%A in (%SystemRoot%\Temp\chklen) do (set len=%%~zA)
del %SystemRoot%\Temp\chklen %nul%

if !len! GTR 6000 (
%eline%
echo Too many licenses are installed, the script may crash.
call :dk_color %Blue% "%_fixmsg%"
timeout /t 30
)
)
exit /b

如果找到了有效的allapps,调用hwiddata子进程 (以key为参数,指示搜索可用激活配置):

::  1st column = Activation ID
::  2nd column = Generic Retail/OEM/MAK Key
::  3rd column = SKU ID
::  4th column = Key part number
::  5th column = Ticket signature value. It's as it is, it's not encoded. (Check mass grave[.]dev/hwid#manual-activation to see how it's generated)
::  6th column = 1 = activation is not working (at the time of writing this), 0 = activation is working
::  7th column = Key Type
::  8th column = WMI Edition ID (For reference only)
::  9th column = Version name incase same Edition ID is used in different OS versions with different key
::  Separator  = _


:hwiddata

set f=
for %%# in ( ... ) do (
for /f "tokens=1-9 delims=_" %%A in ("%%#") do (

REM Detect key

if %1==key if %osSKU%==%%C if not defined key (
echo "!allapps! !altapplist!" | find /i "%%A" %nul1% && (
if %%F==1 set notworking=1
set key=%%B
)
)

REM Generate ticket

if %1==ticket if "%key%"=="%%B" (
set "string=OSMajorVersion=5;OSMinorVersion=1;OSPlatformId=2;PP=0;Pfn=Microsoft.Windows.%%C.%%D_8wekyb3d8bbwe;PKeyIID=465145217131314304264339481117862266242033457260311819664735280;$([char]0)"
for /f "tokens=* delims=" %%i in ('%psc% [conv%f%ert]::ToBas%f%e64String([Text.En%f%coding]::Uni%f%code.GetBytes("""!string!"""^)^)') do set "encoded=%%i"
echo "!encoded!" | find "AAAA" %nul1% || exit /b

<nul set /p "=<?xml version="1.0" encoding="utf-8"?><genuineAuthorization xmlns="http://www.microsoft.com/DRM/SL/GenuineAuthorization/1.0"><version>1.0</version><genuineProperties origin="sppclient"><properties>OA3xOriginalProductId=;OA3xOriginalProductKey=;SessionId=!encoded!;TimeStampClient=2022-10-11T12:00:00Z</properties><signatures><signature name="clientLockboxKey" method="rsa-sha256">%%E=</signature></signatures></genuineProperties></genuineAuthorization>" >"%tdir%\GenuineTicket"
)

)
)
exit /b

for %%# in ( ... )内含多个预设的激活信息串,每一串通过_分割为9个字段,每个字段包含以下信息:

  • 激活 ID
  • 密钥
  • 产品 ID
  • 密钥部件码
  • 密钥签名值
  • 激活状态,0表示可激活,1表示不可激活
  • 密钥类型
  • WMI 版本名称
  • 版本名称拓展 (可选,用于区分可能的激活语言)

例如,对于其中一个字串:

8b351c9c-f398-4515-9900-09df49427262_XGVPP-NMH47-7TTHJ-W3FW7-8H%f%V2C___4_X19-99683_HGNKjkKcKQHO6n8srMUrDh/MElffBZarLqCMD9rWtgFKf3YzYOLDPEMGhuO/auNMKCeiU7ebFbQALS/MyZ7TvidMQ2dvzXeXXKzPBjfwQx549WJUU7qAQ9Txg9cR9SAT8b12Pry2iBk+nZWD9VtHK3kOnEYkvp5WTCTsrSi6Re4_0_OEM:NONSLP_Enterprise

这一字串对应的激活信息如下:

  • 激活 ID:8b351c9c-f398-4515-9900-09df49427262,这是一个用于标识此次激活请求的唯一GUID。
  • 密钥:XGVPP-NMH47-7TTHJ-W3FW7-8H%f%V2C,这是产品密钥。
  • 产品ID:4,表明这是企业版激活。
  • 密钥部件码:X19-99683,这是该密钥的唯一部件号码。
  • 密钥签名值:HGNKjkKcKQHO6n8srMUrDh/MElffBZarLqCMD9rWtgFKf3YzYOLDPEMGhuO/auNMKCeiU7ebFbQALS/MyZ7TvidMQ2dvzXeXXKzPBjfwQx549WJUU7qAQ9Txg9cR9SAT8b12Pry2iBk+nZWD9VtHK3kOnEYkvp5WTCTsrSi6Re4,这是密钥的摘要签名,为了确保激活数据未经篡改。
  • 激活状态:0,表示密钥是可激活的。
  • 密钥类型:OEM:NONSLP,表明这个密钥是为OEM提供的,且并未使用SLP (System Locked Pre-Installation 预装系统锁定) 绑定。
  • WMI 版本名称:Enterprise,一个用户友好的名称,表明这是企业版的激活信息。
  • 版本名称拓展:无,这是为了区分可能的激活语言的标识,这是一个可选项目。

执行hwiddata key会尝试将所有的激活配置的产品ID字段与系统的SKU号码匹配 (即 if %osSKU%==%%C),如果有成功的匹配,将激活密钥写入key变量中以准备激活。

在查找到可用的适用于当前系统的密钥后,准备安装密钥:

::  Install key

echo:
if defined changekey (
call :dk_color %Blue% "[%altedition%] edition product key will be used to enable HWID activation."
echo:
)

if defined winsub (
call :dk_color %Blue% "Windows Subscription [SKU ID-%slcSKU%] detected. Script will activate base edition [SKU ID-%regSKU%]."
echo:
)

call :dk_inskey "[%key%]"

这会调用dk_inskey子进程安装密钥key

::  Install Key

:dk_inskey

if %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call InstallProductKey ProductKey="%key%" %nul%
if %_wmic% EQU 0 %psc% "try { $null=(([WMISEARCHER]'SELECT Version FROM %sps%').Get()).InstallProductKey('%key%'); exit 0 } catch { exit $_.Exception.InnerException.HResult }" %nul%
set keyerror=%errorlevel%
cmd /c exit /b %keyerror%
if %keyerror% NEQ 0 set "keyerror=[0x%=ExitCode%]"

if %keyerror% EQU 0 (
if %sps%==SoftwareLicensingService call :dk_refresh
echo Installing Generic Product Key          %~1 [Successful]
) else (
call :dk_color %Red% "Installing Generic Product Key          %~1 [Failed] %keyerror%"
if not defined error (
if defined altapplist call :dk_color %Red% "Activation ID not found for this key."
call :dk_color %Blue% "%_fixmsg%"
set showfix=1
)
set error=1
)

exit /b

dk_inskey使用wmic或者Powershell执行密钥安装,将key变量对应的值安装为Windows 激活密钥。

如果电脑拥有wmic服务 (Windows Management Instrumentation Command-line),脚本会执行:

wmic path %sps% where __CLASS='%sps%' call InstallProductKey ProductKey="%key%" %nul%

具体地:

  • spsSoftwareLicensingService,即使用软件激活服务执行InstallProductKey ProductKey="%key%"命令
  • InstallProductKey ProductKey="%key%"指示激活服务安装key变量指定的产品激活密钥

如果电脑没有wmic服务,脚本会用Powershell达到类似的目的。

安装密钥后,将 Windows 区域临时地更改到美国以规避 Windows Store 许可在许多国家无法激活的问题:

::  Change Windows region to USA to avoid activation issues as Windows store license is not available in many countries 

for /f "skip=2 tokens=2*" %%a in ('reg query "HKCU\Control Panel\International\Geo" /v Name %nul6%') do set "name=%%b"
for /f "skip=2 tokens=2*" %%a in ('reg query "HKCU\Control Panel\International\Geo" /v Nation %nul6%') do set "nation=%%b"

set regionchange=
if not "%name%"=="US" (
set regionchange=1
%psc% "Set-WinHomeLocation -GeoId 244" %nul%
if !errorlevel! EQU 0 (
echo Changing Windows Region To USA          [Successful]
) else (
call :dk_color %Red% "Changing Windows Region To USA          [Failed]"
)
)

随后,构造GenuineTicket.xml正版激活配置文件:

::  Generate GenuineTicket.xml and apply
::  In some cases clipup -v -o method fails and in some cases service restart method fails as well
::  To maximize success rate and get better error details, script will install tickets two times (service restart + clipup -v -o)

set "tdir=%ProgramData%\Microsoft\Windows\ClipSVC\GenuineTicket"
if not exist "%tdir%\" md "%tdir%\" %nul%

if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%
if exist "%tdir%\*.xml" del /f /q "%tdir%\*.xml" %nul%
if exist "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*" del /f /q "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*" %nul%

call :hwiddata ticket

copy /y /b "%tdir%\GenuineTicket" "%tdir%\GenuineTicket.xml" %nul%

if not exist "%tdir%\GenuineTicket.xml" (
call :dk_color %Red% "Generating GenuineTicket.xml            [Failed, aborting...]"
echo [%encoded%]
if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%
goto :dl_final
) else (
echo Generating GenuineTicket.xml            [Successful]
)

这会调用hwiddata ticket

hwiddata会找到先前已定义的产品密钥对应的条目,并构建硬件ID数据的字符串形式:

set "string=OSMajorVersion=5;OSMinorVersion=1;OSPlatformId=2;PP=0;Pfn=Microsoft.Windows.%%C.%%D_8wekyb3d8bbwe;PKeyIID=465145217131314304264339481117862266242033457260311819664735280;$([char]0)"

将其转换为base64编码:

for /f "tokens=* delims=" %%i in ('%psc% [conv%f%ert]::ToBas%f%e64String([Text.En%f%coding]::Uni%f%code.GetBytes("""!string!"""^)^)') do set "encoded=%%i"

检查编码结果是否包含”AAAA”子串,如果没有,则认为生成的base64编码不符合预期,立刻退出执行:

echo "!encoded!" | find "AAAA" %nul1% || exit /b

构造GenuineTicket.xml内容,并写入到工作目录下GenuineTicket

<nul set /p "=<?xml version="1.0" encoding="utf-8"?><genuineAuthorization xmlns="http://www.microsoft.com/DRM/SL/GenuineAuthorization/1.0"><version>1.0</version><genuineProperties origin="sppclient"><properties>OA3xOriginalProductId=;OA3xOriginalProductKey=;SessionId=!encoded!;TimeStampClient=2022-10-11T12:00:00Z</properties><signatures><signature name="clientLockboxKey" method="rsa-sha256">%%E=</signature></signatures></genuineProperties></genuineAuthorization>" >"%tdir%\GenuineTicket"

hwiddata ticket执行完毕,将生成的GenuineTicket文件覆盖复制为GenuineTicket.xml

copy /y /b "%tdir%\GenuineTicket" "%tdir%\GenuineTicket.xml" %nul%

在完成了对GenuineTicket.xml的构建后,准备安装GenuineTicket.xml

set "_xmlexist=if exist "%tdir%\GenuineTicket.xml""

%_xmlexist% (
%psc% "Start-Job { Restart-Service ClipSVC } | Wait-Job -Timeout 20 | Out-Null"
%_xmlexist% timeout /t 2 %nul%
%_xmlexist% timeout /t 2 %nul%

%_xmlexist% (
set error=1
if exist "%tdir%\*.xml" del /f /q "%tdir%\*.xml" %nul%
call :dk_color %Gray% "Installing GenuineTicket.xml            [Failed with ClipSVC service restart, wait...]"
)
)

copy /y /b "%tdir%\GenuineTicket" "%tdir%\GenuineTicket.xml" %nul%
clipup -v -o

set rebuildinfo=

if not exist %ProgramData%\Microsoft\Windows\ClipSVC\tokens.dat (
set error=1
set rebuildinfo=1
call :dk_color %Red% "Checking ClipSVC tokens.dat             [Not Found]"
)

%_xmlexist% (
set error=1
set rebuildinfo=1
call :dk_color %Red% "Installing GenuineTicket.xml            [Failed With clipup -v -o]"
)

if exist "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*.xml" (
set error=1
set rebuildinfo=1
call :dk_color %Red% "Checking Ticket Migration               [Failed]"
)

if not defined altapplist if not defined showfix if defined rebuildinfo (
set showfix=1
call :dk_color %Blue% "%_fixmsg%"
)

if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%

由于ClipSVC方法和clipup方法都有概率失败,使用多种方法尝试将构建的GenuineTicket.xml应用到系统中以最大化成功概率:

方法一:重启ClipSVC服务:

%_xmlexist% (
    %psc% "Start-Job { Restart-Service ClipSVC } | Wait-Job -Timeout 20 | Out-Null"
    %_xmlexist% timeout /t 2 %nul%
    %_xmlexist% timeout /t 2 %nul%

    %_xmlexist% (
        set error=1
        if exist "%tdir%\*.xml" del /f /q "%tdir%\*.xml" %nul%
        call :dk_color %Gray% "Installing GenuineTicket.xml [Failed with ClipSVC service restart, wait...]"
    )
)

方法二:使用clipup

clipup -v -o

检查系统的tokens.dat是否存在:

set rebuildinfo=

if not exist %ProgramData%\Microsoft\Windows\ClipSVC\tokens.dat (
    set error=1
    set rebuildinfo=1
    call :dk_color %Red% "Checking ClipSVC tokens.dat [Not Found]"
)

%_xmlexist% (
    set error=1
    set rebuildinfo=1
    call :dk_color %Red% "Installing GenuineTicket.xml [Failed With clipup -v -o]"
)

如果不存在,打印错误信息。

检查是否存在与许可证迁移相关的.xml文件:

if exist "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*.xml" (
    set error=1
    set rebuildinfo=1
    call :dk_color %Red% "Checking Ticket Migration [Failed]"
)

如果存在,打印错误信息。

最后,清除临时文件:

if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%

检查激活状态:

call :dk_product

echo:
echo Activating...

call :dk_act
call :dk_checkperm
if defined _perm (
echo:
call :dk_color %Green% "%winos% is permanently activated with a digital license."
goto :dl_final
)

如果激活成功,进入收尾阶段:

:dl_final

echo:

if defined regionchange (
%psc% "Set-WinHomeLocation -GeoId %nation%" %nul%
if !errorlevel! EQU 0 (
echo Restoring Windows Region                [Successful]
) else (
call :dk_color %Red% "Restoring Windows Region                [Failed] [%name% - %nation%]"
)
)

REM if %osSKU%==175 call :dk_color %Red% "%winos% does not support activation on non-azure platforms."

::  Trigger reevaluation of SPP's Scheduled Tasks

if defined _perm (
call :dk_reeval %nul%
)
goto :dk_done

如果在激活中临时修改了Windows地区,将会在这里更改回来:

if defined regionchange (
%psc% "Set-WinHomeLocation -GeoId %nation%" %nul%
if !errorlevel! EQU 0 (
echo Restoring Windows Region                [Successful]
) else (
call :dk_color %Red% "Restoring Windows Region                [Failed] [%name% - %nation%]"
)
)

如果已经成功永久激活Windows,尝试修复一些sppsvc有时候由于无法删除注册表项而导致的问题:

::  Trigger reevaluation, it helps in updating SPP tasks

:dk_reeval

::  This key is left by the system in rearm process and sppsvc sometimes fails to delete it, it causes issues in working of the Scheduled Tasks of SPP

set "ruleskey=HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\PersistedSystemState"
reg delete "%ruleskey%" /v "State" /f %nul%
reg delete "%ruleskey%" /v "SuppressRulesEngine" /f %nul%

set r1=$TB = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0);
set r2=%r1% [void]$TB.DefinePInvokeMethod('SLpTriggerServiceWorker', 'sppc.dll', 22, 1, [Int32], @([UInt32], [IntPtr], [String], [UInt32]), 1, 3);
set d1=%r2% [void]$TB.CreateType()::SLpTriggerServiceWorker(0, 0, 'reeval', 0)
%psc% "Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null; %d1%"
exit /b

最后,打印收尾信息:

:dk_done

echo:
if %_unattended%==1 timeout /t 2 & exit /b

if defined fixes (
call :dk_color %White% "Follow ALL the ABOVE blue lines.   "
call :dk_color2 %Blue% "Press [1] to Open Support Webpage " %Gray% " Press [0] to Ignore"
choice /C:10 /N
if !errorlevel!==1 (for %%# in (%fixes%) do (start %%#))
)

if defined terminal (
call :dk_color %_Yellow% "Press [0] key to %_exitmsg%..."
choice /c 0 /n
) else (
call :dk_color %_Yellow% "Press any key to %_exitmsg%..."
pause %nul1%
)

exit /b
暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇