Skip to content

Instantly share code, notes, and snippets.

@muink
Created March 18, 2019 10:59
Show Gist options
  • Save muink/581456faac2f76beed6375321d57f59a to your computer and use it in GitHub Desktop.
Save muink/581456faac2f76beed6375321d57f59a to your computer and use it in GitHub Desktop.
windows系统重装快速离线恢复激活

windows系统重装快速离线恢复激活

这种方法的前提要求是你没有更换过主板
微软在激活系统时会读取主板上的DMI信息回传微软服务器并记录
一般只要主板UUID没有变化重装时就能直接激活
同时要保留激活时使用的Key

  1. 在旧系统中自建一个文件夹 将bak.bat放进去并执行
  2. 执行key.vbs 将自己的密钥记录下来
  3. 在新系统中将reA.bat放进之前自建的文件夹并执行
  4. 重启电脑

bak.bat

@echo off
%~1 mshta vbscript:createobject("shell.application").shellexecute("%~f0","::","","runas",1)(window.close)&exit
cd /d %~dp0
md bak >nul 2>nul
rem %windir%=%SystemDrive%\Windows

xcopy /y /o /b %windir%\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens.dat bak\
if %processor_architecture% == x86 (
	if exist "%windir%\SysWOW64" xcopy /y /o /b %windir%\SysNative\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms bak\&&ren bak\x64\
	xcopy /y /o /b %windir%\System32\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms bak\x32\
) else (
	xcopy /y /o /b %windir%\System32\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms bak\x64\
	xcopy /y /o /b %windir%\SysWOW64\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms bak\x32\
)

reA.bat

@echo off
rem X64 system redirector
if %processor_architecture% == x86 if exist "%windir%\SysWOW64" "%windir%\SysNative\cmd" /c %~f0&exit
%~1 mshta vbscript:createobject("shell.application").shellexecute("%~f0","::","","runas",1)(window.close)&exit
cd /d %~dp0

:key
echo.enter key e.g: xxxxx-xxxxx-xxxxx-xxxxx-xxxxx
set /p keys=enter your key: 
if not "%keys%"=="" slmgr -ipk %keys%

net stop sppsvc
set token_path=%windir%\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform
set pkeypath=%windir%\System32\spp\tokens\pkeyconfig
set pkey86path=%windir%\SysWOW64\spp\tokens\pkeyconfig
if %processor_architecture% == x86 goto :x86

:x64
takeown /f %token_path%\tokens.dat /a
icacls %token_path%\tokens.dat /grant administrators:F
del /f/q %token_path%\tokens.dat
xcopy /y /o /b bak\tokens.dat %token_path%\

takeown /f %pkeypath%\pkeyconfig.xrm-ms /a
icacls %pkeypath%\pkeyconfig.xrm-ms /grant administrators:F
del /f/q %pkeypath%\pkeyconfig.xrm-ms
xcopy /y /o /b bak\x64\pkeyconfig.xrm-ms %pkeypath%\

takeown /f %pkey86path%\pkeyconfig.xrm-ms /a
icacls %pkey86path%\pkeyconfig.xrm-ms /grant administrators:F
del /f/q %pkey86path%\pkeyconfig.xrm-ms
xcopy /y /o /b bak\x32\pkeyconfig.xrm-ms %pkey86path%\

goto :done
:x86
takeown /f %token_path%\tokens.dat /a
icacls %token_path%\tokens.dat /grant administrators:F
del /f/q %token_path%\tokens.dat
xcopy /y /o /b bak\tokens.dat %token_path%\

takeown /f %pkeypath%\pkeyconfig.xrm-ms /a
icacls %pkeypath%\pkeyconfig.xrm-ms /grant administrators:F
del /f/q %pkeypath%\pkeyconfig.xrm-ms
xcopy /y /o /b bak\x32\pkeyconfig.xrm-ms %pkeypath%\

:done
net start sppsvc

slui
slmgr -xpr

key.vbs

Set WshShell = CreateObject("WScript.Shell")
strMessage = "Windows key viewer"
MsgBox ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId")),0,strMessage
 
Function ConvertToKey(Key)
Const KeyOffset = 52
i = 28
Chars = "BCDFGHJKMPQRTVWXY2346789"
Do
Cur = 0
x = 14
Do
Cur = Cur * 256
Cur = Key(x + KeyOffset) + Cur
Key(x + KeyOffset) = (Cur \ 24) And 255
Cur = Cur Mod 24
x = x -1
Loop While x >= 0
i = i -1
KeyOutput = Mid(Chars, Cur + 1, 1) & KeyOutput
If (((29 - i) Mod 6) = 0) And (i <> -1) Then
i = i -1
KeyOutput = "-" & KeyOutput
End If
Loop While i >= 0
ConvertToKey = KeyOutput
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment