Snippet content copied to clipboard.
Are you sure to delete this snippet? No, don't delete

MAS_AIO Edited

  1. @::Please stop false-flagging this script over and over. This is the 3rd time I've had to update the script to deal with the false positives.
  2. @::Nothing in this script is malicious and it is used by thousands of people *daily*.
  3. @::Is a real person even the one deciding to flag this or is it Copilot told to flag anything it decides not to like?
  4. @::If a campaign is using this script as a cover, please flag parts of the campaign instead of the script. This isn't the first time we experienced collateral damage due to campaigns completely unrelated to us.
  5. @::If you disagree that MAS is not malicious, we would appreciate if you contacted us to explain what constitutes MAS as "Sonbokli" and we'll look into it. Thank you.
  6. @set masver=3.10
  7. @setlocal DisableDelayedExpansion
  8. @echo off
  9. ​
  10. ​
  11. ​
  12. :: For command line switches, check m{}assgrave{dot}dev/command_line_switches
  13. :: If you want to better understand script, read from separate files version.
  14. ​
  15. ​
  16. ​
  17. ::============================================================================
  18. ::
  19. :: Homepage: m{}assgrave{dot}dev
  20. ::
  21. ::============================================================================
  22. ​
  23. ​
  24. ​
  25. ::========================================================================================================================================
  26. ​
  27. :: Set environment variables, it helps if they are misconfigured in the system
  28. ​
  29. setlocal EnableExtensions
  30. setlocal DisableDelayedExpansion
  31. ​
  32. set "PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
  33. ​
  34. set "SysPath=%SystemRoot%\System32"
  35. set "Path=%SystemRoot%\System32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\"
  36. if exist "%SystemRoot%\Sysnative\reg.exe" (
  37. set "SysPath=%SystemRoot%\Sysnative"
  38. set "Path=%SystemRoot%\Sysnative;%SystemRoot%;%SystemRoot%\Sysnative\Wbem;%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\;%Path%"
  39. )
  40. ​
  41. set "ComSpec=%SysPath%\cmd.exe"
  42. set "PSModulePath=%ProgramFiles%\WindowsPowerShell\Modules;%SysPath%\WindowsPowerShell\v1.0\Modules"
  43. ​
  44. set re1=
  45. set re2=
  46. set "_cmdf=%~f0"
  47. for %%# in (%*) do (
  48. if /i "%%#"=="re1" set re1=1
  49. if /i "%%#"=="re2" set re2=1
  50. if /i "%%#"=="-qedit" (set re1=1&set re2=1)
  51. )
  52. ​
  53. :: Re-launch the script with x64 process if it was initiated by x86 process on x64 bit Windows
  54. :: or with ARM64 process if it was initiated by x86/ARM32 process on ARM64 Windows
  55. ​
  56. if exist %SystemRoot%\Sysnative\cmd.exe if not defined re1 (
  57. setlocal EnableDelayedExpansion
  58. start %SystemRoot%\Sysnative\cmd.exe /c ""!_cmdf!" %* re1"
  59. exit /b
  60. )
  61. ​
  62. :: Re-launch the script with ARM32 process if it was initiated by x64 process on ARM64 Windows
  63. ​
  64. if exist %SystemRoot%\SysArm32\cmd.exe if %PROCESSOR_ARCHITECTURE%==AMD64 if not defined re2 (
  65. setlocal EnableDelayedExpansion
  66. start %SystemRoot%\SysArm32\cmd.exe /c ""!_cmdf!" %* re2"
  67. exit /b
  68. )
  69. ​
  70. ::========================================================================================================================================
  71. ​
  72. set "blank="
  73. set "mas="
  74. set "github="
  75. set "selfgit="
  76. ​
  77. :: Check if Null service is working, it's important for the batch script
  78. ​
  79. sc query Null | find /i "RUNNING"
  80. if %errorlevel% NEQ 0 (
  81. echo:
  82. echo Null service is not running, script may crash...
  83. echo:
  84. echo:
  85. echo Check this webpage for help - %mas%fix_service
  86. echo:
  87. echo:
  88. ping 127.0.0.1 -n 20
  89. )
  90. cls
  91. ​
  92. :: Check LF line ending
  93. ​
  94. pushd "%~dp0"
  95. >nul findstr /v "$" "%~nx0" && (
  96. echo:
  97. echo Error - Script either has LF line ending issue or an empty line at the end of the script is missing.
  98. echo:
  99. echo:
  100. echo Check this webpage for help - %mas%troubleshoot
  101. echo:
  102. echo:
  103. ping 127.0.0.1 -n 20 >nul
  104. popd
  105. exit /b
  106. )
  107. popd
  108. ​
  109. ::========================================================================================================================================
  110. ​
  111. cls
  112. color 07
  113. title Microsoft_Activation_Scripts %masver%
  114. ​
  115. set _args=
  116. set _elev=
  117. set _unattended=0
  118. ​
  119. set _args=%*
  120. if defined _args set _args=%_args:"=%
  121. if defined _args set _args=%_args:re1=%
  122. if defined _args set _args=%_args:re2=%
  123. if defined _args (
  124. for %%A in (%_args%) do (
  125. if /i "%%A"=="-el" set _elev=1
  126. )
  127. )
  128. ​
  129. if defined _args echo "%_args%" | find /i "/" >nul && set _unattended=1
  130. ​
  131. ::========================================================================================================================================
  132. ​
  133. set "nul1=1>nul"
  134. set "nul2=2>nul"
  135. set "nul6=2^>nul"
  136. set "nul=>nul 2>&1"
  137. ​
  138. call :dk_setvar
  139. ​
  140. if %winbuild% EQU 1 (
  141. %eline%
  142. echo Failed to detect Windows build number.
  143. echo:
  144. setlocal EnableDelayedExpansion
  145. set fixes=%fixes% %mas%troubleshoot
  146. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  147. goto dk_done
  148. )
  149. ​
  150. if exist "%Systemdrive%\Users\WDAGUtilityAccount" (
  151. sc query gcs | find /i "RUNNING" %nul% && (
  152. %eline%
  153. echo Windows Sandbox detected; activation is not supported.
  154. echo The script cannot run due to missing licensing components. Aborting...
  155. echo:
  156. goto dk_done
  157. )
  158. )
  159. ​
  160. if %winbuild% LSS 6001 (
  161. %nceline%
  162. echo Unsupported OS version detected [%winbuild%].
  163. echo MAS only supports Windows Vista/7/8/8.1/10/11 and their Server equivalents.
  164. if %winbuild% EQU 6000 (
  165. echo:
  166. echo Windows Vista RTM is not supported because Powershell cannot be installed.
  167. echo Upgrade to Windows Vista SP1 or SP2.
  168. )
  169. goto dk_done
  170. )
  171. ​
  172. if %winbuild% LSS 7600 if not exist "%SysPath%\WindowsPowerShell\v1.0\Modules" (
  173. %nceline%
  174. if not exist %ps% (
  175. echo PowerShell is not installed in your system.
  176. )
  177. echo Install PowerShell 2.0 using the following URL.
  178. echo:
  179. echo https://www.catalog.update.microsoft.com/Search.aspx?q=KB968930
  180. if %_unattended%==0 start https://www.catalog.update.microsoft.com/Search.aspx?q=KB968930
  181. goto dk_done
  182. )
  183. ​
  184. ::========================================================================================================================================
  185. ​
  186. :: Fix special character limitations in path name
  187. ​
  188. set "_work=%~dp0"
  189. if "%_work:~-1%"=="\" set "_work=%_work:~0,-1%"
  190. ​
  191. set "_batf=%~f0"
  192. set "_batp=%_batf:'=''%"
  193. ​
  194. set _PSarg="""%~f0""" -el %_args%
  195. set _PSarg=%_PSarg:'=''%
  196. ​
  197. set "_ttemp=%userprofile%\AppData\Local\Temp"
  198. ​
  199. setlocal EnableDelayedExpansion
  200. ​
  201. ::========================================================================================================================================
  202. ​
  203. echo "!_batf!" | find /i "!_ttemp!" %nul1% && (
  204. if /i not "!_work!"=="!_ttemp!" (
  205. %eline%
  206. echo The script was launched from the temp folder.
  207. echo You are most likely running the script directly from the archive file.
  208. echo:
  209. echo Extract the archive file and launch the script from the extracted folder.
  210. goto dk_done
  211. )
  212. )
  213. ​
  214. ::========================================================================================================================================
  215. ​
  216. :: Elevate script as admin and pass arguments and preventing loop
  217. ​
  218. %nul1% fltmc || (
  219. if not defined _elev %psc% "start cmd.exe -arg '/c \"!_PSarg!\"' -verb runas" && exit /b
  220. %eline%
  221. echo This script needs admin rights.
  222. echo Right click on this script and select 'Run as administrator'.
  223. goto dk_done
  224. )
  225. ​
  226. ::========================================================================================================================================
  227. ​
  228. :: Check PowerShell
  229. ​
  230. :: Query the language mode directly; no self-reading or dynamic code is needed for this test.
  231. for /f "delims=" %%a in ('%psc% "if ($PSVersionTable.PSEdition -ne 'Core') {$ExecutionContext.SessionState.LanguageMode}" %nul6%') do (set tstresult=%%a)
  232. ​
  233. if /i not "%tstresult%"=="FullLanguage" (
  234. %eline%
  235. for /f "delims=" %%a in ('%psc% "$ExecutionContext.SessionState.LanguageMode" %nul6%') do (set tstresult2=%%a)
  236. echo Test 1 - %tstresult%
  237. echo Test 2 - !tstresult2!
  238. echo:
  239. ​
  240. REM check LanguageMode
  241. ​
  242. echo: !tstresult2! | findstr /i "ConstrainedLanguage RestrictedLanguage NoLanguage" %nul1% && (
  243. echo FullLanguage mode not found in PowerShell. Aborting...
  244. echo If you have applied restrictions on Powershell then undo those changes.
  245. set fixes=%fixes% %mas%fix_powershell
  246. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%fix_powershell"
  247. goto dk_done
  248. )
  249. ​
  250. REM check Powershell core version
  251. ​
  252. cmd /c "%psc% "$PSVersionTable.PSEdition"" | find /i "Core" %nul1% && (
  253. echo Windows Powershell is needed for MAS but it seems to be replaced with Powershell core. Aborting...
  254. set fixes=%fixes% %mas%in-place_repair_upgrade
  255. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%in-place_repair_upgrade"
  256. goto dk_done
  257. )
  258. ​
  259. REM check for Mal-ware that may cause issues with Powershell
  260. ​
  261. for /r "%ProgramFiles%\" %%f in (secureboot.exe) do if exist "%%f" (
  262. echo "%%f"
  263. echo Mal%blank%ware found, PowerShell is not working properly.
  264. set fixes=%fixes% %mas%remove_mal%w%ware
  265. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%remove_mal%w%ware"
  266. goto dk_done
  267. )
  268. ​
  269. REM check if .NET is working properly
  270. ​
  271. if /i "!tstresult2!"=="FullLanguage" (
  272. cmd /c "%psc% ""try {[System.AppDomain]::CurrentDomain.GetAssemblies(); [System.Math]::Sqrt(144)} catch {Exit 3}""" %nul%
  273. if !errorlevel!==3 (
  274. echo Windows Powershell failed to load .NET command. Aborting...
  275. set fixes=%fixes% %mas%in-place_repair_upgrade
  276. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%in-place_repair_upgrade"
  277. goto dk_done
  278. )
  279. )
  280. ​
  281. REM check antivirus and other errors
  282. ​
  283. echo PowerShell is not working properly. Aborting...
  284. ​
  285. if /i "!tstresult2!"=="FullLanguage" (
  286. echo:
  287. echo Your antivirus software might be blocking the script.
  288. echo:
  289. sc query sense | find /i "RUNNING" %nul% && (
  290. echo Installed Antivirus - Microsoft Defender for Endpoint
  291. )
  292. cmd /c "%psc% ""$av = Get-WmiObject -Namespace root\SecurityCenter2 -Class AntiVirusProduct; $n = @(); foreach ($i in $av) { $n += $i.displayName }; if ($n) { Write-Host ('Installed Antivirus - ' + ($n -join ', '))}"""
  293. )
  294. ​
  295. set fixes=%fixes% %mas%troubleshoot
  296. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  297. goto dk_done
  298. )
  299. ​
  300. ::========================================================================================================================================
  301. ​
  302. :: Disable QuickEdit and launch from conhost.exe to avoid Terminal app
  303. ​
  304. if %winbuild% GEQ 17763 (
  305. set terminal=1
  306. ) else (
  307. set terminal=
  308. )
  309. ​
  310. :: Check if script is running in Terminal app
  311. ​
  312. if defined terminal (
  313. set lines=0
  314. for /f "skip=3 tokens=* delims=" %%A in ('mode con') do if "!lines!"=="0" (
  315. for %%B in (%%A) do set lines=%%B
  316. )
  317. if !lines! GEQ 100 set terminal=
  318. )
  319. ​
  320. if %_unattended%==1 goto :skipQE
  321. for %%# in (%_args%) do (if /i "%%#"=="-qedit" goto :skipQE)
  322. ​
  323. :: Relaunch to disable QuickEdit in the current session and use conhost.exe instead of the Terminal app
  324. :: This code disables QuickEdit for the current cmd.exe session without making permanent registry changes
  325. :: It is included because clicking on the script window can pause execution, causing confusion that the script has stopped due to an error
  326. ​
  327. set resetQE=1
  328. reg query HKCU\Console /v QuickEdit %nul2% | find /i "0x0" %nul1% && set resetQE=0
  329. reg add HKCU\Console /v QuickEdit /t REG_DWORD /d 0 /f %nul1%
  330. ​
  331. if defined terminal (
  332. start conhost.exe "!_batf!" %_args% -qedit
  333. start reg add HKCU\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%
  334. exit /b
  335. ) else if %resetQE% EQU 1 (
  336. start cmd.exe /c ""!_batf!" %_args% -qedit"
  337. start reg add HKCU\Console /v QuickEdit /t REG_DWORD /d %resetQE% /f %nul1%
  338. exit /b
  339. )
  340. ​
  341. :skipQE
  342. ​
  343. ​
  344. ::========================================================================================================================================
  345. ​
  346. if not exist "%SystemRoot%\Temp\" mkdir "%SystemRoot%\Temp" %nul%
  347. ​
  348. :: Run script with parameters in unattended mode
  349. ​
  350. set _elev=
  351. if defined _args echo "%_args%" | find /i "/S" %nul% && (set "_silent=%nul%") || (set _silent=)
  352. if defined _args echo "%_args%" | find /i "/K-" %nul% && (echo Online KMS options were removed from this build. & exit /b 2)
  353. if defined _args echo "%_args%" | find /i "/" %nul% && (
  354. echo "%_args%" | find /i "/HWID" %nul% && (setlocal & cls & (call :HWIDActivation %_args% %_silent%) & endlocal)
  355. echo "%_args%" | find /i "/Z-" %nul% && (setlocal & cls & (call :TSforgeActivation %_args% %_silent%) & endlocal)
  356. echo "%_args%" | find /i "/Ohook" %nul% && (setlocal & cls & (call :OhookActivation %_args% %_silent%) & endlocal)
  357. exit /b
  358. )
  359. ​
  360. ::========================================================================================================================================
  361. ​
  362. setlocal DisableDelayedExpansion
  363. ​
  364. :: Check desktop location
  365. ​
  366. set desktop=
  367. for /f "skip=2 tokens=2*" %%a in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop') do call set "desktop=%%b"
  368. if not defined desktop for /f "delims=" %%a in ('%psc% "& {write-host $([Environment]::GetFolderPath('Desktop'))}"') do call set "desktop=%%a"
  369. set "_pdesk=%desktop:'=''%"
  370. ​
  371. setlocal EnableDelayedExpansion
  372. ​
  373. if not defined desktop (
  374. %eline%
  375. echo Unable to detect Desktop location, aborting...
  376. goto dk_done
  377. )
  378. ​
  379. ::========================================================================================================================================
  380. ​
  381. :MainMenu
  382. ​
  383. cls
  384. color 07
  385. title Microsoft %blank%Activation %blank%Scripts %masver%
  386. if not defined terminal mode 76, 34
  387. ​
  388. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" set _serexist=1
  389. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-*EvalEdition~*.mum" set _evalexist=1
  390. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-EnterpriseS*dition~*.mum" set _ltscexist=1
  391. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-EnterpriseSN*dition~*.mum" set _ltscnexist=1
  392. ​
  393. if %winbuild% GEQ 10240 if not defined _serexist if not defined _evalexist set _hwidgo=1
  394. if %winbuild% GTR 14393 if defined _ltscnexist set _hwidgo=
  395. if not defined _hwidgo set _tsforgego=1
  396. ​
  397. set _ohookgo=1
  398. if %winbuild% GEQ 9200 (
  399. if %winbuild% LSS 10240 set _ohookgo=
  400. if %winbuild% GEQ 19041 if %winbuild% LEQ 19045 set _ohookgo=
  401. if defined _serexist set _ohookgo=
  402. if defined _evalexist set _ohookgo=
  403. if defined _ltscexist set _ohookgo=
  404. reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration /v ProductReleaseIds %nul2% | find /i "O365" %nul% && set _ohookgo=1
  405. reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\ClickToRun\Configuration /v ProductReleaseIds %nul2% | find /i "O365" %nul% && set _ohookgo=1
  406. )
  407. if not defined _ohookgo set _tsforgego=1
  408. ​
  409. echo:
  410. echo:
  411. echo:
  412. if %winbuild% GEQ 10240 if %winbuild% LEQ 19045 if not defined _serexist if not defined _evalexist if not defined _ltscexist (
  413. call :dk_color2 %_Green% " Tip:" %_White% " To activate ESU updates after W10 EOL, use TSforge option."
  414. )
  415. echo:
  416. echo:
  417. echo: ______________________________________________________________
  418. echo:
  419. echo: Activation Methods:
  420. echo:
  421. if defined _hwidgo (
  422. call :dk_color3 %_White% " [1] " %_Green% "HWID" %_White% " - Windows"
  423. ) else (
  424. echo: [1] HWID - Windows
  425. )
  426. if defined _ohookgo (
  427. call :dk_color3 %_White% " [2] " %_Green% "Ohook" %_White% " - Office"
  428. ) else (
  429. echo: [2] Ohook - Office
  430. )
  431. if defined _tsforgego (
  432. call :dk_color3 %_White% " [3] " %_Green% "TSforge" %_White% " - Windows / Office / ESU"
  433. ) else (
  434. echo: [3] TSforge - Windows / Office / ESU
  435. )
  436. echo: __________________________________________________
  437. echo:
  438. echo: [5] Check Activation Status
  439. echo: [6] Change Windows Edition
  440. echo: [7] Change Office Edition
  441. echo: __________________________________________________
  442. echo:
  443. echo: [8] Troubleshoot
  444. echo: [E] Extras
  445. echo: [0] Exit
  446. echo: ______________________________________________________________
  447. echo:
  448. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard [1,2,3,5,6,7,8,E,0] :"
  449. choice /C:1235678E0 /N
  450. set _erl=%errorlevel%
  451. ​
  452. if %_erl%==9 exit /b
  453. if %_erl%==8 goto :Extras
  454. if %_erl%==7 setlocal & call :troubleshoot & cls & endlocal & goto :MainMenu
  455. if %_erl%==6 setlocal & call :change_offedition & cls & endlocal & goto :MainMenu
  456. if %_erl%==5 setlocal & call :change_winedition & cls & endlocal & goto :MainMenu
  457. if %_erl%==4 setlocal & call :check_actstatus & cls & endlocal & goto :MainMenu
  458. if %_erl%==3 setlocal & call :TSforgeActivation & cls & endlocal & goto :MainMenu
  459. if %_erl%==2 setlocal & call :OhookActivation & cls & endlocal & goto :MainMenu
  460. if %_erl%==1 setlocal & call :HWIDActivation & cls & endlocal & goto :MainMenu
  461. goto :MainMenu
  462. ​
  463. :dk_color3
  464. ​
  465. if %_NCS% EQU 1 (
  466. echo %esc%[%~1%~2%esc%[%~3%~4%esc%[%~5%~6%esc%[0m
  467. ) else (
  468. %psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'-NoNewline; write-host -back '%7' -fore '%8' '%9'
  469. )
  470. exit /b
  471. ​
  472. ::========================================================================================================================================
  473. ​
  474. :Extras
  475. ​
  476. cls
  477. title Extras
  478. if not defined terminal mode 76, 30
  479. echo:
  480. echo:
  481. echo:
  482. echo:
  483. echo:
  484. echo: ______________________________________________________
  485. echo:
  486. echo: [1] Extract $OEM$ Folder
  487. echo:
  488. echo: ____________________________________________
  489. echo:
  490. echo: [0] Go to Main Menu
  491. echo: ______________________________________________________
  492. echo:
  493. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard [1,0] :"
  494. choice /C:10 /N
  495. set _erl=%errorlevel%
  496. ​
  497. if %_erl%==2 goto :MainMenu
  498. if %_erl%==1 goto :Extract$OEM$
  499. goto :Extras
  500. ​
  501. ::========================================================================================================================================
  502. ​
  503. :Extract$OEM$
  504. ​
  505. cls
  506. title Extract $OEM$ Folder
  507. if not defined terminal mode 76, 30
  508. ​
  509. if exist "!desktop!\$OEM$\" (
  510. %eline%
  511. echo $OEM$ folder already exists on the Desktop.
  512. echo _____________________________________________________
  513. echo:
  514. call :dk_color %_Yellow% "Press [0] key to %_exitmsg%..."
  515. choice /c 0 /n
  516. goto :Extras
  517. )
  518. ​
  519. :Extract$OEM$2
  520. ​
  521. cls
  522. title Extract $OEM$ Folder
  523. if not defined terminal mode 78, 30
  524. echo:
  525. echo:
  526. echo:
  527. echo:
  528. echo: Extract $OEM$ folder on the desktop
  529. echo: ____________________________________________________________
  530. echo:
  531. echo: [1] HWID [Windows]
  532. echo: [2] Ohook [Office]
  533. echo: [3] TSforge [Windows / ESU / Office]
  534. echo:
  535. echo: [5] HWID [Windows] ^+ Ohook [Office]
  536. echo: [6] HWID [Windows] ^+ Ohook [Office] ^+ TSforge [ESU]
  537. echo: [7] TSforge [Windows / ESU] ^+ Ohook [Office]
  538. echo:
  539. echo: [0] Go Back
  540. echo: ____________________________________________________________
  541. echo:
  542. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard :"
  543. choice /C:1235670 /N
  544. set _erl=%errorlevel%
  545. ​
  546. if %_erl%==7 goto:Extras
  547. if %_erl%==6 (set "_oem=TSforge [Windows / ESU] + Ohook [Office]" & set "para=/Z-Windows /Z-ESU /Ohook" &goto:Extract$OEM$3)
  548. if %_erl%==5 (set "_oem=HWID [Windows] + Ohook [Office] + TSforge [ESU]" & set "para=/HWID /Ohook /Z-ESU" &goto:Extract$OEM$3)
  549. if %_erl%==4 (set "_oem=HWID [Windows] + Ohook [Office]" & set "para=/HWID /Ohook" &goto:Extract$OEM$3)
  550. if %_erl%==3 (set "_oem=TSforge" & set "para=/Z-WindowsESUOffice" &goto:Extract$OEM$3)
  551. if %_erl%==2 (set "_oem=Ohook" & set "para=/Ohook" &goto:Extract$OEM$3)
  552. if %_erl%==1 (set "_oem=HWID" & set "para=/HWID" &goto:Extract$OEM$3)
  553. goto :Extract$OEM$2
  554. ​
  555. ::========================================================================================================================================
  556. ​
  557. :Extract$OEM$3
  558. ​
  559. cls
  560. set "_dir=!desktop!\$OEM$\$$\Setup\Scripts"
  561. md "!_dir!\"
  562. ​
  563. :: Copy the reviewed script without randomizing its contents.
  564. copy /y "!_batf!" "!_dir!\MAS_AIO.cmd" %nul%
  565. ​
  566. (
  567. echo @echo off
  568. echo fltmc ^>nul ^|^| exit /b
  569. echo call "%%~dp0MAS_AIO.cmd" %para%
  570. echo cd \
  571. echo ^(goto^) 2^>nul ^& ^(if "%%~dp0"=="%%SystemRoot%%\Setup\Scripts\" rd /s /q "%%~dp0"^)
  572. )>"!_dir!\SetupComplete.cmd"
  573. ​
  574. set _error=
  575. if not exist "!_dir!\MAS_AIO.cmd" set _error=1
  576. if not exist "!_dir!\SetupComplete.cmd" set _error=1
  577. ​
  578. if defined _error (
  579. %eline%
  580. echo The script failed to create the $OEM$ folder.
  581. if exist "!desktop!\$OEM$\.*" rmdir /s /q "!desktop!\$OEM$\" %nul%
  582. ) else (
  583. echo:
  584. call :dk_color %Blue% "%_oem%"
  585. call :dk_color %Green% "$OEM$ folder was successfully created on your Desktop."
  586. )
  587. echo ___________________________________________________________________
  588. echo:
  589. call :dk_color %_Yellow% "Press [0] key to %_exitmsg%..."
  590. choice /c 0 /n
  591. goto Extras
  592. ​
  593. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  594. ​
  595. :HWIDActivation
  596. ​
  597. :: To activate, run the script with "/HWID" parameter or change 0 to 1 in below line
  598. set _act=0
  599. ​
  600. :: To disable changing edition if current edition doesn't support HWID activation, change the value to 1 from 0 or run the script with "/HWID-NoEditionChange" parameter
  601. set _NoEditionChange=0
  602. ​
  603. :: If value is changed in above lines or parameter is used then script will run in unattended mode
  604. ​
  605. ::========================================================================================================================================
  606. ​
  607. cls
  608. color 07
  609. title HWID Activation %masver%
  610. ​
  611. set _args=
  612. set _elev=
  613. set _unattended=0
  614. ​
  615. set _args=%*
  616. if defined _args set _args=%_args:"=%
  617. if defined _args (
  618. for %%A in (%_args%) do (
  619. if /i "%%A"=="/HWID" set _act=1
  620. if /i "%%A"=="/HWID-NoEditionChange" set _NoEditionChange=1
  621. if /i "%%A"=="-el" set _elev=1
  622. )
  623. )
  624. ​
  625. for %%A in (%_act% %_NoEditionChange%) do (if "%%A"=="1" set _unattended=1)
  626. ​
  627. ::========================================================================================================================================
  628. ​
  629. if %winbuild% LSS 10240 (
  630. %eline%
  631. echo Unsupported OS version detected [%winbuild%].
  632. echo HWID Activation is only supported on Windows 10/11.
  633. call :dk_color %Blue% "Use TSforge activation option from the main menu."
  634. goto dk_done
  635. )
  636. ​
  637. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" (
  638. %eline%
  639. echo HWID Activation is not supported on Windows Server.
  640. call :dk_color %Blue% "Use TSforge activation option from the main menu."
  641. goto dk_done
  642. )
  643. ​
  644. setlocal EnableDelayedExpansion
  645. ​
  646. ::========================================================================================================================================
  647. ​
  648. cls
  649. if not defined terminal (
  650. mode 110, 34
  651. if exist "%SysPath%\spp\store_test\" mode 134, 34
  652. )
  653. title HWID Activation %masver%
  654. ​
  655. echo:
  656. echo Initializing...
  657. call :dk_chkmal
  658. ​
  659. for %%# in (
  660. sppsvc.exe
  661. ClipUp.exe
  662. ) do (
  663. if not exist %SysPath%\%%# (
  664. %eline%
  665. echo [%SysPath%\%%#] file is missing, aborting...
  666. echo:
  667. if not defined results (
  668. call :dk_color %Blue% "Go back to Main Menu, select Troubleshoot and run DISM Restore and SFC Scan options."
  669. call :dk_color %Blue% "After that, restart system and try activation again."
  670. set fixes=%fixes% %mas%in-place_repair_upgrade
  671. call :dk_color2 %Blue% "If it still shows the same error, do this - " %_Yellow% " %mas%in-place_repair_upgrade"
  672. )
  673. goto dk_done
  674. )
  675. )
  676. ​
  677. ::========================================================================================================================================
  678. ​
  679. set spp=SoftwareLicensingProduct
  680. set sps=SoftwareLicensingService
  681. ​
  682. call :dk_ckeckwmic
  683. call :dk_checksku
  684. call :dk_product
  685. call :dk_sppissue
  686. ​
  687. ::========================================================================================================================================
  688. ​
  689. :: Check if system is permanently activated or not
  690. ​
  691. call :dk_checkperm
  692. if defined _perm (
  693. cls
  694. echo ___________________________________________________________________________________________
  695. echo:
  696. call :dk_color2 %_White% " " %Green% "%winos% is already permanently activated."
  697. echo ___________________________________________________________________________________________
  698. if %_unattended%==1 goto dk_done
  699. echo:
  700. choice /C:10 /N /M "> [1] Activate Anyway [0] %_exitmsg% : "
  701. if errorlevel 2 exit /b
  702. )
  703. cls
  704. ​
  705. ::========================================================================================================================================
  706. ​
  707. :: Check Evaluation version
  708. ​
  709. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-*EvalEdition~*.mum" (
  710. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul2% | find /i "Eval" %nul1% && (
  711. %eline%
  712. echo [%winos% ^| %winbuild%]
  713. echo:
  714. echo Evaluation editions cannot be activated outside of their evaluation period.
  715. call :dk_color %Blue% "Use TSforge activation option from the main menu to reset evaluation period."
  716. set fixes=%fixes% %mas%evaluation_editions
  717. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%evaluation_editions"
  718. goto dk_done
  719. )
  720. )
  721. ​
  722. ::========================================================================================================================================
  723. ​
  724. set error=
  725. ​
  726. cls
  727. echo:
  728. call :dk_showosinfo
  729. ​
  730. :: Check Internet connection
  731. ​
  732. set _int=
  733. for %%a in (download.windowsupdate.com) do if not defined _int (
  734. for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do (if not "%%#"=="" set _int=1)
  735. )
  736. ​
  737. if not defined _int (
  738. %psc% "If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}"
  739. if !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)
  740. )
  741. ​
  742. if defined _int (
  743. echo Checking Internet Connection [Connected%ping_f%]
  744. ) else (
  745. set error=1
  746. call :dk_color %Red% "Checking Internet Connection [Not Connected]"
  747. call :dk_color %Blue% "Internet is required for HWID activation."
  748. )
  749. ​
  750. ::========================================================================================================================================
  751. ​
  752. echo Initiating Diagnostic Tests...
  753. ​
  754. set "_serv=ClipSVC wlidsvc sppsvc KeyIso LicenseManager Winmgmt"
  755. ​
  756. :: Client License Service (ClipSVC)
  757. :: Microsoft Account Sign-in Assistant
  758. :: Software Protection
  759. :: CNG Key Isolation
  760. :: Windows License Manager Service
  761. :: Windows Management Instrumentation
  762. ​
  763. call :dk_errorcheck
  764. ​
  765. ::========================================================================================================================================
  766. ​
  767. :: Detect Key
  768. ​
  769. set key=
  770. set altkey=
  771. set changekey=
  772. set altapplist=
  773. set altedition=
  774. set notworking=
  775. ​
  776. call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  777. if defined allapps call :hwiddata key
  778. if not defined key (
  779. for /f "delims=" %%a in ('%psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':getactivationid\:.*';. ([scriptblock]::Create($f[1]))"') do (set altapplist=%%a)
  780. if defined altapplist call :hwiddata key
  781. )
  782. ​
  783. if defined notworking call :hwidfallback
  784. if not defined key call :hwidfallback
  785. ​
  786. if defined altkey (set key=%altkey%&set changekey=1&set notworking=)
  787. ​
  788. if defined notworking if defined notfoundaltactID (
  789. call :dk_color %Red% "Checking Alternate Edition For HWID [%altedition% Activation ID Not Found]"
  790. )
  791. ​
  792. if not defined key (
  793. %eline%
  794. echo [%winos% ^| %winbuild% ^| SKU:%osSKU%]
  795. if not defined skunotfound (
  796. echo This product does not support HWID activation.
  797. echo Make sure you are using the latest version of the script.
  798. echo If you are, then try TSforge activation option from the main menu.
  799. set fixes=%fixes% %mas%
  800. echo %mas%
  801. ) else (
  802. echo Required license files not found in %SysPath%\spp\tokens\skus\
  803. set fixes=%fixes% %mas%troubleshoot
  804. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  805. )
  806. echo:
  807. goto dk_done
  808. )
  809. ​
  810. if defined notworking set error=1
  811. ​
  812. ::========================================================================================================================================
  813. ​
  814. :: Install key
  815. ​
  816. echo:
  817. if defined changekey (
  818. call :dk_color %Blue% "[%altedition%] edition product key will be used to enable HWID activation."
  819. echo:
  820. )
  821. ​
  822. if defined winsub (
  823. call :dk_color %Blue% "Windows Subscription [SKU ID-%slcSKU%] detected. Script will activate base edition [SKU ID-%regSKU%]."
  824. echo:
  825. )
  826. ​
  827. set generickey=1
  828. call :dk_inskey "[%key%]"
  829. ​
  830. ::========================================================================================================================================
  831. ​
  832. :: Change Windows region to USA to avoid activation issues as Windows store license is not available in many countries
  833. ​
  834. for /f "skip=2 tokens=2*" %%a in ('reg query "HKCU\Control Panel\International\Geo" /v Name %nul6%') do set "name=%%b"
  835. for /f "skip=2 tokens=2*" %%a in ('reg query "HKCU\Control Panel\International\Geo" /v Nation %nul6%') do set "nation=%%b"
  836. ​
  837. :: Skip changing region in top countries
  838. ​
  839. set regionchange=1
  840. for %%# in (US CN IN BR DE JP GB FR MX ID IT PK TR KR CA ES AU NG VN PL PH NL EG AR TH CO SA TW MY CL) do if /i "%name%"=="%%#" set regionchange=
  841. ​
  842. if defined regionchange (
  843. %psc% "Set-WinHomeLocation -GeoId 244" %nul%
  844. if !errorlevel! EQU 0 (
  845. echo Changing Windows Region To USA [Successful] [Script will change it back]
  846. ) else (
  847. call :dk_color %Red% "Changing Windows Region To USA [Failed]"
  848. )
  849. )
  850. ​
  851. ::==========================================================================================================================================
  852. ​
  853. :: Generate GenuineTicket.xml and apply
  854. :: In some cases clipup -v -o method fails and in some cases service restart method fails as well
  855. :: To maximize success rate and get better error details, script will install tickets two times (service restart + clipup -v -o)
  856. ​
  857. set "tdir=%ProgramData%\Microsoft\Windows\ClipSVC\GenuineTicket"
  858. if not exist "%tdir%\" md "%tdir%\" %nul%
  859. ​
  860. if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%
  861. if exist "%tdir%\*.xml" del /f /q "%tdir%\*.xml" %nul%
  862. if exist "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*" del /f /q "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*" %nul%
  863. ​
  864. call :hwiddata ticket
  865. ​
  866. copy /y /b "%tdir%\GenuineTicket" "%tdir%\GenuineTicket.xml" %nul%
  867. ​
  868. if not exist "%tdir%\GenuineTicket.xml" (
  869. call :dk_color %Red% "Generating GenuineTicket.xml [Failed, aborting...]"
  870. echo [%encoded%]
  871. if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%
  872. goto :dl_final
  873. ) else (
  874. echo Generating GenuineTicket.xml [Successful]
  875. )
  876. ​
  877. set "_xmlexist=if exist "%tdir%\GenuineTicket.xml""
  878. ​
  879. %_xmlexist% (
  880. %psc% "Start-Job { Restart-Service ClipSVC } | Wait-Job -Timeout 20 | Out-Null"
  881. %_xmlexist% timeout /t 2 %nul%
  882. %_xmlexist% timeout /t 2 %nul%
  883. ​
  884. %_xmlexist% (
  885. set error=1
  886. if exist "%tdir%\*.xml" del /f /q "%tdir%\*.xml" %nul%
  887. call :dk_color %Gray% "Installing GenuineTicket.xml [Failed with ClipSVC service restart, wait...]"
  888. )
  889. )
  890. ​
  891. copy /y /b "%tdir%\GenuineTicket" "%tdir%\GenuineTicket.xml" %nul%
  892. clipup -v -o
  893. ​
  894. set rebuildinfo=
  895. ​
  896. if not exist %ProgramData%\Microsoft\Windows\ClipSVC\tokens.dat (
  897. set error=1
  898. set rebuildinfo=1
  899. call :dk_color %Red% "Checking ClipSVC tokens.dat [Not Found]"
  900. )
  901. ​
  902. %_xmlexist% (
  903. set error=1
  904. set rebuildinfo=1
  905. call :dk_color %Red% "Installing GenuineTicket.xml [Failed With clipup -v -o]"
  906. )
  907. ​
  908. if exist "%ProgramData%\Microsoft\Windows\ClipSVC\Install\Migration\*.xml" (
  909. set error=1
  910. set rebuildinfo=1
  911. call :dk_color %Red% "Checking Ticket Migration [Failed]"
  912. )
  913. ​
  914. if not defined altapplist if not defined showfix if defined rebuildinfo (
  915. set showfix=1
  916. call :dk_color %Blue% "%_fixmsg%"
  917. echo:
  918. )
  919. ​
  920. if exist "%tdir%\Genuine*" del /f /q "%tdir%\Genuine*" %nul%
  921. ​
  922. ::==========================================================================================================================================
  923. ​
  924. call :dk_product
  925. ​
  926. echo:
  927. echo Activating...
  928. ​
  929. call :dk_act
  930. call :dk_checkperm
  931. if defined _perm (
  932. echo:
  933. call :dk_color %Green% "%winos% is permanently activated with a digital license."
  934. goto :dl_final
  935. )
  936. ​
  937. ::==========================================================================================================================================
  938. ​
  939. :: Clear store ID related registry to fix activation if Internet is connected
  940. ​
  941. set "_ident=HKU\S-1-5-19\SOFTWARE\Microsoft\IdentityCRL"
  942. ​
  943. if %keyerror% EQU 0 if defined _int (
  944. reg delete "%_ident%" /f %nul%
  945. for %%# in (wlidsvc LicenseManager sppsvc) do (%psc% "Start-Job { Restart-Service %%# } | Wait-Job -Timeout 20 | Out-Null")
  946. call :dk_refresh
  947. call :dk_act
  948. call :dk_checkperm
  949. ​
  950. reg query "%_ident%" %nul% || (
  951. set error=1
  952. echo:
  953. call :dk_color %Red% "Generating New IdentityCRL Registry [Failed] [%_ident%]"
  954. )
  955. )
  956. ​
  957. ::==========================================================================================================================================
  958. ​
  959. :: Extended licensing servers tests incase error not found and activation failed
  960. ​
  961. if %keyerror% EQU 0 if not defined _perm if defined _int (
  962. ipconfig /flushdns %nul%
  963. set "tls=[Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12;"
  964. ​
  965. for %%# in (
  966. licensing.mp.microsoft.com/v7.0/licenses/content
  967. login.live.com/ppsecure/deviceaddcredential.srf
  968. purchase.mp.microsoft.com/v7.0/users/me/orders
  969. ) do if not defined resfail (
  970. %psc% "try { !tls! irm https://%%# -Method POST } catch { if ($_.Exception.Response -eq $null) { Write-Host """"[%%#] $($_.Exception.Message)"""" -ForegroundColor Red -BackgroundColor Black; exit 3 } }"
  971. if !errorlevel!==3 set resfail=1
  972. )
  973. )
  974. ​
  975. if defined resfail (
  976. set error=1
  977. for %%# in (
  978. live.com
  979. microsoft.com
  980. login.live.com
  981. purchase.mp.microsoft.com
  982. licensing.mp.microsoft.com
  983. ) do (
  984. findstr /i "%%#" "%SysPath%\drivers\etc\hosts" %nul1% && set "hosfail= [%%# Blocked in Hosts]"
  985. )
  986. call :dk_color %Red% "Checking Licensing Servers [Failed to Connect]!hosfail!"
  987. set fixes=%fixes% %mas%licensing-servers-issue
  988. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%licensing-servers-issue"
  989. echo:
  990. )
  991. ​
  992. ::==========================================================================================================================================
  993. ​
  994. :: Windows update and store block check
  995. ​
  996. if %keyerror% EQU 0 if not defined _perm if defined _int (
  997. ​
  998. reg query "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v DisableWindowsUpdateAccess %nul2% | find /i "0x1" %nul% && set wublock=1
  999. reg query "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /v DoNotConnectToWindowsUpdateInternetLocations %nul2% | find /i "0x1" %nul% && set wublock=1
  1000. if defined wublock (
  1001. call :dk_color %Red% "Checking Update Blocker In Registry [Found]"
  1002. call :dk_color %Blue% "HWID activation needs working Windows updates, if you have used any tool to block updates, undo it."
  1003. echo:
  1004. )
  1005. ​
  1006. reg query "HKLM\SOFTWARE\Policies\Microsoft\WindowsStore" /v DisableStoreApps %nul2% | find /i "0x1" %nul% && (
  1007. set storeblock=1
  1008. call :dk_color %Red% "Checking Store Blocker In Registry [Found]"
  1009. call :dk_color %Blue% "If you have used any tool to block Store, undo it."
  1010. echo:
  1011. )
  1012. ​
  1013. set wcount=0
  1014. for %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type ServiceSidType RequiredPrivileges FailureActions) do (
  1015. reg query HKLM\SYSTEM\CurrentControlSet\Services\wuauserv /v %%G %nul% || (set wucorrupt=1&set /a wcount+=1)
  1016. )
  1017. ​
  1018. for %%G in (Parameters Security) do (
  1019. reg query HKLM\SYSTEM\CurrentControlSet\Services\wuauserv\%%G %nul% || (set wucorrupt=1&set /a wcount+=1)
  1020. )
  1021. ​
  1022. if defined wucorrupt (
  1023. set error=1
  1024. call :dk_color %Red% "Checking Windows Update Registry [Corruption Found]"
  1025. if !wcount! GTR 2 (
  1026. call :dk_color %Red% "Windows seems to be infected with Mal%w%ware."
  1027. set fixes=%fixes% %mas%remove_mal%w%ware
  1028. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%remove_mal%w%ware"
  1029. echo:
  1030. ) else (
  1031. call :dk_color %Blue% "HWID activation needs working Windows updates, if you have used any tool to block updates, undo it."
  1032. echo:
  1033. )
  1034. ) else (
  1035. %psc% "Start-Job { Start-Service wuauserv } | Wait-Job -Timeout 20 | Out-Null"
  1036. sc query wuauserv | find /i "RUNNING" %nul% || (
  1037. set error=1
  1038. set wuerror=1
  1039. sc start wuauserv %nul%
  1040. call :dk_color %Red% "Starting Windows Update Service [Failed] [!errorlevel!]"
  1041. call :dk_color %Blue% "HWID activation needs working Windows updates, if you have used any tool to block updates, undo it."
  1042. echo:
  1043. )
  1044. )
  1045. )
  1046. ​
  1047. ::==========================================================================================================================================
  1048. ​
  1049. :: Check Internet related error codes
  1050. ​
  1051. if %keyerror% EQU 0 if not defined _perm if defined _int (
  1052. if not defined wucorrupt if not defined wublock if not defined wuerror if not defined storeblock if not defined resfail (
  1053. echo "%error_code%" | findstr /i "0x80072e 0x80072f 0x800704cf 0x87e10bcf 0x800705b4" %nul% && (
  1054. call :dk_color %Red% "Checking Internet Issues [Found] %error_code%"
  1055. set fixes=%fixes% %mas%licensing-servers-issue
  1056. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%licensing-servers-issue"
  1057. echo:
  1058. )
  1059. )
  1060. )
  1061. ​
  1062. ::==========================================================================================================================================
  1063. ​
  1064. echo:
  1065. if defined _perm (
  1066. call :dk_color %Green% "%winos% is permanently activated with a digital license."
  1067. ) else (
  1068. call :dk_color %Red% "Activation Failed %error_code%"
  1069. if defined notworking (
  1070. call :dk_color %Blue% "At the time of writing, HWID Activation is not supported for this product."
  1071. call :dk_color %Blue% "Use TSforge activation option from the main menu instead."
  1072. ) else (
  1073. if not defined error call :dk_color %Blue% "%_fixmsg%"
  1074. set fixes=%fixes% %mas%troubleshoot
  1075. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  1076. )
  1077. )
  1078. ​
  1079. ::========================================================================================================================================
  1080. ​
  1081. :dl_final
  1082. ​
  1083. echo:
  1084. ​
  1085. if defined regionchange (
  1086. %psc% "Set-WinHomeLocation -GeoId %nation%" %nul%
  1087. if !errorlevel! EQU 0 (
  1088. echo Restoring Windows Region [Successful]
  1089. ) else (
  1090. call :dk_color %Red% "Restoring Windows Region [Failed] [%name% - %nation%]"
  1091. )
  1092. )
  1093. ​
  1094. REM if %osSKU%==175 call :dk_color %Red% "%winos% does not support activation on non-azure platforms."
  1095. ​
  1096. :: Trigger reevaluation of SPP's Scheduled Tasks
  1097. ​
  1098. if defined _perm (
  1099. call :dk_reeval %nul%
  1100. )
  1101. goto :dk_done
  1102. ​
  1103. ::========================================================================================================================================
  1104. ​
  1105. :: Set variables
  1106. ​
  1107. :dk_setvar
  1108. ​
  1109. set ps=%SysPath%\WindowsPowerShell\v1.0\powershell.exe
  1110. set psc=%ps% -nop -c
  1111. set winbuild=1
  1112. for /f "tokens=2 delims=[]" %%G in ('ver') do for /f "tokens=2,3,4 delims=. " %%H in ("%%~G") do set "winbuild=%%J"
  1113. ​
  1114. set _slexe=sppsvc.exe& set _slser=sppsvc
  1115. if %winbuild% LEQ 6300 (set _slexe=SLsvc.exe& set _slser=SLsvc)
  1116. if %winbuild% LSS 7600 if exist "%SysPath%\SLsvc.exe" (set _slexe=SLsvc.exe& set _slser=SLsvc)
  1117. if %_slexe%==SLsvc.exe set _vis=1
  1118. ​
  1119. set _NCS=1
  1120. if %winbuild% LSS 10586 set _NCS=0
  1121. if %winbuild% GEQ 10586 reg query "HKCU\Console" /v ForceV2 %nul2% | find /i "0x0" %nul1% && (set _NCS=0)
  1122. ​
  1123. echo "%PROCESSOR_ARCHITECTURE% %PROCESSOR_ARCHITEW6432%" | find /i "ARM64" %nul1% && (if %winbuild% LSS 21277 set ps32onArm=1)
  1124. ​
  1125. if %_NCS% EQU 1 (
  1126. for /F %%a in ('echo prompt $E ^| cmd') do set "esc=%%a"
  1127. set "Red="41;97m""
  1128. set "Gray="100;97m""
  1129. set "Green="42;97m""
  1130. set "Blue="44;97m""
  1131. set "White="107;91m""
  1132. set "_Red="40;91m""
  1133. set "_White="40;37m""
  1134. set "_Green="40;92m""
  1135. set "_Yellow="40;93m""
  1136. ) else (
  1137. set "Red="Red" "white""
  1138. set "Gray="Darkgray" "white""
  1139. set "Green="DarkGreen" "white""
  1140. set "Blue="Blue" "white""
  1141. set "White="White" "Red""
  1142. set "_Red="Black" "Red""
  1143. set "_White="Black" "Gray""
  1144. set "_Green="Black" "Green""
  1145. set "_Yellow="Black" "Yellow""
  1146. )
  1147. ​
  1148. set "nceline=echo: &echo ==== ERROR ==== &echo:"
  1149. set "eline=echo: &call :dk_color %Red% "==== ERROR ====" &echo:"
  1150. if %~z0 GEQ 200000 (
  1151. set "_exitmsg=Go back"
  1152. set "_fixmsg=Go back to Main Menu, select Troubleshoot and run Fix Licensing option."
  1153. ) else (
  1154. set "_exitmsg=Exit"
  1155. set "_fixmsg=In MAS folder, run Troubleshoot script and select Fix Licensing option."
  1156. )
  1157. exit /b
  1158. ​
  1159. :: Show OS info
  1160. ​
  1161. :dk_showosinfo
  1162. ​
  1163. for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE') do set osarch=%%b
  1164. ​
  1165. for /f "tokens=6-7 delims=[]. " %%i in ('ver') do if not "%%j"=="" (
  1166. set fullbuild=%%i.%%j
  1167. ) else (
  1168. for /f "tokens=3" %%G in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v UBR" %nul6%') do if not errorlevel 1 set /a "UBR=%%G"
  1169. for /f "skip=2 tokens=3,4 delims=. " %%G in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v BuildLabEx') do (
  1170. if defined UBR (set "fullbuild=%%G.!UBR!") else (set "fullbuild=%%G.%%H")
  1171. )
  1172. )
  1173. ​
  1174. echo Checking OS Info [%winos% ^| %fullbuild% ^| %osarch%]
  1175. exit /b
  1176. ​
  1177. :: Check SKU value
  1178. ​
  1179. :dk_checksku
  1180. ​
  1181. call :dk_reflection
  1182. ​
  1183. set osSKU=
  1184. set slcSKU=
  1185. set wmiSKU=
  1186. set regSKU=
  1187. set winsub=
  1188. ​
  1189. if %winbuild% GEQ 14393 (set info=Kernel-BrandingInfo) else (set info=Kernel-ProductInfo)
  1190. set d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('SLGetWindowsInformationDWORD', 'slc.dll', 'Public, Static', 1, [int], @([String], [int].MakeByRefType()), 1, 3);
  1191. set d1=%d1% $Sku = 0; [void]$TypeBuilder.CreateType()::SLGetWindowsInformationDWORD('%info%', [ref]$Sku); $Sku
  1192. for /f "delims=" %%s in ('"%psc% %d1%"') do if not errorlevel 1 (set slcSKU=%%s)
  1193. set slcSKU=%slcSKU: =%
  1194. if "%slcSKU%"=="0" set slcSKU=
  1195. for /f "tokens=* delims=0123456789" %%a in ("%slcSKU%") do (if not "[%%a]"=="[]" set slcSKU=)
  1196. ​
  1197. for /f "tokens=3 delims=." %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions" /v OSProductPfn %nul6%') do set "regSKU=%%a"
  1198. if %_wmic% EQU 1 for /f "tokens=2 delims==" %%a in ('"wmic Path Win32_OperatingSystem Get OperatingSystemSKU /format:LIST" %nul6%') do if not errorlevel 1 set "wmiSKU=%%a"
  1199. if %_wmic% EQU 0 for /f "tokens=1" %%a in ('%psc% "([WMI]'Win32_OperatingSystem=@').OperatingSystemSKU" %nul6%') do if not errorlevel 1 set "wmiSKU=%%a"
  1200. ​
  1201. if %winbuild% GEQ 15063 %psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':winsubstatus\:.*';. ([scriptblock]::Create($f[1]))" %nul2% | find /i "Subscription_is_activated" %nul% && (
  1202. if defined regSKU if defined slcSKU if not "%regSKU%"=="%slcSKU%" (
  1203. set winsub=1
  1204. set osSKU=%regSKU%
  1205. )
  1206. )
  1207. ​
  1208. if not defined osSKU set osSKU=%slcSKU%
  1209. if not defined osSKU set osSKU=%wmiSKU%
  1210. if not defined osSKU set osSKU=%regSKU%
  1211. exit /b
  1212. ​
  1213. :: Get Windows Subscription status
  1214. ​
  1215. :winsubstatus:
  1216. $DM = [AppDomain]::CurrentDomain.DefineDynamicAssembly(6, 1).DefineDynamicModule(4).DefineType(2)
  1217. [void]$DM.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  1218. $m = [System.Runtime.InteropServices.Marshal]
  1219. $p = $m::AllocHGlobal(12)
  1220. $r = $DM.CreateType()::ClipGetSubscriptionStatus([ref]$p)
  1221. if ($r -eq 0) {
  1222. $enabled = $m::ReadInt32($p)
  1223. if ($enabled -ge 1) {
  1224. $state = $m::ReadInt32($p, 8)
  1225. if ($state -eq 1) {
  1226. "Subscription_is_activated."
  1227. }
  1228. }
  1229. }
  1230. :winsubstatus:
  1231. ​
  1232. :: Get Windows permanent activation status
  1233. ​
  1234. :dk_checkperm
  1235. ​
  1236. if %_wmic% EQU 1 wmic path %spp% where (LicenseStatus='1' and GracePeriodRemaining='0' and PartialProductKey is not NULL AND LicenseDependsOn is NULL) get Name /value %nul2% | findstr /i "Windows" %nul1% && set _perm=1||set _perm=
  1237. if %_wmic% EQU 0 %psc% "(([WMISEARCHER]'SELECT Name FROM %spp% WHERE LicenseStatus=1 AND GracePeriodRemaining=0 AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).Name | %% {echo ('Name='+$_)}" %nul2% | findstr /i "Windows" %nul1% && set _perm=1||set _perm=
  1238. exit /b
  1239. ​
  1240. :: Refresh license status
  1241. ​
  1242. :dk_refresh
  1243. ​
  1244. if %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call RefreshLicenseStatus %nul%
  1245. if %_wmic% EQU 0 %psc% "$null=(([WMICLASS]'%sps%').GetInstances()).RefreshLicenseStatus()" %nul%
  1246. exit /b
  1247. ​
  1248. :: Install Key
  1249. ​
  1250. :dk_inskey
  1251. ​
  1252. if %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call InstallProductKey ProductKey="%key%" %nul%
  1253. if %_wmic% EQU 0 %psc% "try { $null=(([WMISEARCHER]'SELECT Version FROM %sps%').Get()).InstallProductKey('%key%'); exit 0 } catch { exit $_.Exception.InnerException.HResult }" %nul%
  1254. set keyerror=%errorlevel%
  1255. cmd /c exit /b %keyerror%
  1256. if %keyerror% NEQ 0 set "keyerror=[0x%=ExitCode%]"
  1257. ​
  1258. if defined generickey (set "keyecho=Installing Generic Product Key ") else (set "keyecho=Installing Product Key ")
  1259. if %keyerror% EQU 0 (
  1260. if %sps%==SoftwareLicensingService call :dk_refresh
  1261. echo %keyecho% %~1 [Successful]
  1262. ) else (
  1263. call :dk_color %Red% "%keyecho% %~1 [Failed] %keyerror%"
  1264. if not defined showfix (
  1265. if defined altapplist call :dk_color %Red% "Activation ID not found for this key."
  1266. call :dk_color %Blue% "%_fixmsg%"
  1267. echo:
  1268. set showfix=1
  1269. )
  1270. set error=1
  1271. )
  1272. ​
  1273. set generickey=
  1274. exit /b
  1275. ​
  1276. :: Activation command
  1277. ​
  1278. :dk_act
  1279. ​
  1280. set error_code=
  1281. if %_wmic% EQU 1 wmic path %spp% where "ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL" call Activate %nul%
  1282. if %_wmic% EQU 0 %psc% "try {$null=(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).Activate(); exit 0} catch { exit $_.Exception.InnerException.HResult }" %nul%
  1283. set error_code=%errorlevel%
  1284. cmd /c exit /b %error_code%
  1285. if %error_code% NEQ 0 (set "error_code=[Error Code: 0x%=ExitCode%]") else (set error_code=)
  1286. exit /b
  1287. ​
  1288. :: Get all products Activation IDs
  1289. ​
  1290. :dk_actids
  1291. ​
  1292. set allapps=
  1293. if %_wmic% EQU 1 set "chkapp=for /f "tokens=2 delims==" %%a in ('"wmic path %spp% where (ApplicationID='%1') get ID /VALUE" %nul6%')"
  1294. 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%')"
  1295. %chkapp% do (if defined allapps (call set "allapps=!allapps! %%a") else (call set "allapps=%%a"))
  1296. ​
  1297. :: Check potential script crash issue when user manually installs way too many licenses for Office (length limit in variable)
  1298. ​
  1299. if defined allapps if %1==0ff1ce15-a989-479d-af46-f275c6370663 (
  1300. set len=0
  1301. echo:!allapps!> "!_ttemp!\chklen"
  1302. for %%A in ("!_ttemp!\chklen") do (set len=%%~zA)
  1303. del "!_ttemp!\chklen" %nul%
  1304. ​
  1305. if !len! GTR 6000 (
  1306. %eline%
  1307. echo Too many licenses are installed, the script may crash.
  1308. call :dk_color %Blue% "%_fixmsg%"
  1309. timeout /t 30
  1310. )
  1311. )
  1312. exit /b
  1313. ​
  1314. :: Get installed products Activation IDs
  1315. ​
  1316. :dk_actid
  1317. ​
  1318. set apps=
  1319. if %_wmic% EQU 1 set "chkapp=for /f "tokens=2 delims==" %%a in ('"wmic path %spp% where (ApplicationID='%1' and PartialProductKey is not null) get ID /VALUE" %nul6%')"
  1320. if %_wmic% EQU 0 set "chkapp=for /f "tokens=2 delims==" %%a in ('%psc% "(([WMISEARCHER]'SELECT ID FROM %spp% WHERE ApplicationID=''%1'' AND PartialProductKey IS NOT NULL').Get()).ID ^| %% {echo ('ID='+$_)}" %nul6%')"
  1321. %chkapp% do (if defined apps (call set "apps=!apps! %%a") else (call set "apps=%%a"))
  1322. exit /b
  1323. ​
  1324. :: Trigger reevaluation, it helps in updating SPP tasks
  1325. ​
  1326. :dk_reeval
  1327. ​
  1328. if %winbuild% LSS 7600 exit /b
  1329. ​
  1330. :: 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
  1331. ​
  1332. set "ruleskey=HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\PersistedSystemState"
  1333. reg delete "%ruleskey%" /v "State" /f %nul%
  1334. reg delete "%ruleskey%" /v "SuppressRulesEngine" /f %nul%
  1335. ​
  1336. set r1=$TB = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0);
  1337. set r2=%r1% [void]$TB.DefinePInvokeMethod('SLpTriggerServiceWorker', 'sppc.dll', 22, 1, [Int32], @([UInt32], [IntPtr], [String], [UInt32]), 1, 3);
  1338. set d1=%r2% [void]$TB.CreateType()::SLpTriggerServiceWorker(0, 0, 'reeval', 0)
  1339. %psc% "Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null; %d1%"
  1340. exit /b
  1341. ​
  1342. :: Get Activation IDs from licensing files if not found through WMI
  1343. ​
  1344. :getactivationid:
  1345. $folderPath = "$env:SysPath\spp\tokens\skus"
  1346. $files = Get-ChildItem -Path $folderPath -Recurse -Filter "*.xrm-ms"
  1347. $guids = @()
  1348. foreach ($file in $files) {
  1349. $content = Get-Content -Path $file.FullName -Raw
  1350. $matches = [regex]::Matches($content, 'name="productSkuId">\{([0-9a-fA-F\-]+)\}')
  1351. foreach ($match in $matches) {
  1352. $guids += $match.Groups[1].Value
  1353. }
  1354. }
  1355. $guids = $guids | Select-Object -Unique
  1356. $guidsString = $guids -join " "
  1357. $guidsString
  1358. :getactivationid:
  1359. ​
  1360. :: Install License files using Powershell/WMI instead of slmgr.vbs
  1361. ​
  1362. :xrm:
  1363. function InstallLicenseFile($Lsc) {
  1364. try {
  1365. $null = $sls.InstallLicense([IO.File]::ReadAllText($Lsc))
  1366. } catch {
  1367. $host.SetShouldExit($_.Exception.HResult)
  1368. }
  1369. }
  1370. function InstallLicenseArr($Str) {
  1371. $a = $Str -split ';'
  1372. ForEach ($x in $a) {InstallLicenseFile "$x"}
  1373. }
  1374. function InstallLicenseDir($Loc) {
  1375. Get-ChildItem $Loc -Recurse -Filter *.xrm-ms | ForEach-Object {InstallLicenseFile $_.FullName}
  1376. }
  1377. function ReinstallLicenses() {
  1378. $Paths = @("$env:SysPath\oem", "$env:SysPath\licensing", "$env:SysPath\spp\tokens")
  1379. foreach ($Path in $Paths) {
  1380. if (Test-Path $Path) { InstallLicenseDir "$Path" }
  1381. }
  1382. }
  1383. :xrm:
  1384. ​
  1385. :: Check wmic.exe
  1386. ​
  1387. :dk_ckeckwmic
  1388. ​
  1389. if %winbuild% LSS 9200 (set _wmic=1&exit /b)
  1390. set _wmic=0
  1391. for %%# in (wmic.exe) do @if not "%%~$PATH:#"=="" (
  1392. cmd /c "wmic path Win32_ComputerSystem get CreationClassName /value" %nul2% | find /i "computersystem" %nul1% && set _wmic=1
  1393. )
  1394. exit /b
  1395. ​
  1396. :: Show info for potential script stuck scenario
  1397. ​
  1398. :dk_sppissue
  1399. ​
  1400. sc start %_slser% %nul%
  1401. set spperror=%errorlevel%
  1402. ​
  1403. if %spperror% NEQ 1056 if %spperror% NEQ 0 (
  1404. %eline%
  1405. echo sc start %_slser% [Error Code: %spperror%]
  1406. if %spperror% EQU 1053 (
  1407. call :dk_color %Blue% "Reboot your machine using the restart option and try again."
  1408. call :dk_color %Blue% "If it still does not work, go back to Main Menu, select Troubleshoot and run Fix WPA Registry option."
  1409. )
  1410. )
  1411. ​
  1412. echo:
  1413. %psc% "$job = Start-Job { (Get-WmiObject -Query 'SELECT * FROM %sps%').Version }; if (-not (Wait-Job $job -Timeout 30)) {write-host '%_slser% is not working correctly. Check this webpage for help - %mas%troubleshoot'}"
  1414. exit /b
  1415. ​
  1416. :: Get Product name (WMI/REG methods are not reliable in all conditions, hence winbrand.dll method is used)
  1417. ​
  1418. :dk_product
  1419. ​
  1420. set d1=%ref% $meth = $TypeBuilder.DefinePInvokeMethod('BrandingFormatString', 'winbrand.dll', 'Public, Static', 1, [String], @([String]), 1, 3);
  1421. set d1=%d1% $meth.SetImplementationFlags(128); $TypeBuilder.CreateType()::BrandingFormatString('%%WINDOWS_LONG%%') -replace [string][char]0xa9, '' -replace [string][char]0xae, '' -replace [string][char]0x2122, ''
  1422. ​
  1423. set winos=
  1424. for /f "delims=" %%s in ('"%psc% %d1%"') do if not errorlevel 1 (set winos=%%s)
  1425. echo "%winos%" | find /i "Windows" %nul1% || (
  1426. for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v ProductName %nul6%') do set "winos=%%b"
  1427. if %winbuild% GEQ 22000 (
  1428. set winos=!winos:Windows 10=Windows 11!
  1429. )
  1430. )
  1431. ​
  1432. if not defined winsub exit /b
  1433. ​
  1434. :: Check base edition product name if Windows subscription license is found
  1435. ​
  1436. for %%# in (pkeyhelper.dll) do @if "%%~$PATH:#"=="" exit /b
  1437. set d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('GetEditionNameFromId', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [IntPtr].MakeByRefType()), 1, 3);
  1438. set d1=%d1% $out = 0; [void]$TypeBuilder.CreateType()::GetEditionNameFromId(%regSKU%, [ref]$out);$s=[Runtime.InteropServices.Marshal]::PtrToStringUni($out); $s
  1439. ​
  1440. for /f %%a in ('%psc% "%d1%"') do if not errorlevel 1 (
  1441. if %winbuild% GEQ 22000 (
  1442. set winos=Windows 11 %%a
  1443. ) else (
  1444. set winos=Windows 10 %%a
  1445. )
  1446. )
  1447. exit /b
  1448. ​
  1449. :: Common lines used in PowerShell reflection code
  1450. ​
  1451. :dk_reflection
  1452. ​
  1453. set ref=$AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1);
  1454. set ref=%ref% $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False);
  1455. set ref=%ref% $TypeBuilder = $ModuleBuilder.DefineType(0);
  1456. exit /b
  1457. ​
  1458. ::========================================================================================================================================
  1459. ​
  1460. :dk_chkmal
  1461. ​
  1462. :: Many users unknowingly download mal-ware by using activators found through Google search.
  1463. :: This code aims to notify users that their system has been affected by mal-ware.
  1464. ​
  1465. set w=
  1466. set results=
  1467. if exist "%ProgramFiles%\KM%w%Spico" set pupfound= KM%w%Spico
  1468. if not defined pupfound (
  1469. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\taskcache\tasks" /f Path /s | find /i "AutoPico" %nul% && set pupfound= KM%w%Spico
  1470. )
  1471. ​
  1472. set hcount=0
  1473. for %%# in (avira.com kaspersky.com virustotal.com mcafee.com) do (
  1474. find /i "%%#" %SysPath%\drivers\etc\hosts %nul% && set /a hcount+=1)
  1475. if %hcount%==4 set "results=[Antivirus URLs are blocked in hosts]"
  1476. ​
  1477. sc start %_slser% %nul%
  1478. echo "%errorlevel%" | findstr "577 225" %nul% && (
  1479. set "results=%results%[Likely File Infector]"
  1480. ) || (
  1481. if not exist %SysPath%\%_slexe% if not exist %SysPath%\alg.exe (set "results=%results%[Likely File Infector]")
  1482. )
  1483. ​
  1484. if not "%results%%pupfound%"=="" (
  1485. if defined pupfound call :dk_color %Gray% "Checking PUP Activators [Found%pupfound%]"
  1486. if defined results call :dk_color %Red% "Checking Probable Mal%w%ware Infection..."
  1487. if defined results (call :dk_color %Red% "%results%"&set showfix=1)
  1488. set fixes=%fixes% %mas%remove_mal%w%ware
  1489. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%remove_mal%w%ware"
  1490. echo:
  1491. )
  1492. ​
  1493. :: Remove the scheduled task of R@1n-KMS (old version) that runs the activation command every minute, as it leads to high CPU usage.
  1494. ​
  1495. if exist %SysPath%\Tasks\R@1n-KMS (
  1496. for /f %%A in ('dir /b /a:-d %SysPath%\Tasks\R@1n-KMS %nul6%') do (schtasks /delete /tn \R@1n-KMS\%%A /f %nul%)
  1497. )
  1498. ​
  1499. exit /b
  1500. ​
  1501. ::========================================================================================================================================
  1502. ​
  1503. :dk_errorcheck
  1504. ​
  1505. set showfix=
  1506. call :dk_chkmal
  1507. ​
  1508. ::==============================
  1509. ​
  1510. :: Check Sandboxing
  1511. ​
  1512. sc query Null %nul% || (
  1513. call :dk_color %Red% "Checking Sandboxing [Found, script may not work properly]"
  1514. if not defined showfix (
  1515. call :dk_color %Blue% "If you are using any third-party antivirus, check if it is blocking the script."
  1516. echo:
  1517. )
  1518. set error=1
  1519. set showfix=1
  1520. )
  1521. ​
  1522. ::==============================
  1523. ​
  1524. :: Check WinPE mode
  1525. ​
  1526. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinPE" /v InstRoot %nul% && (
  1527. ​
  1528. call :dk_color %Red% "Checking WinPE [Found]"
  1529. if not defined showfix (
  1530. call :dk_color %Blue% "WinPE mode found. Reboot the system and run in normal mode."
  1531. echo:
  1532. )
  1533. set error=1
  1534. set showfix=1
  1535. )
  1536. ​
  1537. ::==============================
  1538. ​
  1539. :: Check Safe mode
  1540. ​
  1541. if defined safeboot_option (
  1542. call :dk_color %Red% "Checking Boot Mode [%safeboot_option%]"
  1543. if not defined showfix (
  1544. call :dk_color %Blue% "Safe mode found. Reboot the system and run in normal mode."
  1545. echo:
  1546. )
  1547. set error=1
  1548. set showfix=1
  1549. )
  1550. ​
  1551. ::==============================
  1552. ​
  1553. :: Check ImageState
  1554. :: https://learn.microsoft.com/en-us/windows-hardware/manufacture/desktop/windows-setup-states
  1555. ​
  1556. for /f "skip=2 tokens=2*" %%A in ('reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Setup\State" /v ImageState') do (set imagestate=%%B)
  1557. ​
  1558. if /i not "%imagestate%"=="IMAGE_STATE_COMPLETE" (
  1559. call :dk_color %Gray% "Checking Windows Setup State [%imagestate%]"
  1560. echo "%imagestate%" | find /i "RESEAL" %nul% && (
  1561. if not defined showfix (
  1562. call :dk_color %Blue% "You need to run it in normal mode in case you are running it in Audit Mode."
  1563. echo:
  1564. )
  1565. set error=1
  1566. set showfix=1
  1567. )
  1568. echo "%imagestate%" | find /i "UNDEPLOYABLE" %nul% && (
  1569. if not defined showfix (
  1570. set fixes=%fixes% %mas%in-place_repair_upgrade
  1571. call :dk_color2 %Blue% "If the activation fails, do this - " %_Yellow% " %mas%in-place_repair_upgrade"
  1572. echo:
  1573. )
  1574. )
  1575. )
  1576. ​
  1577. ::==============================
  1578. ​
  1579. :: Check corrupt services
  1580. ​
  1581. set serv_cor=
  1582. for %%# in (%_serv%) do (
  1583. set _regcorr=
  1584. set _corrupt=
  1585. sc start %%# %nul%
  1586. if !errorlevel! EQU 1060 set _corrupt=1
  1587. sc query %%# %nul% || set _corrupt=1
  1588. for %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type) do if not defined _regcorr (
  1589. reg query HKLM\SYSTEM\CurrentControlSet\Services\%%# /v %%G %nul% || (set _corrupt=1&set _regcorr=-RegistryError)
  1590. )
  1591. ​
  1592. if defined _corrupt (if defined serv_cor (set "serv_cor=!serv_cor! %%#!_regcorr!") else (set "serv_cor=%%#!_regcorr!"))
  1593. )
  1594. ​
  1595. if defined serv_cor (
  1596. call :dk_color %Red% "Checking Corrupt Services [%serv_cor%]"
  1597. ​
  1598. if not defined showfix (
  1599. echo:
  1600. if /i "%serv_cor%"=="sppsvc-RegistryError" (
  1601. set fixes=%fixes% %mas%fix_service
  1602. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%fix_service"
  1603. ) else (
  1604. set fixes=%fixes% %mas%in-place_repair_upgrade
  1605. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%in-place_repair_upgrade"
  1606. )
  1607. echo:
  1608. )
  1609. ​
  1610. set error=1
  1611. set showfix=1
  1612. )
  1613. ​
  1614. ::==============================
  1615. ​
  1616. :: Check disabled services
  1617. ​
  1618. set serv_ste=
  1619. for %%# in (%_serv%) do (
  1620. sc start %%# %nul%
  1621. if !errorlevel! EQU 1058 (if defined serv_ste (set "serv_ste=!serv_ste! %%#") else (set "serv_ste=%%#"))
  1622. )
  1623. ​
  1624. :: Change disabled services startup type to default
  1625. ​
  1626. set serv_csts=
  1627. set serv_cste=
  1628. ​
  1629. if defined serv_ste (
  1630. for %%# in (%serv_ste%) do (
  1631. if /i %%#==ClipSVC (reg add "HKLM\SYSTEM\CurrentControlSet\Services\%%#" /v "Start" /t REG_DWORD /d "3" /f %nul% & sc config %%# start= demand %nul%)
  1632. if /i %%#==wlidsvc sc config %%# start= demand %nul%
  1633. if /i %%#==sppsvc (reg add "HKLM\SYSTEM\CurrentControlSet\Services\%%#" /v "Start" /t REG_DWORD /d "2" /f %nul% & sc config %%# start= delayed-auto %nul%)
  1634. if /i %%#==SLsvc sc config %%# start= auto %nul%
  1635. if /i %%#==KeyIso sc config %%# start= demand %nul%
  1636. if /i %%#==LicenseManager sc config %%# start= demand %nul%
  1637. if /i %%#==Winmgmt sc config %%# start= auto %nul%
  1638. if !errorlevel!==0 (
  1639. if defined serv_csts (set "serv_csts=!serv_csts! %%#") else (set "serv_csts=%%#")
  1640. ) else (
  1641. if defined serv_cste (set "serv_cste=!serv_cste! %%#") else (set "serv_cste=%%#")
  1642. )
  1643. )
  1644. )
  1645. ​
  1646. if defined serv_csts call :dk_color %Gray% "Enabling Disabled Services [Successful] [%serv_csts%]"
  1647. ​
  1648. if defined serv_cste (
  1649. call :dk_color %Red% "Enabling Disabled Services [Failed] [%serv_cste%]"
  1650. ​
  1651. if not defined showfix (
  1652. echo:
  1653. echo %serv_cste% | findstr /i "ClipSVC sppsvc" %nul% && (
  1654. echo A registry fix has been applied to enable the disabled service.
  1655. call :dk_color %Blue% "Reboot your machine using the restart option to fix this error."
  1656. ) || (
  1657. set fixes=%fixes% %mas%in-place_repair_upgrade
  1658. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%in-place_repair_upgrade"
  1659. )
  1660. echo:
  1661. )
  1662. ​
  1663. set error=1
  1664. set showfix=1
  1665. )
  1666. ​
  1667. ::==============================
  1668. ​
  1669. :: Check if the services are able to run or not
  1670. :: Workarounds are added to get correct status and error code because sc query doesn't output correct results in some conditions
  1671. ​
  1672. set serv_e=
  1673. for %%# in (%_serv%) do (
  1674. set errorcode=
  1675. set checkerror=
  1676. ​
  1677. sc query %%# | find /i "RUNNING" %nul% || (
  1678. %psc% "Start-Job { Start-Service %%# } | Wait-Job -Timeout 20 | Out-Null"
  1679. set errorcode=!errorlevel!
  1680. sc query %%# | find /i "RUNNING" %nul% || set checkerror=1
  1681. )
  1682. ​
  1683. sc start %%# %nul%
  1684. if !errorlevel! NEQ 1056 if !errorlevel! NEQ 0 (set errorcode=!errorlevel!&set checkerror=1)
  1685. if defined checkerror if defined serv_e (set "serv_e=!serv_e!, %%#-!errorcode!") else (set "serv_e=%%#-!errorcode!")
  1686. )
  1687. ​
  1688. if defined serv_e (
  1689. call :dk_color %Red% "Starting Services [Failed] [%serv_e%]"
  1690. ​
  1691. if not defined showfix (
  1692. set listwospp=%_serv:sppsvc=%
  1693. echo %serv_e% | findstr /i "!listwospp!" %nul% && (
  1694. set showfix=1
  1695. call :dk_color %Blue% "Reboot your machine using the restart option and run the script again."
  1696. set fixes=%fixes% %mas%in-place_repair_upgrade
  1697. call :dk_color2 %Blue% "If service error is still not fixed, do this - " %_Yellow% " %mas%in-place_repair_upgrade"
  1698. echo:
  1699. )
  1700. )
  1701. set error=1
  1702. )
  1703. ​
  1704. ::==============================
  1705. ​
  1706. :: Check WMI
  1707. ​
  1708. set wmifailed=
  1709. if %_wmic% EQU 1 wmic path Win32_ComputerSystem get CreationClassName /value %nul2% | find /i "computersystem" %nul1%
  1710. if %_wmic% EQU 0 %psc% "Get-WmiObject -Class Win32_ComputerSystem | Select-Object -Property CreationClassName" %nul2% | find /i "computersystem" %nul1%
  1711. ​
  1712. if %errorlevel% NEQ 0 set wmifailed=1
  1713. ​
  1714. if %_wmic% EQU 1 wmic path %sps% get Version %nul%
  1715. if %_wmic% EQU 0 %psc% "try { $null=([WMISEARCHER]'SELECT * FROM %sps%').Get().Version; exit 0 } catch { exit $_.Exception.InnerException.HResult }" %nul%
  1716. set error_code=%errorlevel%
  1717. cmd /c exit /b %error_code%
  1718. if %error_code% NEQ 0 set "error_code=0x%=ExitCode%"
  1719. ​
  1720. echo "%error_code%" | findstr /i "0x800410 0x800440 0x80131501" %nul1% && set wmifailed=1& :: https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants
  1721. ​
  1722. if defined wmifailed (
  1723. call :dk_color %Red% "Checking WMI [Not Working]"
  1724. ​
  1725. if not defined showfix (
  1726. call :dk_color %Blue% "Go back to Main Menu, select Troubleshoot and run Fix WMI option."
  1727. echo:
  1728. )
  1729. set error=1
  1730. set showfix=1
  1731. )
  1732. ​
  1733. ::==============================
  1734. ​
  1735. :: Check SPP Registry Key
  1736. ​
  1737. if %winbuild% GEQ 7600 reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Plugins\Objects\msft:rm/algorithm/hwid/4.0" /f ba02fed39662 /d %nul% || (
  1738. call :dk_color %Red% "Checking SPP Registry Key [Incorrect ModuleId Found] [Most likely caused by gaming spoofers]"
  1739. if not defined showfix (
  1740. set fixes=%fixes% %mas%issues_due_to_gaming_spoofers
  1741. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%issues_due_to_gaming_spoofers"
  1742. echo:
  1743. )
  1744. set error=1
  1745. set showfix=1
  1746. )
  1747. ​
  1748. ::==============================
  1749. ​
  1750. :: Check TokenStore registry key
  1751. ​
  1752. set tokenstore=
  1753. if %winbuild% GEQ 7600 (
  1754. for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v TokenStore %nul6%') do call set "tokenstore=%%b"
  1755. if %winbuild% LSS 9200 set "tokenstore=%Systemdrive%\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform"
  1756. ​
  1757. if %winbuild% GEQ 9200 if /i not "!tokenstore!"=="%SysPath%\spp\store" if /i not "!tokenstore!"=="%SysPath%\spp\store\2.0" if /i not "!tokenstore!"=="%SysPath%\spp\store_test\2.0" (
  1758. call :dk_color %Red% "Checking TokenStore Registry Key [Correct Path Not Found] [!tokenstore!]"
  1759. if not defined showfix (
  1760. set fixes=%fixes% %mas%in-place_repair_upgrade
  1761. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%in-place_repair_upgrade"
  1762. echo:
  1763. )
  1764. set toerr=1
  1765. set error=1
  1766. set showfix=1
  1767. )
  1768. )
  1769. ​
  1770. ::==============================
  1771. ​
  1772. :: This code creates token folder only if it's missing and sets default permission for it
  1773. ​
  1774. if %winbuild% GEQ 7600 if not defined toerr if not exist "%tokenstore%\" (
  1775. ​
  1776. mkdir "%tokenstore%" %nul%
  1777. ​
  1778. if %winbuild% LSS 9200 set "d=$sddl = 'O:NSG:NSD:AI(A;OICIID;FA;;;SY)(A;OICIID;FA;;;BA)(A;OICIID;FA;;;NS)';"
  1779. if %winbuild% GEQ 9200 set "d=$sddl = 'O:BAG:BAD:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICIIO;GR;;;BU)(A;;FR;;;BU)(A;OICI;FA;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)';"
  1780. set "d=!d! $AclObject = New-Object System.Security.AccessControl.DirectorySecurity;"
  1781. set "d=!d! $AclObject.SetSecurityDescriptorSddlForm($sddl);"
  1782. set "d=!d! Set-Acl -Path %tokenstore% -AclObject $AclObject;"
  1783. %psc% "!d!" %nul%
  1784. ​
  1785. if exist "%tokenstore%\" (
  1786. call :dk_color %Gray% "Checking SPP Token Folder [Not Found, Created Now] [%tokenstore%\]"
  1787. ) else (
  1788. call :dk_color %Red% "Checking SPP Token Folder [Not Found, Failed to Create] [%tokenstore%\]"
  1789. if not defined showfix (
  1790. set fixes=%fixes% %mas%in-place_repair_upgrade
  1791. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%in-place_repair_upgrade"
  1792. echo:
  1793. )
  1794. set error=1
  1795. set showfix=1
  1796. )
  1797. )
  1798. ​
  1799. ::==============================
  1800. ​
  1801. :: This code checks if SPP has permission access to tokens folder and required registry keys. It's often caused by gaming spoofers.
  1802. ​
  1803. set permerror=
  1804. if %winbuild% GEQ 9200 if not defined toerr if not defined ps32onArm if exist "%tokenstore%\" (
  1805. for %%# in (
  1806. "%tokenstore%+FullControl"
  1807. "HKLM:\SYSTEM\WPA+QueryValues, EnumerateSubKeys, WriteKey"
  1808. "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform+SetValue"
  1809. ) do for /f "tokens=1,2 delims=+" %%A in (%%#) do if not defined permerror (
  1810. %psc% "$acl = (Get-Acl '%%A' | fl | Out-String); if (-not ($acl -match 'NT SERVICE\\sppsvc Allow %%B') -or ($acl -match 'NT SERVICE\\sppsvc Deny')) {Exit 2}" %nul%
  1811. if !errorlevel!==2 (
  1812. if "%%A"=="%tokenstore%" (
  1813. set "permerror=Error Found In Token Folder"
  1814. ) else (
  1815. set "permerror=Error Found In SPP Registries"
  1816. )
  1817. )
  1818. )
  1819. ​
  1820. REM https://learn.microsoft.com/en-us/office/troubleshoot/activation/license-issue-when-start-office-application
  1821. ​
  1822. if not defined permerror (
  1823. reg query "HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion" %nul% && (
  1824. set "pol=HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Policies"
  1825. reg query "!pol!" %nul% || reg add "!pol!" %nul%
  1826. %psc% "$netServ = (New-Object Security.Principal.SecurityIdentifier('S-1-5-20')).Translate([Security.Principal.NTAccount]).Value; $aclString = Get-Acl 'Registry::!pol!' | Format-List | Out-String; if (-not ($aclString.Contains($netServ + ' Allow FullControl') -or $aclString.Contains('NT SERVICE\sppsvc Allow FullControl')) -or ($aclString.Contains('Deny'))) {Exit 3}" %nul%
  1827. if !errorlevel!==3 set "permerror=Error Found In S-1-5-20 SPP"
  1828. )
  1829. )
  1830. ​
  1831. if defined permerror (
  1832. call :dk_color %Red% "Checking SPP Permissions [!permerror!]"
  1833. if not defined showfix (
  1834. call :dk_color %Blue% "%_fixmsg%"
  1835. echo:
  1836. )
  1837. set error=1
  1838. set showfix=1
  1839. )
  1840. )
  1841. ​
  1842. ::==============================
  1843. ​
  1844. :: Check WPA Registry Errors
  1845. ​
  1846. set chkalp=
  1847. set wpainfo=NotFound
  1848. for /f "delims=" %%a in ('%psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':wpatest\:.*';. ([scriptblock]::Create($f[1]))" %nul6%') do (set wpainfo=%%a)
  1849. for /f "delims=0123456789" %%i in ("%wpainfo%") do set chkalp=%%i
  1850. ​
  1851. if defined chkalp (
  1852. call :dk_color %Red% "Checking WPA Registry Errors [%wpainfo%]"
  1853. if not defined showfix (
  1854. echo "%wpainfo%" | find /i "Error Found" %nul% && (
  1855. call :dk_color %Blue% "Go back to Main Menu, select Troubleshoot and run Fix WPA Registry option."
  1856. echo:
  1857. set error=1
  1858. set showfix=1
  1859. )
  1860. )
  1861. set wpainfo=a
  1862. )
  1863. ​
  1864. if not defined chkalp (
  1865. if %wpainfo% GEQ 5000 (
  1866. call :dk_color %Gray% "Checking WPA Registry Count [%wpainfo%]"
  1867. call :dk_color %Blue% "A large number of WPA registries have been found, which may cause high CPU usage."
  1868. call :dk_color %Blue% "Go back to Main Menu, select Troubleshoot and run Fix WPA Registry option."
  1869. echo:
  1870. ) else (
  1871. echo Checking WPA Registry Count [%wpainfo%]
  1872. )
  1873. )
  1874. ​
  1875. ::==============================
  1876. ​
  1877. :: Check Rearm
  1878. ​
  1879. reg query "HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\PersistedTSReArmed" %nul% && (
  1880. call :dk_color %Red% "Checking Rearm [System is Rearmed]"
  1881. if not defined showfix (
  1882. call :dk_color %Blue% "Reboot your machine using the restart option to fix this error."
  1883. echo:
  1884. )
  1885. set error=1
  1886. set showfix=1
  1887. )
  1888. ​
  1889. ​
  1890. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ClipSVC\Volatile\PersistedSystemState" %nul% && (
  1891. call :dk_color %Red% "Checking ClipSVC PersistedSystemState [Found]"
  1892. if not defined showfix (
  1893. call :dk_color %Blue% "Reboot your machine using the restart option to fix this error."
  1894. echo:
  1895. )
  1896. set error=1
  1897. set showfix=1
  1898. )
  1899. ​
  1900. ::==============================
  1901. ​
  1902. :: Check SoftwareLicensingService
  1903. ​
  1904. if %error_code% NEQ 0 (
  1905. call :dk_color %Red% "Checking SoftwareLicensingService [Not Working] [%error_code%]"
  1906. if not defined showfix (
  1907. call :dk_color %Blue% "%_fixmsg%"
  1908. call :dk_color %Blue% "If activation still fails then run Fix WPA Registry option."
  1909. echo:
  1910. )
  1911. set error=1
  1912. set showfix=1
  1913. )
  1914. ​
  1915. ::==============================
  1916. ​
  1917. :: Check Activation IDs
  1918. ​
  1919. call :dk_actid 55c92734-d682-4d71-983e-d6ec3f16059f
  1920. ​
  1921. if not defined apps (
  1922. %psc% "if (-not $env:_vis) {Start-Job { Stop-Service %_slser% -force } | Wait-Job -Timeout 20 | Out-Null}; $sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses" %nul%
  1923. if not defined _vis if !errorlevel! NEQ 0 set rlicfailed=1
  1924. call :dk_actid 55c92734-d682-4d71-983e-d6ec3f16059f
  1925. )
  1926. ​
  1927. if not defined apps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  1928. ​
  1929. if not defined apps if defined allapps if not defined notwinact (
  1930. call :dk_color %Gray% "Checking Activation IDs [Key Not Installed or Act ID Not Found]"
  1931. )
  1932. ​
  1933. if not defined apps if not defined allapps (
  1934. call :dk_color %Red% "Checking Activation IDs [Not found]"
  1935. if not defined showfix (
  1936. call :dk_color %Blue% "%_fixmsg%"
  1937. call :dk_color %Blue% "If activation still fails then run Fix WPA Registry option."
  1938. echo:
  1939. )
  1940. set error=1
  1941. set showfix=1
  1942. )
  1943. ​
  1944. if not defined showfix if defined rlicfailed (
  1945. call :dk_color %Blue% "%_fixmsg%"
  1946. call :dk_color %Blue% "If activation still fails then run Fix WPA Registry option."
  1947. echo:
  1948. )
  1949. ​
  1950. if %winbuild% GEQ 7600 if exist "%tokenstore%\" if not exist "%tokenstore%\tokens.dat" (
  1951. call :dk_color %Red% "Checking SPP tokens.dat [Not Found] [%tokenstore%\]"
  1952. )
  1953. ​
  1954. ::==============================
  1955. ​
  1956. :: Check Eval Windows
  1957. ​
  1958. if not defined notwinact if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-*EvalEdition~*.mum" (
  1959. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul2% | find /i "Eval" %nul1% || (
  1960. call :dk_color %Red% "Checking Eval Packages [License swapping found. Non-Eval licenses are installed in Eval Windows]"
  1961. if not defined showfix (
  1962. call :dk_color %Blue% "License swapping is not the right way to upgrade to the full version. Learn the correct method at the link below."
  1963. set fixes=%fixes% %mas%evaluation_editions
  1964. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%evaluation_editions"
  1965. echo:
  1966. )
  1967. set error=1
  1968. set showfix=1
  1969. )
  1970. )
  1971. ​
  1972. ::==============================
  1973. ​
  1974. :: Check HKU\S-1-5-20\Software registry, in some systems it's missing and that causes Windows activation problems
  1975. ​
  1976. reg query "HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion" %nul% || (
  1977. call :dk_color %Red% "Checking HKU\S-1-5-20 Registry [Not Found]"
  1978. if not defined showfix (
  1979. set fixes=%fixes% %mas%in-place_repair_upgrade
  1980. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%in-place_repair_upgrade"
  1981. echo:
  1982. )
  1983. set error=1
  1984. set showfix=1
  1985. )
  1986. ​
  1987. ::==============================
  1988. ​
  1989. :: Check license and package files for the current edition
  1990. ​
  1991. set osedition=0
  1992. if %_wmic% EQU 1 set "chkedi=for /f "tokens=2 delims==" %%a in ('"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL) get LicenseFamily /VALUE" %nul6%')"
  1993. if %_wmic% EQU 0 set "chkedi=for /f "tokens=2 delims==" %%a in ('%psc% "(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}" %nul6%')"
  1994. %chkedi% do if not errorlevel 1 (call set "osedition=%%a")
  1995. ​
  1996. if %osedition%==0 for /f "skip=2 tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul6%') do set "osedition=%%a"
  1997. ​
  1998. :: Workaround for an issue in builds between 1607 and 1709 where ProfessionalEducation is shown as Professional
  1999. ​
  2000. if not %osedition%==0 (
  2001. if "%osSKU%"=="164" set osedition=ProfessionalEducation
  2002. if "%osSKU%"=="165" set osedition=ProfessionalEducationN
  2003. )
  2004. ​
  2005. if not defined notwinact (
  2006. if %osedition%==0 (
  2007. call :dk_color %Red% "Checking Edition Name [Not Found In Registry]"
  2008. ) else (
  2009. if not exist "%SysPath%\spp\tokens\skus\%osedition%\%osedition%*.xrm-ms" if not exist "%SysPath%\spp\tokens\skus\Security-SPP-Component-SKU-%osedition%\*-%osedition%-*.xrm-ms" if not exist "%SysPath%\licensing\skus\Security-Licensing-SLC-Component-SKU-%osedition%\*-%osedition%-*.xrm-ms" (
  2010. set skunotfound=1
  2011. call :dk_color %Red% "Checking License Files [Not Found] [%osedition%]"
  2012. )
  2013. if not exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-*-%osedition%-*.mum" (
  2014. if not exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-%osedition%Edition*.mum" (
  2015. call :dk_color %Red% "Checking Package Files [Not Found] [%osedition%]"
  2016. if not defined showfix (
  2017. set fixes=%fixes% %mas%in-place_repair_upgrade
  2018. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%in-place_repair_upgrade"
  2019. echo:
  2020. )
  2021. set error=1
  2022. set showfix=1
  2023. )
  2024. )
  2025. )
  2026. )
  2027. ​
  2028. ::==============================
  2029. ​
  2030. :: Check SKU value to find if there is any difference
  2031. ​
  2032. if not defined notwinact (
  2033. if %winbuild% GEQ 10240 (
  2034. %nul% set /a "sum=%slcSKU%+%regSKU%+%wmiSKU%"
  2035. set /a "sum/=3"
  2036. if not "!sum!"=="%slcSKU%" (
  2037. call :dk_color %Gray% "Checking SLC/WMI/REG SKU [Difference Found - SLC:%slcSKU% WMI:%wmiSKU% Reg:%regSKU%]"
  2038. )
  2039. ) else (
  2040. %nul% set /a "sum=%slcSKU%+%wmiSKU%"
  2041. set /a "sum/=2"
  2042. if not "!sum!"=="%slcSKU%" (
  2043. call :dk_color %Gray% "Checking SLC/WMI SKU [Difference Found - SLC:%slcSKU% WMI:%wmiSKU%]"
  2044. )
  2045. )
  2046. )
  2047. ​
  2048. ::==============================
  2049. ​
  2050. :: This "WLMS" service was included in previous Eval editions (which were activable) to automatically shut down the system every hour after the evaluation period expired and prevent SPPSVC from stopping.
  2051. ​
  2052. sc query wlms %nul%
  2053. ​
  2054. if %errorlevel% NEQ 1060 (
  2055. echo Checking Eval WLMS Service [Found]
  2056. )
  2057. ​
  2058. ::==============================
  2059. ​
  2060. :: Check SPP interference in IFEO
  2061. ​
  2062. for %%# in (SppEx%w%tComObj.exe SLsvc.exe sppsvc.exe sppsvc.exe\PerfOptions) do (
  2063. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ima%w%ge File Execu%w%tion Options\%%#" %nul% && (if defined _sppint (set "_sppint=!_sppint!, %%#") else (set "_sppint=%%#"))
  2064. )
  2065. if defined _sppint (
  2066. echo %_sppint% | find /i "PerfOptions" %nul% && (
  2067. call :dk_color %Red% "Checking SPP Interference In IFEO [%_sppint% - System might deactivate later]"
  2068. if not defined showfix (
  2069. call :dk_color %Blue% "%_fixmsg%"
  2070. echo:
  2071. )
  2072. set showfix=1
  2073. ) || (
  2074. echo Checking SPP In IFEO [%_sppint%]
  2075. )
  2076. )
  2077. ​
  2078. ::==============================
  2079. ​
  2080. :: Check and fix SkipRearm registry value
  2081. ​
  2082. if %winbuild% GEQ 7600 for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "SkipRearm" %nul6%') do if /i %%b NEQ 0x0 (
  2083. reg add "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "SkipRearm" /t REG_DWORD /d "0" /f %nul%
  2084. call :dk_color %Gray% "Checking SkipRearm [Default 0 Value Not Found. Changing To 0]"
  2085. %psc% "Start-Job { Stop-Service sppsvc -force } | Wait-Job -Timeout 20 | Out-Null"
  2086. )
  2087. ​
  2088. ::==============================
  2089. ​
  2090. :: Check SvcRestartTask status, this task helps in making sure system remains activated
  2091. ​
  2092. if %winbuild% GEQ 9200 if not exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-*EvalEdition~*.mum" (
  2093. %psc% "Get-WmiObject -Query 'SELECT Description FROM SoftwareLicensingProduct WHERE PartialProductKey IS NOT NULL AND LicenseDependsOn IS NULL' | Select-Object -Property Description" %nul2% | findstr /i "KMS_" %nul1% || (
  2094. for /f "delims=" %%a in ('%psc% "$s=New-Object -ComObject 'Schedule.Service'; $s.Connect(); $state=$s.GetFolder('\Microsoft\Windows\SoftwareProtectionPlatform').GetTask('SvcRestartTask').State; @{0='Unknown';1='Disabled';2='Queued';3='Ready';4='Running'}[$state]" %nul6%') do (set taskinfo=%%a)
  2095. ​
  2096. echo !taskinfo! | find /i "Ready" %nul% || (
  2097. reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "actionlist" /f %nul%
  2098. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\Microsoft\Windows\SoftwareProtectionPlatform\SvcRestartTask" %nul% || set taskinfo=Removed
  2099. if "!taskinfo!"=="" set "taskinfo=Not Found"
  2100. ​
  2101. call :dk_color %Gray% "Checking SvcRestartTask Status [!taskinfo!. System might deactivate later.]"
  2102. if not defined showfix (
  2103. echo "!taskinfo!" | findstr /i "Removed Not Found" %nul1% && (
  2104. set fixes=%fixes% %mas%in-place_repair_upgrade
  2105. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%in-place_repair_upgrade"
  2106. ) || (
  2107. call :dk_color %Blue% "Reboot your machine using the restart option and run the script again."
  2108. )
  2109. echo:
  2110. )
  2111. )
  2112. )
  2113. )
  2114. ​
  2115. ::==============================
  2116. ​
  2117. exit /b
  2118. ​
  2119. :: This code checks for invalid registry keys in HKLM\SYSTEM\WPA. This issue may appear even on healthy systems
  2120. ​
  2121. :wpatest:
  2122. $wpaKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $env:COMPUTERNAME).OpenSubKey("SYSTEM\\WPA")
  2123. $count = 0
  2124. foreach ($subkeyName in $wpaKey.GetSubKeyNames()) {
  2125. if ($subkeyName -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {
  2126. $count++
  2127. }
  2128. }
  2129. $osVersion = [System.Environment]::OSVersion.Version
  2130. $minBuildNumber = 14393
  2131. if ($osVersion.Build -ge $minBuildNumber) {
  2132. $subkeyHashTable = @{}
  2133. foreach ($subkeyName in $wpaKey.GetSubKeyNames()) {
  2134. if ($subkeyName -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {
  2135. $keyNumber = $subkeyName -replace '.*-', ''
  2136. $subkeyHashTable[$keyNumber] = $true
  2137. }
  2138. }
  2139. for ($i=1; $i -le $count; $i++) {
  2140. if (-not $subkeyHashTable.ContainsKey("$i")) {
  2141. Write-Output "Total Keys $count. Error Found - $i key does not exist."
  2142. $wpaKey.Close()
  2143. exit
  2144. }
  2145. }
  2146. }
  2147. $wpaKey.GetSubKeyNames() | ForEach-Object {
  2148. if ($_ -match '8DEC0AF1-0341-4b93-85CD-72606C2DF94C.*') {
  2149. if ($PSVersionTable.PSVersion.Major -lt 3) {
  2150. cmd /c "reg query "HKLM\SYSTEM\WPA\$_" /ve /t REG_BINARY >nul 2>&1"
  2151. if ($LASTEXITCODE -ne 0) {
  2152. Write-Host "Total Keys $count. Error Found - Binary Data is corrupt."
  2153. $wpaKey.Close()
  2154. exit
  2155. }
  2156. } else {
  2157. $subkey = $wpaKey.OpenSubKey($_)
  2158. $p = $subkey.GetValueNames()
  2159. if (($p | Where-Object { $subkey.GetValueKind($_) -eq [Microsoft.Win32.RegistryValueKind]::Binary }).Count -eq 0) {
  2160. Write-Host "Total Keys $count. Error Found - Binary Data is corrupt."
  2161. $wpaKey.Close()
  2162. exit
  2163. }
  2164. }
  2165. }
  2166. }
  2167. $count
  2168. $wpaKey.Close()
  2169. :wpatest:
  2170. ​
  2171. ::========================================================================================================================================
  2172. ​
  2173. :dk_color
  2174. ​
  2175. if %_NCS% EQU 1 (
  2176. echo %esc%[%~1%~2%esc%[0m
  2177. ) else if exist %ps% (
  2178. %psc% write-host -back '%1' -fore '%2' '%3'
  2179. ) else if not exist %ps% (
  2180. echo %~3
  2181. )
  2182. exit /b
  2183. ​
  2184. :dk_color2
  2185. ​
  2186. if %_NCS% EQU 1 (
  2187. echo %esc%[%~1%~2%esc%[%~3%~4%esc%[0m
  2188. ) else if exist %ps% (
  2189. %psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'
  2190. ) else if not exist %ps% (
  2191. echo %~3 %~6
  2192. )
  2193. exit /b
  2194. ​
  2195. ::========================================================================================================================================
  2196. ​
  2197. :dk_done
  2198. ​
  2199. echo:
  2200. if %_unattended%==1 timeout /t 2 & exit /b
  2201. ​
  2202. ​
  2203. if defined terminal (
  2204. call :dk_color %_Yellow% "Press [0] key to %_exitmsg%..."
  2205. choice /c 0 /n
  2206. ) else (
  2207. call :dk_color %_Yellow% "Press any key to %_exitmsg%..."
  2208. pause %nul1%
  2209. )
  2210. ​
  2211. exit /b
  2212. ​
  2213. ::========================================================================================================================================
  2214. ​
  2215. :: 1st column = Activation ID
  2216. :: 2nd column = Generic Retail/OEM/MAK Key
  2217. :: 3rd column = SKU ID
  2218. :: 4th column = Key part number
  2219. :: 5th column = 1 = activation is not working (at the time of writing this), 0 = activation is working
  2220. :: 6th column = Key Type
  2221. :: 7th column = WMI Edition ID (For reference only)
  2222. :: 8th column = Version name incase same Edition ID is used in different OS versions with different key
  2223. :: Separator = _
  2224. ​
  2225. ​
  2226. :hwiddata
  2227. ​
  2228. set f=
  2229. for %%# in (
  2230. 8b351c9c-f398-4515-9900-09df49427262_XGVPP-NMH47-7TTHJ-W3FW7-8H%f%V2C___4_X19-99683_0_OEM:NONSLP_Enterprise
  2231. c83cef07-6b72-4bbc-a28f-a00386872839_3V6Q6-NQXCX-V8YXR-9QCYV-QP%f%FCT__27_X19-98746_0_Volume:MAK_EnterpriseN
  2232. 4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T__48_X19-98841_0_____Retail_Professional
  2233. 9fbaf5d6-4d83-4422-870d-fdda6e5858aa_2B87N-8KFHP-DKV6R-Y2C8J-PK%f%CKT__49_X19-98859_0_____Retail_ProfessionalN
  2234. f742e4ff-909d-4fe9-aacb-3231d24a0c58_4CPRK-NM3K3-X6XXQ-RXX86-WX%f%CHW__98_X19-98877_0_____Retail_CoreN
  2235. 1d1bac85-7365-4fea-949a-96978ec91ae0_N2434-X9D7W-8PF6X-8DV9T-8T%f%YMD__99_X19-99652_0_____Retail_CoreCountrySpecific
  2236. 3ae2cc14-ab2d-41f4-972f-5e20142771dc_BT79Q-G7N6G-PGBYW-4YWX6-6F%f%4BT_100_X19-99661_0_____Retail_CoreSingleLanguage
  2237. 2b1f36bb-c1cd-4306-bf5c-a0367c2d97d8_YTMG3-N6DKC-DKB77-7M9GH-8H%f%VX7_101_X19-98868_0_____Retail_Core
  2238. 2a6137f3-75c0-4f26-8e3e-d83d802865a4_XKCNC-J26Q9-KFHD2-FKTHY-KD%f%72Y_119_X19-99606_0_OEM:NONSLP_PPIPro
  2239. e558417a-5123-4f6f-91e7-385c1c7ca9d4_YNMGQ-8RYV3-4PGQ3-C8XTP-7C%f%FBY_121_X19-98886_0_____Retail_Education
  2240. c5198a66-e435-4432-89cf-ec777c9d0352_84NGF-MHBT6-FXBX8-QWJK7-DR%f%R8H_122_X19-98892_0_____Retail_EducationN
  2241. f6e29426-a256-4316-88bf-cc5b0f95ec0c_PJB47-8PN2T-MCGDY-JTY3D-CB%f%CPV_125_X23-50331_1_Volume:MAK_EnterpriseS_Ge
  2242. cce9d2de-98ee-4ce2-8113-222620c64a27_KCNVH-YKWX8-GJJB9-H9FDT-6F%f%7W2_125_X22-66075_1_Volume:MAK_EnterpriseS_VB
  2243. d06934ee-5448-4fd1-964a-cd077618aa06_43TBQ-NH92J-XKTM7-KT3KK-P3%f%9PB_125_X21-83233_0_OEM:NONSLP_EnterpriseS_RS5
  2244. 706e0cfd-23f4-43bb-a9af-1a492b9f1302_NK96Y-D9CD8-W44CQ-R8YTK-DY%f%JWX_125_X21-05035_0_OEM:NONSLP_EnterpriseS_RS1
  2245. faa57748-75c8-40a2-b851-71ce92aa8b45_FWN7H-PF93Q-4GGP8-M8RF3-MD%f%WWW_125_X19-99617_0_OEM:NONSLP_EnterpriseS_TH
  2246. 3d1022d8-969f-4222-b54b-327f5a5af4c9_2DBW3-N2PJG-MVHW3-G7TDK-9H%f%KR4_126_X21-04921_0_Volume:MAK_EnterpriseSN_RS1
  2247. 60c243e1-f90b-4a1b-ba89-387294948fb6_NTX6B-BRYC2-K6786-F6MVQ-M7%f%V2X_126_X19-98770_0_Volume:MAK_EnterpriseSN_TH
  2248. 01eb852c-424d-4060-94b8-c10d799d7364_3XP6D-CRND4-DRYM2-GM84D-4G%f%G8Y_139_X23-37869_1_____Retail_ProfessionalCountrySpecific_Zn
  2249. eb6d346f-1c60-4643-b960-40ec31596c45_DXG7C-N36C4-C4HTG-X4T3X-2Y%f%V77_161_X21-43626_0_____Retail_ProfessionalWorkstation
  2250. 89e87510-ba92-45f6-8329-3afa905e3e83_WYPNQ-8C467-V2W6J-TX4WX-WT%f%2RQ_162_X21-43644_0_____Retail_ProfessionalWorkstationN
  2251. 62f0c100-9c53-4e02-b886-a3528ddfe7f6_8PTT6-RNW4C-6V7J2-C2D3X-MH%f%BPB_164_X21-04955_0_____Retail_ProfessionalEducation
  2252. 13a38698-4a49-4b9e-8e83-98fe51110953_GJTYN-HDMQY-FRR76-HVGC7-QP%f%F8P_165_X21-04956_0_____Retail_ProfessionalEducationN
  2253. df96023b-dcd9-4be2-afa0-c6c871159ebe_NJCF7-PW8QT-3324D-688JX-2Y%f%V66_175_X21-41295_0_____Retail_ServerRdsh
  2254. d4ef7282-3d2c-4cf0-9976-8854e64a8d1e_V3WVW-N2PV2-CGWC3-34QGF-VM%f%J2C_178_X21-32983_0_____Retail_Cloud
  2255. af5c9381-9240-417d-8d35-eb40cd03e484_NH9J3-68WK7-6FB93-4K3DF-DJ%f%4F6_179_X21-32987_0_____Retail_CloudN
  2256. 8ab9bdd1-1f67-4997-82d9-8878520837d9_XQQYW-NFFMW-XJPBH-K8732-CK%f%FFD_188_X21-99378_0_____OEM:DM_IoTEnterprise
  2257. ed655016-a9e8-4434-95d9-4345352c2552_QPM6N-7J2WJ-P88HH-P3YRH-YY%f%74H_191_X21-99682_0_OEM:NONSLP_IoTEnterpriseS_VB
  2258. 6c4de1b8-24bb-4c17-9a77-7b939414c298_CGK42-GYN6Y-VD22B-BX98W-J8%f%JXD_191_X23-12617_0_OEM:NONSLP_IoTEnterpriseS_Ge
  2259. d4bdc678-0a4b-4a32-a5b3-aaa24c3b0f24_K9VKN-3BGWV-Y624W-MCRMQ-BH%f%DCD_202_X22-53884_0_____Retail_CloudEditionN
  2260. 92fb8726-92a8-4ffc-94ce-f82e07444653_KY7PN-VR6RX-83W6Y-6DDYQ-T6%f%R4W_203_X22-53847_0_____Retail_CloudEdition
  2261. 5a85300a-bfce-474f-ac07-a30983e3fb90_N979K-XWD77-YW3GB-HBGH6-D3%f%2MH_205_X23-15042_0_____OEM:DM_IoTEnterpriseSK
  2262. 80083eae-7031-4394-9e88-4901973d56fe_P8Q7T-WNK7X-PMFXY-VXHBG-RR%f%K69_206_X23-62084_0_____OEM:DM_IoTEnterpriseK
  2263. 1bc2140b-285b-4351-b99c-26a126104b29_TMP2N-KGFHJ-PWM6F-68KCQ-3P%f%JBP_210_X23-60513_0_____Retail_WNC
  2264. ) do (
  2265. for /f "tokens=1-9 delims=_" %%A in ("%%#") do (
  2266. ​
  2267. REM Detect key
  2268. ​
  2269. if %1==key if %osSKU%==%%C if not defined key (
  2270. echo "!allapps! !altapplist!" | find /i "%%A" %nul1% && (
  2271. if %%E==1 set notworking=1
  2272. set key=%%B
  2273. )
  2274. )
  2275. ​
  2276. REM Generate ticket
  2277. ​
  2278. if %1==ticket if "%key%"=="%%B" (
  2279. set "SessionIdStr=OSMajorVersion=5;OSMinorVersion=1;OSPlatformId=2;PP=0;Pfn=Microsoft.Windows.%%C.%%D_8wekyb3d8bbwe;PKeyIID=465145217131314304264339481117862266242033457260311819664735280;"
  2280. %psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':sign\:.*';. ([scriptblock]::Create($f[1]))"
  2281. )
  2282. ​
  2283. )
  2284. )
  2285. exit /b
  2286. ​
  2287. ::========================================================================================================================================
  2288. ​
  2289. :sign:
  2290. $ErrorActionPreference = "Stop"
  2291. ​
  2292. function SignProperties {
  2293. param (
  2294. $Properties,
  2295. $rsa
  2296. )
  2297. ​
  2298. $sha256 = [Security.Cryptography.SHA256]::Create()
  2299. $bytes = [Text.Encoding]::UTF8.GetBytes($Properties)
  2300. $hash = $sha256.ComputeHash($bytes)
  2301. ​
  2302. $signature = $rsa.SignHash($hash, [Security.Cryptography.HashAlgorithmName]::SHA256, [Security.Cryptography.RSASignaturePadding]::Pkcs1)
  2303. return [Convert]::ToBase64String($signature)
  2304. ​
  2305. }
  2306. ​
  2307. [byte[]] $key = 0x07,0x02,0x00,0x00,0x00,0xA4,0x00,0x00,0x52,0x53,0x41,0x32,0x00,0x04,0x00,0x00,
  2308. 0x01,0x00,0x01,0x00,0x29,0x87,0xBA,0x3F,0x52,0x90,0x57,0xD8,0x12,0x26,0x6B,0x38,
  2309. 0xB2,0x3B,0xF9,0x67,0x08,0x4F,0xDD,0x8B,0xF5,0xE3,0x11,0xB8,0x61,0x3A,0x33,0x42,
  2310. 0x51,0x65,0x05,0x86,0x1E,0x00,0x41,0xDE,0xC5,0xDD,0x44,0x60,0x56,0x3D,0x14,0x39,
  2311. 0xB7,0x43,0x65,0xE9,0xF7,0x2B,0xA5,0xF0,0xA3,0x65,0x68,0xE9,0xE4,0x8B,0x5C,0x03,
  2312. 0x2D,0x36,0xFE,0x28,0x4C,0xD1,0x3C,0x3D,0xC1,0x90,0x75,0xF9,0x6E,0x02,0xE0,0x58,
  2313. 0x97,0x6A,0xCA,0x80,0x02,0x42,0x3F,0x6C,0x15,0x85,0x4D,0x83,0x23,0x6A,0x95,0x9E,
  2314. 0x38,0x52,0x59,0x38,0x6A,0x99,0xF0,0xB5,0xCD,0x53,0x7E,0x08,0x7C,0xB5,0x51,0xD3,
  2315. 0x8F,0xA3,0x0D,0xA0,0xFA,0x8D,0x87,0x3C,0xFC,0x59,0x21,0xD8,0x2E,0xD9,0x97,0x8B,
  2316. 0x40,0x60,0xB1,0xD7,0x2B,0x0A,0x6E,0x60,0xB5,0x50,0xCC,0x3C,0xB1,0x57,0xE4,0xB7,
  2317. 0xDC,0x5A,0x4D,0xE1,0x5C,0xE0,0x94,0x4C,0x5E,0x28,0xFF,0xFA,0x80,0x6A,0x13,0x53,
  2318. 0x52,0xDB,0xF3,0x04,0x92,0x43,0x38,0xB9,0x1B,0xD9,0x85,0x54,0x7B,0x14,0xC7,0x89,
  2319. 0x16,0x8A,0x4B,0x82,0xA1,0x08,0x02,0x99,0x23,0x48,0xDD,0x75,0x9C,0xC8,0xC1,0xCE,
  2320. 0xB0,0xD7,0x1B,0xD8,0xFB,0x2D,0xA7,0x2E,0x47,0xA7,0x18,0x4B,0xF6,0x29,0x69,0x44,
  2321. 0x30,0x33,0xBA,0xA7,0x1F,0xCE,0x96,0x9E,0x40,0xE1,0x43,0xF0,0xE0,0x0D,0x0A,0x32,
  2322. 0xB4,0xEE,0xA1,0xC3,0x5E,0x9B,0xC7,0x7F,0xF5,0x9D,0xD8,0xF2,0x0F,0xD9,0x8F,0xAD,
  2323. 0x75,0x0A,0x00,0xD5,0x25,0x43,0xF7,0xAE,0x51,0x7F,0xB7,0xDE,0xB7,0xAD,0xFB,0xCE,
  2324. 0x83,0xE1,0x81,0xFF,0xDD,0xA2,0x77,0xFE,0xEB,0x27,0x1F,0x10,0xFA,0x82,0x37,0xF4,
  2325. 0x7E,0xCC,0xE2,0xA1,0x58,0xC8,0xAF,0x1D,0x1A,0x81,0x31,0x6E,0xF4,0x8B,0x63,0x34,
  2326. 0xF3,0x05,0x0F,0xE1,0xCC,0x15,0xDC,0xA4,0x28,0x7A,0x9E,0xEB,0x62,0xD8,0xD8,0x8C,
  2327. 0x85,0xD7,0x07,0x87,0x90,0x2F,0xF7,0x1C,0x56,0x85,0x2F,0xEF,0x32,0x37,0x07,0xAB,
  2328. 0xB0,0xE6,0xB5,0x02,0x19,0x35,0xAF,0xDB,0xD4,0xA2,0x9C,0x36,0x80,0xC6,0xDC,0x82,
  2329. 0x08,0xE0,0xC0,0x5F,0x3C,0x59,0xAA,0x4E,0x26,0x03,0x29,0xB3,0x62,0x58,0x41,0x59,
  2330. 0x3A,0x37,0x43,0x35,0xE3,0x9F,0x34,0xE2,0xA1,0x04,0x97,0x12,0x9D,0x8C,0xAD,0xF7,
  2331. 0xFB,0x8C,0xA1,0xA2,0xE9,0xE4,0xEF,0xD9,0xC5,0xE5,0xDF,0x0E,0xBF,0x4A,0xE0,0x7A,
  2332. 0x1E,0x10,0x50,0x58,0x63,0x51,0xE1,0xD4,0xFE,0x57,0xB0,0x9E,0xD7,0xDA,0x8C,0xED,
  2333. 0x7D,0x82,0xAC,0x2F,0x25,0x58,0x0A,0x58,0xE6,0xA4,0xF4,0x57,0x4B,0xA4,0x1B,0x65,
  2334. 0xB9,0x4A,0x87,0x46,0xEB,0x8C,0x0F,0x9A,0x48,0x90,0xF9,0x9F,0x76,0x69,0x03,0x72,
  2335. 0x77,0xEC,0xC1,0x42,0x4C,0x87,0xDB,0x0B,0x3C,0xD4,0x74,0xEF,0xE5,0x34,0xE0,0x32,
  2336. 0x45,0xB0,0xF8,0xAB,0xD5,0x26,0x21,0xD7,0xD2,0x98,0x54,0x8F,0x64,0x88,0x20,0x2B,
  2337. 0x14,0xE3,0x82,0xD5,0x2A,0x4B,0x8F,0x4E,0x35,0x20,0x82,0x7E,0x1B,0xFE,0xFA,0x2C,
  2338. 0x79,0x6C,0x6E,0x66,0x94,0xBB,0x0A,0xEB,0xBA,0xD9,0x70,0x61,0xE9,0x47,0xB5,0x82,
  2339. 0xFC,0x18,0x3C,0x66,0x3A,0x09,0x2E,0x1F,0x61,0x74,0xCA,0xCB,0xF6,0x7A,0x52,0x37,
  2340. 0x1D,0xAC,0x8D,0x63,0x69,0x84,0x8E,0xC7,0x70,0x59,0xDD,0x2D,0x91,0x1E,0xF7,0xB1,
  2341. 0x56,0xED,0x7A,0x06,0x9D,0x5B,0x33,0x15,0xDD,0x31,0xD0,0xE6,0x16,0x07,0x9B,0xA5,
  2342. 0x94,0x06,0x7D,0xC1,0xE9,0xD6,0xC8,0xAF,0xB4,0x1E,0x2D,0x88,0x06,0xA7,0x63,0xB8,
  2343. 0xCF,0xC8,0xA2,0x6E,0x84,0xB3,0x8D,0xE5,0x47,0xE6,0x13,0x63,0x8E,0xD1,0x7F,0xD4,
  2344. 0x81,0x44,0x38,0xBF
  2345. ​
  2346. $rsa = New-Object Security.Cryptography.RSACryptoServiceProvider
  2347. $rsa.ImportCspBlob($key)
  2348. $SessionId = [Convert]::ToBase64String([Text.Encoding]::Unicode.GetBytes($env:SessionIdStr + [char]0))
  2349. $PropertiesStr = "OA3xOriginalProductId=;OA3xOriginalProductKey=;SessionId=$SessionId;TimeStampClient=2022-10-11T12:00:00Z"
  2350. $SignatureStr = SignProperties $PropertiesStr $rsa
  2351. ​
  2352. $xml = @"
  2353. <?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>$PropertiesStr</properties><signatures><signature name="clientLockboxKey" method="rsa-sha256">$SignatureStr</signature></signatures></genuineProperties></genuineAuthorization>
  2354. "@
  2355. [System.IO.File]::WriteAllText("$env:ProgramData\Microsoft\Windows\ClipSVC\GenuineTicket\GenuineTicket", ($xml -join ""), [System.Text.Encoding]::ASCII)
  2356. :sign:
  2357. ​
  2358. ::========================================================================================================================================
  2359. ​
  2360. :: Below code is used to get alternate edition name and key if current edition doesn't support HWID activation
  2361. ​
  2362. :: 1st column = Current SKU ID
  2363. :: 2nd column = Current Edition Name
  2364. :: 3rd column = Current Edition Activation ID
  2365. :: 4th column = Alternate Edition Activation ID
  2366. :: 5th column = Alternate Edition HWID Key
  2367. :: 6th column = Alternate Edition Name
  2368. :: Separator = _
  2369. ​
  2370. ​
  2371. :hwidfallback
  2372. ​
  2373. set notfoundaltactID=
  2374. if %_NoEditionChange%==1 exit /b
  2375. ​
  2376. for %%# in (
  2377. 125_EnterpriseS-2021_______________cce9d2de-98ee-4ce2-8113-222620c64a27_ed655016-a9e8-4434-95d9-4345352c2552_QPM6N-7J2WJ-P88HH-P3YRH-YY%f%74H_IoTEnterpriseS-2021
  2378. 125_EnterpriseS-2024_______________f6e29426-a256-4316-88bf-cc5b0f95ec0c_6c4de1b8-24bb-4c17-9a77-7b939414c298_CGK42-GYN6Y-VD22B-BX98W-J8%f%JXD_IoTEnterpriseS-2024
  2379. 138_ProfessionalSingleLanguage_____a48938aa-62fa-4966-9d44-9f04da3f72f2_4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T_Professional
  2380. 139_ProfessionalCountrySpecific____f7af7d09-40e4-419c-a49b-eae366689ebd_4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T_Professional
  2381. 139_ProfessionalCountrySpecific-Zn_01eb852c-424d-4060-94b8-c10d799d7364_4de7cb65-cdf1-4de9-8ae8-e3cce27b9f2c_VK7JG-NPHTM-C97JM-9MPGT-3V%f%66T_Professional
  2382. ) do (
  2383. for /f "tokens=1-6 delims=_" %%A in ("%%#") do if %osSKU%==%%A (
  2384. echo "!allapps! !altapplist!" | find /i "%%C" %nul1% && (
  2385. echo "!allapps!" | find /i "%%D" %nul1% && (
  2386. set altkey=%%E
  2387. set altedition=%%F
  2388. ) || (
  2389. set altedition=%%F
  2390. set notfoundaltactID=1
  2391. )
  2392. )
  2393. )
  2394. )
  2395. exit /b
  2396. ​
  2397. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2398. ​
  2399. :OhookActivation
  2400. ​
  2401. :: To activate Office with Ohook activation, run the script with "/Ohook" parameter or change 0 to 1 in below line
  2402. set _act=0
  2403. ​
  2404. :: To remove Ohook activation, run the script with /Ohook-Uninstall parameter or change 0 to 1 in below line
  2405. set _rem=0
  2406. ​
  2407. :: If value is changed in above lines or parameter is used then script will run in unattended mode
  2408. ​
  2409. ::========================================================================================================================================
  2410. ​
  2411. cls
  2412. color 07
  2413. title Ohook Activation %masver%
  2414. ​
  2415. set _args=
  2416. set _elev=
  2417. set _unattended=0
  2418. ​
  2419. set _args=%*
  2420. if defined _args set _args=%_args:"=%
  2421. if defined _args (
  2422. for %%A in (%_args%) do (
  2423. if /i "%%A"=="/Ohook" set _act=1
  2424. if /i "%%A"=="/Ohook-Uninstall" set _rem=1
  2425. if /i "%%A"=="-el" set _elev=1
  2426. )
  2427. )
  2428. ​
  2429. for %%A in (%_act% %_rem%) do (if "%%A"=="1" set _unattended=1)
  2430. ​
  2431. ::========================================================================================================================================
  2432. ​
  2433. if %_rem%==1 goto :oh_uninstall
  2434. ​
  2435. :oh_menu
  2436. ​
  2437. if %_unattended%==0 (
  2438. cls
  2439. if not defined terminal mode 76, 25
  2440. title Ohook Activation %masver%
  2441. call :oh_checkapps
  2442. echo:
  2443. echo:
  2444. echo:
  2445. echo:
  2446. if defined checknames (call :dk_color %_Yellow% " Close [!checknames!] before proceeding...")
  2447. echo ____________________________________________________________
  2448. echo:
  2449. echo [1] Install Ohook Office Activation
  2450. echo:
  2451. echo [2] Uninstall Ohook
  2452. echo ____________________________________________
  2453. echo:
  2454. echo:
  2455. echo [0] %_exitmsg%
  2456. echo ____________________________________________________________
  2457. echo:
  2458. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard [1,2,0]"
  2459. choice /C:120 /N
  2460. set _el=!errorlevel!
  2461. if !_el!==3 exit /b
  2462. if !_el!==2 goto :oh_uninstall
  2463. if !_el!==1 goto :oh_menu2
  2464. goto :oh_menu
  2465. )
  2466. ​
  2467. ::========================================================================================================================================
  2468. ​
  2469. :oh_menu2
  2470. ​
  2471. cls
  2472. if not defined terminal (
  2473. mode 140, 32
  2474. %psc% "&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=32;$B.Height=300;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}" %nul%
  2475. )
  2476. title Ohook Activation %masver%
  2477. ​
  2478. echo:
  2479. echo Initializing...
  2480. call :dk_chkmal
  2481. ​
  2482. if not exist %SysPath%\%_slexe% (
  2483. %eline%
  2484. echo [%SysPath%\%_slexe%] file is missing, aborting...
  2485. echo:
  2486. if not defined results (
  2487. call :dk_color %Blue% "Go back to Main Menu, select Troubleshoot and run DISM Restore and SFC Scan options."
  2488. call :dk_color %Blue% "After that, restart system and try activation again."
  2489. set fixes=%fixes% %mas%in-place_repair_upgrade
  2490. call :dk_color2 %Blue% "If it still shows the same error, do this - " %_Yellow% " %mas%in-place_repair_upgrade"
  2491. )
  2492. goto dk_done
  2493. )
  2494. ​
  2495. ::========================================================================================================================================
  2496. ​
  2497. set spp=SoftwareLicensingProduct
  2498. set sps=SoftwareLicensingService
  2499. ​
  2500. call :dk_reflection
  2501. call :dk_ckeckwmic
  2502. call :dk_product
  2503. call :dk_sppissue
  2504. ​
  2505. ::========================================================================================================================================
  2506. ​
  2507. set error=
  2508. ​
  2509. cls
  2510. echo:
  2511. call :dk_showosinfo
  2512. ​
  2513. ::========================================================================================================================================
  2514. ​
  2515. echo Initiating Diagnostic Tests...
  2516. ​
  2517. set "_serv=%_slser% Winmgmt"
  2518. ​
  2519. :: Software Protection
  2520. :: Windows Management Instrumentation
  2521. ​
  2522. set notwinact=1
  2523. set ohookact=1
  2524. call :dk_errorcheck
  2525. ​
  2526. call :oh_setspp
  2527. ​
  2528. :: Check unsupported office versions
  2529. ​
  2530. set o14c2r=
  2531. set o16uwp=
  2532. ​
  2533. set _68=HKLM\SOFTWARE\Microsoft\Office
  2534. set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office
  2535. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set o14msi=Office 2010 MSI )
  2536. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set o14msi=Office 2010 MSI )
  2537. %nul% reg query %_68%\14.0\CVH /f Click2run /k && set o14c2r=Office 2010 C2R
  2538. %nul% reg query %_86%\14.0\CVH /f Click2run /k && set o14c2r=Office 2010 C2R
  2539. ​
  2540. if %winbuild% GEQ 10240 (
  2541. for /f "delims=" %%a in ('%psc% "(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty InstallLocation)" %nul6%') do (if exist "%%a\Integration\Integrator.exe" set o16uwp=Office UWP )
  2542. )
  2543. ​
  2544. if not "%o14c2r%%o16uwp%"=="" (
  2545. echo:
  2546. call :dk_color %Red% "Checking Unsupported Office Install [ %o14c2r%%o16uwp%]"
  2547. if not "%o16uwp%"=="" call :dk_color %Blue% "Use TSforge option to activate it."
  2548. )
  2549. ​
  2550. if %winbuild% GEQ 10240 %psc% "Get-AppxPackage -name "Microsoft.MicrosoftOfficeHub"" | find /i "Office" %nul1% && (
  2551. set ohub=1
  2552. )
  2553. ​
  2554. ::========================================================================================================================================
  2555. ​
  2556. :: Check supported office versions
  2557. ​
  2558. call :oh_getpath
  2559. ​
  2560. sc query ClickToRunSvc %nul%
  2561. set error1=%errorlevel%
  2562. ​
  2563. if defined o16c2r if %error1% EQU 1060 (
  2564. call :dk_color %Red% "Checking ClickToRun Service [Not found, Office 16.0 files found]"
  2565. set o16c2r=
  2566. set error=1
  2567. )
  2568. ​
  2569. sc query OfficeSvc %nul%
  2570. set error2=%errorlevel%
  2571. ​
  2572. if defined o15c2r if %error1% EQU 1060 if %error2% EQU 1060 (
  2573. call :dk_color %Red% "Checking ClickToRun Service [Not found, Office 15.0 files found]"
  2574. set o15c2r=
  2575. set error=1
  2576. )
  2577. ​
  2578. if "%o16c2r%%o15c2r%%o16msi%%o15msi%%o14msi%"=="" (
  2579. set error=1
  2580. echo:
  2581. if not "%o14c2r%%o16uwp%"=="" (
  2582. call :dk_color %Red% "Checking Supported Office Install [Not Found]"
  2583. ) else (
  2584. call :dk_color %Red% "Checking Installed Office [Not Found]"
  2585. )
  2586. ​
  2587. if defined ohub (
  2588. echo:
  2589. echo You only have the Office Dashboard app installed; you need to install the full version of Office.
  2590. )
  2591. call :dk_color %Blue% "Download and install Office from the URL below, then try again."
  2592. set fixes=%fixes% %mas%genuine-installation-media
  2593. call :dk_color %_Yellow% "%mas%genuine-installation-media"
  2594. goto dk_done
  2595. )
  2596. ​
  2597. set multioffice=
  2598. if not "%o16c2r%%o15c2r%%o16msi%%o15msi%%o14msi%"=="1" set multioffice=1
  2599. if not "%o14c2r%%o16uwp%"=="" set multioffice=1
  2600. ​
  2601. if defined multioffice (
  2602. call :dk_color %Gray% "Checking Multiple Office Install [Found, its recommended to install only one version]"
  2603. )
  2604. ​
  2605. ::========================================================================================================================================
  2606. ​
  2607. :: Check Windows Server
  2608. ​
  2609. set winserver=
  2610. reg query "HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions" /v ProductType %nul2% | find /i "WinNT" %nul1% || set winserver=1
  2611. if not defined winserver (
  2612. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul2% | find /i "Server" %nul1% && set winserver=1
  2613. )
  2614. ​
  2615. ::========================================================================================================================================
  2616. ​
  2617. :: Check Smart App Control
  2618. ​
  2619. set "sacstate="
  2620. if %winbuild% GEQ 22621 (
  2621. for /f "tokens=3" %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\CI\Policy" /v VerifiedAndReputablePolicyState %nul6%') do set "sacstate=%%a"
  2622. )
  2623. if defined sacstate (
  2624. if "%sacstate%"=="0x1" (
  2625. call :dk_color %Gray% "Checking Smart App Control State [Enabled]"
  2626. call :dk_color %Blue% "Smart App Control may prevent you from opening Office after Ohook activation."
  2627. call :dk_color %Blue% "If blocked, stop and review the Windows Security detection; keep protection enabled."
  2628. ) else if "%sacstate%"=="0x2" (
  2629. call :dk_color %Gray% "Checking Smart App Control State [Evaluation]"
  2630. call :dk_color %Blue% "Smart App Control may prevent you from opening Office in the future if it enables itself after the evaluation period."
  2631. call :dk_color %Blue% "Keep Smart App Control enabled; do not bypass a security block."
  2632. )
  2633. )
  2634. ​
  2635. ::========================================================================================================================================
  2636. ​
  2637. :: Process Office 15.0 C2R
  2638. ​
  2639. if not defined o15c2r goto :starto16c2r
  2640. ​
  2641. call :oh_reset
  2642. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  2643. ​
  2644. set oVer=15
  2645. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg% /v InstallPath" %nul6%') do (set "_oRoot=%%b\root")
  2646. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\Configuration /v Platform" %nul6%') do (set "_oArch=%%b")
  2647. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\Configuration /v VersionToReport" %nul6%') do (set "_version=%%b")
  2648. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\Configuration /v ProductReleaseIds" %nul6%') do (set "_prids=%o15c2r_reg%\Configuration /v ProductReleaseIds" & set "_config=%o15c2r_reg%\Configuration")
  2649. if not defined _oArch for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\propertyBag /v Platform" %nul6%') do (set "_oArch=%%b")
  2650. if not defined _version for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\propertyBag /v version" %nul6%') do (set "_version=%%b")
  2651. if not defined _prids for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\propertyBag /v ProductReleaseId" %nul6%') do (set "_prids=%o15c2r_reg%\propertyBag /v ProductReleaseId" & set "_config=%o15c2r_reg%\propertyBag")
  2652. ​
  2653. echo "%o15c2r_reg%" | find /i "Wow6432Node" %nul1% && (set _tok=10) || (set _tok=9)
  2654. for /f "tokens=%_tok% delims=\" %%a in ('reg query %o15c2r_reg%\ProductReleaseIDs\Active %nul6% ^| findstr /i "Retail Volume"') do (
  2655. echo "!_oIds!" | find /i " %%a " %nul1% || (set "_oIds= !_oIds! %%a ")
  2656. )
  2657. ​
  2658. set "_oLPath=%_oRoot%\Licenses"
  2659. set "_oIntegrator=%_oRoot%\integration\integrator.exe"
  2660. ​
  2661. if /i "%_oArch%"=="x64" (set "_hookPath=%_oRoot%\vfs\System" & set "_hook=sppc64.dll")
  2662. if /i "%_oArch%"=="x86" (set "_hookPath=%_oRoot%\vfs\SystemX86" & set "_hook=sppc32.dll")
  2663. ​
  2664. call :oh_ppcpath
  2665. ​
  2666. echo:
  2667. echo Activating Office... [C2R ^| %_version% ^| %_oArch%]
  2668. ​
  2669. if not defined _oIds (
  2670. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  2671. set error=1
  2672. goto :starto16c2r
  2673. )
  2674. ​
  2675. if defined noOsppc (
  2676. call :dk_color %Red% "Checking OSPPC.DLL [Not found. Aborting activation...]"
  2677. call :dk_color %Blue% "%_fixmsg%"
  2678. set error=1
  2679. goto :starto16c2r
  2680. )
  2681. ​
  2682. call :oh_expiredpreview 2013
  2683. call :oh_fixprids
  2684. call :oh_process
  2685. if defined isOspp (
  2686. call :oh_hookinstall_ospp
  2687. ) else (
  2688. call :oh_hookinstall
  2689. )
  2690. ​
  2691. ::========================================================================================================================================
  2692. ​
  2693. :starto16c2r
  2694. ​
  2695. :: Process Office 16.0 C2R
  2696. ​
  2697. if not defined o16c2r goto :startmsi
  2698. ​
  2699. call :oh_reset
  2700. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  2701. ​
  2702. set oVer=16
  2703. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg% /v InstallPath" %nul6%') do (set "_oRoot=%%b\root")
  2704. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v Platform" %nul6%') do (set "_oArch=%%b")
  2705. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v VersionToReport" %nul6%') do (set "_version=%%b")
  2706. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v AudienceData" %nul6%') do (set "_AudienceData=^| %%b ")
  2707. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v ProductReleaseIds" %nul6%') do (set "_prids=%o16c2r_reg%\Configuration /v ProductReleaseIds" & set "_config=%o16c2r_reg%\Configuration")
  2708. ​
  2709. echo "%o16c2r_reg%" | find /i "Wow6432Node" %nul1% && (set _tok=9) || (set _tok=8)
  2710. for /f "tokens=%_tok% delims=\" %%a in ('reg query "%o16c2r_reg%\ProductReleaseIDs" /s /f ".16" /k %nul6% ^| findstr /i "Retail Volume"') do (
  2711. echo "!_oIds!" | find /i " %%a " %nul1% || (set "_oIds= !_oIds! %%a ")
  2712. )
  2713. set _oIds=%_oIds:.16=%
  2714. set _o16c2rIds=%_oIds%
  2715. ​
  2716. set "_oLPath=%_oRoot%\Licenses16"
  2717. set "_oIntegrator=%_oRoot%\integration\integrator.exe"
  2718. ​
  2719. if /i "%_oArch%"=="x64" (set "_hookPath=%_oRoot%\vfs\System" & set "_hook=sppc64.dll")
  2720. if /i "%_oArch%"=="x86" (set "_hookPath=%_oRoot%\vfs\SystemX86" & set "_hook=sppc32.dll")
  2721. ​
  2722. call :oh_ppcpath
  2723. ​
  2724. echo:
  2725. echo Activating Office... [C2R ^| %_version% %_AudienceData%^| %_oArch%]
  2726. ​
  2727. if not defined _oIds (
  2728. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  2729. set error=1
  2730. goto :startmsi
  2731. )
  2732. ​
  2733. if defined noOsppc (
  2734. call :dk_color %Red% "Checking OSPPC.DLL [Not found. Aborting activation...]"
  2735. call :dk_color %Blue% "%_fixmsg%"
  2736. set error=1
  2737. goto :startmsi
  2738. )
  2739. ​
  2740. call :oh_expiredpreview 2016 2019 2021 2024
  2741. call :oh_fixprids
  2742. call :oh_process
  2743. if defined isOspp (
  2744. call :oh_hookinstall_ospp
  2745. ) else (
  2746. call :oh_hookinstall
  2747. )
  2748. ​
  2749. ::========================================================================================================================================
  2750. ​
  2751. :: Old version of Office with subscription license key may show a banner to sign in to fix license issue.
  2752. :: Although script applies a Resiliency registry entry to fix that but it doesn't work on old office versions.
  2753. :: Below code checks that condition and informs the user to update the Office.
  2754. ​
  2755. if defined _sublic (
  2756. if not exist "%_oLPath%\Word2021VL_KMS_Client_AE*.xrm-ms" (
  2757. call :dk_color %Gray% "Checking Old Office With Sub License [Found. Update Office, otherwise, it may show a licensing issue-related banner.]"
  2758. )
  2759. )
  2760. ​
  2761. ::========================================================================================================================================
  2762. ​
  2763. :: mass{}grave{dot}dev/office-license-is-not-genuine
  2764. :: Add registry keys for volume products so that 'non-genuine' banner won't appear
  2765. :: Script already is using MAK instead of GVLK so it won't appear anyway, but registry keys are added incase Office installs default GVLK grace key for volume products
  2766. ​
  2767. set "kmskey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\0ff1ce15-a989-479d-af46-f275c6370663"
  2768. echo "%_oIds%" | find /i "Volume" %nul1% && (
  2769. if %winbuild% GEQ 9200 (
  2770. if not "%osarch%"=="x86" (
  2771. reg delete "%kmskey%" /f /reg:32 %nul%
  2772. reg add "%kmskey%" /f /v KeyManagementServiceName /t REG_SZ /d "127.0.0.1" /reg:32 %nul%
  2773. )
  2774. reg delete "%kmskey%" /f %nul%
  2775. reg add "%kmskey%" /f /v KeyManagementServiceName /t REG_SZ /d "127.0.0.1" %nul%
  2776. echo Adding a Registry to Prevent Banner [Successful]
  2777. )
  2778. )
  2779. ​
  2780. ::========================================================================================================================================
  2781. ​
  2782. :startmsi
  2783. ​
  2784. if defined o14msi call :oh_setspp 14
  2785. if defined o14msi call :oh_processmsi 14 %o14msi_reg%
  2786. call :oh_setspp
  2787. if defined o15msi call :oh_processmsi 15 %o15msi_reg%
  2788. if defined o16msi call :oh_processmsi 16 %o16msi_reg%
  2789. ​
  2790. ::========================================================================================================================================
  2791. ​
  2792. call :oh_clearblock
  2793. call :oh_uninstkey
  2794. call :oh_licrefresh
  2795. ​
  2796. ::========================================================================================================================================
  2797. ​
  2798. echo:
  2799. if not defined error (
  2800. call :dk_color %Green% "Office is permanently activated."
  2801. if defined ohub call :dk_color %Gray% "Office apps such as Word, Excel are activated, use them directly. Ignore 'Buy' button in Office dashboard app."
  2802. echo Help: %mas%troubleshoot
  2803. ) else (
  2804. call :dk_color %Red% "Some errors were detected."
  2805. if not defined ierror if not defined showfix call :dk_color %Blue% "%_fixmsg%"
  2806. set fixes=%fixes% %mas%troubleshoot
  2807. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  2808. )
  2809. ​
  2810. goto :dk_done
  2811. ​
  2812. ::========================================================================================================================================
  2813. ​
  2814. :oh_uninstall
  2815. ​
  2816. cls
  2817. if not defined terminal mode 145, 32
  2818. title Uninstall Ohook Activation %masver%
  2819. ​
  2820. set _present=
  2821. set _unerror=
  2822. call :oh_reset
  2823. call :oh_getpath
  2824. ​
  2825. echo:
  2826. echo Uninstalling Ohook activation...
  2827. echo:
  2828. ​
  2829. if defined o16c2r_reg (for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg% /v InstallPath" %nul6%') do (set "_16CHook=%%b\root\vfs"))
  2830. if defined o15c2r_reg (for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg% /v InstallPath" %nul6%') do (set "_15CHook=%%b\root\vfs"))
  2831. if defined o16msi_reg (for /f "skip=2 tokens=2*" %%a in ('"reg query %o16msi_reg%\Common\InstallRoot /v Path" %nul6%') do (set "_16MHook=%%b"))
  2832. if defined o15msi_reg (for /f "skip=2 tokens=2*" %%a in ('"reg query %o15msi_reg%\Common\InstallRoot /v Path" %nul6%') do (set "_15MHook=%%b"))
  2833. if defined o14msi_reg (for /f "skip=2 tokens=2*" %%a in ('"reg query %o14msi_reg%\Common\InstallRoot /v Path" %nul6%') do (set "_14MHook=%%b"))
  2834. ​
  2835. if defined _16CHook (if exist "%_16CHook%\System\sppc*dll" (set _present=1& del /s /f /q "%_16CHook%\System\sppc*dll" & if exist "%_16CHook%\System\sppc*dll" set _unerror=1))
  2836. if defined _16CHook (if exist "%_16CHook%\SystemX86\sppc*dll" (set _present=1& del /s /f /q "%_16CHook%\SystemX86\sppc*dll" & if exist "%_16CHook%\SystemX86\sppc*dll" set _unerror=1))
  2837. if defined _15CHook (if exist "%_15CHook%\System\sppc*dll" (set _present=1& del /s /f /q "%_15CHook%\System\sppc*dll" & if exist "%_15CHook%\System\sppc*dll" set _unerror=1))
  2838. if defined _15CHook (if exist "%_15CHook%\SystemX86\sppc*dll" (set _present=1& del /s /f /q "%_15CHook%\SystemX86\sppc*dll" & if exist "%_15CHook%\SystemX86\sppc*dll" set _unerror=1))
  2839. if defined _16MHook (if exist "%_16MHook%sppc*dll" (set _present=1& del /s /f /q "%_16MHook%sppc*dll" & if exist "%_16MHook%sppc*dll" set _unerror=1))
  2840. if defined _15MHook (if exist "%_15MHook%sppc*dll" (set _present=1& del /s /f /q "%_15MHook%sppc*dll" & if exist "%_15MHook%sppc*dll" set _unerror=1))
  2841. if defined _14MHook (if exist "%_14MHook%sppc*dll" (set _present=1& del /s /f /q "%_14MHook%sppc*dll" & if exist "%_14MHook%sppc*dll" set _unerror=1))
  2842. ​
  2843. for %%# in (14 15 16) do (
  2844. for %%A in ("%ProgramFiles%" "%ProgramW6432%" "%ProgramFiles(x86)%") do (
  2845. if exist "%%~A\Microsoft Office\Office%%#\sppc*dll" (set _present=1& del /s /f /q "%%~A\Microsoft Office\Office%%#\sppc*dll" & if exist "%%~A\Microsoft Office\Office%%#\sppc*dll" set _unerror=1)
  2846. )
  2847. )
  2848. ​
  2849. for %%# in (System SystemX86) do (
  2850. for %%G in ("Office 15" "Office") do (
  2851. for %%A in ("%ProgramFiles%" "%ProgramW6432%" "%ProgramFiles(x86)%") do (
  2852. if exist "%%~A\Microsoft %%~G\root\vfs\%%#\sppc*dll" (set _present=1& del /s /f /q "%%~A\Microsoft %%~G\root\vfs\%%#\sppc*dll" & if exist "%%~A\Microsoft %%~G\root\vfs\%%#\sppc*dll" set _unerror=1)
  2853. )
  2854. )
  2855. )
  2856. ​
  2857. ::==================================
  2858. ​
  2859. for %%# in (OSPPC.DLL sppcs.dll) do (
  2860. for %%A in ("%CommonProgramFiles%" "%CommonProgramW6432%" "%CommonProgramFiles(x86)%") do (
  2861. for %%G in ("%%~A\Microsoft Shared\OfficeSoftwareProtectionPlatform\%%#") do (
  2862. set size=0
  2863. set size=%%~zG
  2864. if !size! GEQ 1 if !size! LSS 100000 (
  2865. set _present=1
  2866. del /f /q "%%~G"
  2867. if exist "%%~G" (move /y "%%~G" "!_ttemp!\needsToBeDeleted%random%" %nul%)
  2868. if exist "%%~G" (set _unerror=1) else (echo Deleted file - %%~G)
  2869. )
  2870. if /i sppcs.dll==%%# if !size! GEQ 100000 (
  2871. move /y "%%~G" "%%~A\Microsoft Shared\OfficeSoftwareProtectionPlatform\OSPPC.DLL" %nul%
  2872. if exist "%%~G" (move /y "%%~A\Microsoft Shared\OfficeSoftwareProtectionPlatform\OSPPC.DLL" "!_ttemp!\needsToBeDeleted%random%" %nul%)
  2873. move /y "%%~G" "%%~A\Microsoft Shared\OfficeSoftwareProtectionPlatform\OSPPC.DLL" %nul%
  2874. if exist "%%~G" (set _unerror=1&echo Failed to rename sppcs.dll back to "%%~A\Microsoft Shared\OfficeSoftwareProtectionPlatform\OSPPC.DLL") else (echo Renamed sppcs.dll back to "%%~A\Microsoft Shared\OfficeSoftwareProtectionPlatform\OSPPC.DLL")
  2875. )
  2876. )
  2877. )
  2878. )
  2879. ​
  2880. ::==================================
  2881. ​
  2882. reg query HKCU\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency %nul% && (
  2883. echo:
  2884. echo Deleting - Registry keys for skipping license check
  2885. ​
  2886. reg load HKU\DEF_TEMP %SystemDrive%\Users\Default\NTUSER.DAT %nul%
  2887. reg query HKU\DEF_TEMP\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency %nul% && reg delete HKU\DEF_TEMP\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /f
  2888. reg unload HKU\DEF_TEMP %nul%
  2889. ​
  2890. set _sidlist=
  2891. for /f "tokens=* delims=" %%a in ('%psc% "$p = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'; Get-ChildItem $p | ForEach-Object { $pi = (Get-ItemProperty """"$p\$($_.PSChildName)"""").ProfileImagePath; if ($pi -like '*\Users\*' -and (Test-Path """"$pi\NTUSER.DAT"""") -and -not ($_.PSChildName -match '\.bak$')) { Split-Path $_.PSPath -Leaf } }" %nul6%') do (if defined _sidlist (set _sidlist=!_sidlist! %%a) else (set _sidlist=%%a))
  2892. ​
  2893. if not defined _sidlist (
  2894. for /f "delims=" %%a in ('%psc% "$explorerProc = Get-Process -Name explorer | Where-Object {$_.SessionId -eq (Get-Process -Id $pid).SessionId} | Select-Object -First 1; $sid = (gwmi -Query ('Select * From Win32_Process Where ProcessID=' + $explorerProc.Id)).GetOwnerSid().Sid; $sid" %nul6%') do (set _sidlist=%%a)
  2895. )
  2896. ​
  2897. for %%# in (!_sidlist!) do (
  2898. ​
  2899. reg query HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency %nul% && reg delete HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /f
  2900. ​
  2901. reg query HKU\%%#\Software %nul% || (
  2902. for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%%#" /v ProfileImagePath" %nul6%') do (
  2903. reg load HKU\%%# "%%b\NTUSER.DAT" %nul%
  2904. reg query HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency %nul% && reg delete HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /f
  2905. reg unload HKU\%%# %nul%
  2906. )
  2907. )
  2908. )
  2909. )
  2910. ​
  2911. ::==================================
  2912. ​
  2913. set "kmskey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\0ff1ce15-a989-479d-af46-f275c6370663"
  2914. reg query "%kmskey%" %nul% && (
  2915. echo:
  2916. echo Deleting - Registry keys for preventing non-genuine banner
  2917. reg delete "%kmskey%" /f
  2918. )
  2919. ​
  2920. reg query "%kmskey%" /reg:32 %nul% && (
  2921. reg delete "%kmskey%" /f /reg:32
  2922. )
  2923. ​
  2924. echo __________________________________________________________________________________________
  2925. echo:
  2926. ​
  2927. if not defined _present (
  2928. echo Ohook activation is not installed.
  2929. ) else (
  2930. if defined _unerror (
  2931. call :dk_color %Red% "Failed to uninstall Ohook activation."
  2932. call :oh_checkapps
  2933. if defined checknames (
  2934. call :dk_color %Blue% "Close [!checknames!] and try again."
  2935. call :dk_color %Blue% "If it is still not fixed, reboot your machine using the restart option and try again."
  2936. ) else (
  2937. call :dk_color %Blue% "Reboot your machine using the restart option and try again."
  2938. )
  2939. ) else (
  2940. call :dk_color %Green% "Successfully uninstalled Ohook activation."
  2941. )
  2942. )
  2943. echo __________________________________________________________________________________________
  2944. ​
  2945. goto :dk_done
  2946. ​
  2947. ::========================================================================================================================================
  2948. ​
  2949. :oh_reset
  2950. ​
  2951. set key=
  2952. set _oRoot=
  2953. set _oArch=
  2954. set _oIds=
  2955. set _oLPath=
  2956. set _hookPath=
  2957. set _hook=
  2958. set _sppcPath=
  2959. set _osppPath=
  2960. set _actid=
  2961. set _prod=
  2962. set _lic=
  2963. set _arr=
  2964. set _prids=
  2965. set _config=
  2966. set _version=
  2967. set _License=
  2968. exit /b
  2969. ​
  2970. ::========================================================================================================================================
  2971. ​
  2972. :oh_getpath
  2973. ​
  2974. set o16c2r=
  2975. set o15c2r=
  2976. set o16msi=
  2977. set o15msi=
  2978. set o14msi=
  2979. ​
  2980. set _68=HKLM\SOFTWARE\Microsoft\Office
  2981. set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office
  2982. ​
  2983. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\ClickToRun /v InstallPath" %nul6%') do if exist "%%b\root\Licenses16\ProPlus*.xrm-ms" (set o16c2r=1&set o16c2r_reg=%_86%\ClickToRun)
  2984. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\ClickToRun /v InstallPath" %nul6%') do if exist "%%b\root\Licenses16\ProPlus*.xrm-ms" (set o16c2r=1&set o16c2r_reg=%_68%\ClickToRun)
  2985. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\15.0\ClickToRun /v InstallPath" %nul6%') do if exist "%%b\root\Licenses\ProPlus*.xrm-ms" (set o15c2r=1&set o15c2r_reg=%_86%\15.0\ClickToRun)
  2986. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\15.0\ClickToRun /v InstallPath" %nul6%') do if exist "%%b\root\Licenses\ProPlus*.xrm-ms" (set o15c2r=1&set o15c2r_reg=%_68%\15.0\ClickToRun)
  2987. ​
  2988. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set o16msi=1&set o16msi_reg=%_86%\16.0)
  2989. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set o16msi=1&set o16msi_reg=%_68%\16.0)
  2990. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set o15msi=1&set o15msi_reg=%_86%\15.0)
  2991. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set o15msi=1&set o15msi_reg=%_68%\15.0)
  2992. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set o14msi=1&set o14msi_reg=%_86%\14.0)
  2993. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set o14msi=1&set o14msi_reg=%_68%\14.0)
  2994. ​
  2995. exit /b
  2996. ​
  2997. ::========================================================================================================================================
  2998. ​
  2999. :oh_expiredpreview
  3000. ​
  3001. echo %_oIds% | find /i "Volume" %nul% || exit /b
  3002. ​
  3003. for %%# in (%*) do (
  3004. if %%#==2013 set _offver=
  3005. if %%#==2016 set _offver=
  3006. if %%#==2019 set _offver=2019
  3007. if %%#==2021 set _offver=2021
  3008. if %%#==2024 set _offver=2024
  3009. if exist "!_oLPath!\ProPlus!_offver!PreviewVL_*.xrm-ms" if not exist "!_oLPath!\ProPlus!_offver!VL_*.xrm-ms" (
  3010. set error=1
  3011. set showfix=1
  3012. call :dk_color %Red% "Checking Expired Preview Products [Office %%# Preview Found]"
  3013. call :dk_color %Blue% "Please run the Office updates first, and then attempt to activate it again."
  3014. )
  3015. )
  3016. ​
  3017. exit /b
  3018. ​
  3019. ::========================================================================================================================================
  3020. ​
  3021. :oh_ppcpath
  3022. ​
  3023. if not defined isOspp (
  3024. if not "%osarch%"=="x86" (
  3025. if /i "%_oArch%"=="x64" set "_sppcPath=%SystemRoot%\System32\sppc.dll"
  3026. if /i "%_oArch%"=="x86" set "_sppcPath=%SystemRoot%\SysWOW64\sppc.dll"
  3027. ) else (
  3028. set "_sppcPath=%SystemRoot%\System32\sppc.dll"
  3029. )
  3030. )
  3031. ​
  3032. set noOsppc=
  3033. set _hook68=
  3034. set _hook86=
  3035. set _osppPath68=
  3036. set _osppPath86=
  3037. ​
  3038. if defined isOspp (
  3039. if not "%osarch%"=="x86" (
  3040. if /i "%_oArch%"=="x64" (
  3041. for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform /v Path" %nul6%') do (set "_osppPath68=%%b")
  3042. if not exist "!_osppPath68!OSPPC.DLL" set noOsppc=1
  3043. )
  3044. if /i "%_oArch%"=="x86" (
  3045. for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform /v Path" %nul6%') do (set "_osppPath68=%%b")
  3046. for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\OfficeSoftwareProtectionPlatform /v Path" %nul6%') do (set "_osppPath86=%%b")
  3047. if not exist "!_osppPath68!OSPPC.DLL" set noOsppc=1
  3048. if not exist "!_osppPath86!OSPPC.DLL" set noOsppc=1
  3049. )
  3050. ) else (
  3051. for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform /v Path" %nul6%') do (set "_osppPath86=%%b")
  3052. if not exist "!_osppPath86!OSPPC.DLL" set noOsppc=1
  3053. )
  3054. if "!_osppPath68:~-1!"=="\" set "_osppPath68=!_osppPath68:~0,-1!"
  3055. if "!_osppPath86:~-1!"=="\" set "_osppPath86=!_osppPath86:~0,-1!"
  3056. )
  3057. ​
  3058. if defined _osppPath68 set _hook68=sppc64.dll
  3059. if defined _osppPath86 set _hook86=sppc32.dll
  3060. ​
  3061. exit /b
  3062. ​
  3063. ::========================================================================================================================================
  3064. ​
  3065. :: Some Office Retail to Volume converter tools may edit the ProductReleaseIds to add VL products. This code restores it because it may affect features.
  3066. ​
  3067. :oh_fixprids
  3068. ​
  3069. if not defined _prids (
  3070. call :dk_color %Gray% "Checking ProductReleaseIds In Registry [Not Found]"
  3071. exit /b
  3072. )
  3073. ​
  3074. set _pridsR=
  3075. set _pridsE=
  3076. for /f "skip=2 tokens=2*" %%a in ('"reg query %_prids%" %nul6%') do (set "_pridsR=%%b")
  3077. ​
  3078. set _pridsR=%_pridsR:,= %
  3079. for %%# in (%_pridsR%) do (echo %%# | findstr /I "%_oIds%" %nul1% || set _pridsE=1)
  3080. for %%# in (%_oIds%) do (echo %%# | findstr /I "%_pridsR%" %nul1% || set _pridsE=1)
  3081. ​
  3082. if not defined _pridsE exit /b
  3083. reg add %_prids% /t REG_SZ /d "" /f %nul1%
  3084. ​
  3085. for %%# in (%_oIds%) do (
  3086. for /f "skip=2 tokens=2*" %%a in ('reg query %_prids%') do if not "%%b"=="" (
  3087. reg add %_prids% /t REG_SZ /d "%%b,%%#" /f %nul1%
  3088. ) else (
  3089. reg add %_prids% /t REG_SZ /d "%%#" /f %nul1%
  3090. )
  3091. )
  3092. ​
  3093. exit /b
  3094. ​
  3095. ::========================================================================================================================================
  3096. ​
  3097. :oh_installlic
  3098. ​
  3099. if not defined _oLPath exit /b
  3100. ​
  3101. if defined _oIntegrator (
  3102. if %oVer%==16 (
  3103. "!_oIntegrator!" /I /License PRIDName=%_License%.16 PidKey=%key% %nul%
  3104. ) else (
  3105. "!_oIntegrator!" /I /License PRIDName=%_License% PidKey=%key% %nul%
  3106. )
  3107. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  3108. echo "!allapps!" | find /i "!_actid!" %nul1% && exit /b
  3109. )
  3110. ​
  3111. :: Fallback to manual method to install licenses incase integrator.exe is not working
  3112. ​
  3113. set _License=%_License:XVolume=XC2RVL_%
  3114. ​
  3115. set _License=%_License:O365EduCloudRetail=O365EduCloudEDUR_%
  3116. ​
  3117. set _License=%_License:ProjectProRetail=ProjectProO365R_%
  3118. set _License=%_License:ProjectStdRetail=ProjectStdO365R_%
  3119. set _License=%_License:VisioProRetail=VisioProO365R_%
  3120. set _License=%_License:VisioStdRetail=VisioStdO365R_%
  3121. ​
  3122. if defined _preview set _License=%_License:Volume=PreviewVL_%
  3123. ​
  3124. set _License=%_License:Retail=R_%
  3125. set _License=%_License:Volume=VL_%
  3126. ​
  3127. for %%# in ("!_oLPath!\client-issuance-*.xrm-ms") do (
  3128. if defined _arr (set "_arr=!_arr!;"!_oLPath!\%%~nx#"") else (set "_arr="!_oLPath!\%%~nx#"")
  3129. )
  3130. ​
  3131. for %%# in ("!_oLPath!\%_License%*.xrm-ms") do (
  3132. if defined _arr (set "_arr=!_arr!;"!_oLPath!\%%~nx#"") else (set "_arr="!_oLPath!\%%~nx#"")
  3133. )
  3134. ​
  3135. %psc% "$sls = Get-WmiObject %sps%; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\:.*';. ([scriptblock]::Create($f[1])); InstallLicenseArr '!_arr!'; InstallLicenseFile '"!_oLPath!\pkeyconfig-office.xrm-ms"'" %nul%
  3136. ​
  3137. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  3138. echo "!allapps!" | find /i "!_actid!" %nul1% || (
  3139. set error=1
  3140. call :dk_color %Red% "Installing Missing License Files [Office %oVer%.0 %_prod%] [Failed]"
  3141. )
  3142. ​
  3143. exit /b
  3144. ​
  3145. ::========================================================================================================================================
  3146. ​
  3147. :oh_hookinstall
  3148. ​
  3149. set ierror=
  3150. set hasherror=
  3151. ​
  3152. if %_hook%==sppc32.dll set offset=2564
  3153. if %_hook%==sppc64.dll set offset=3076
  3154. ​
  3155. ::======================================
  3156. ​
  3157. :: Remove previous Install
  3158. ​
  3159. for %%# in (sppcs.dll sppc.dll) do (
  3160. del /f /q "%_hookPath%\%%#" %nul%
  3161. if exist "%_hookPath%\%%#" (move /y "%_hookPath%\%%#" "!_ttemp!\needsToBeDeleted%random%" %nul%)
  3162. if exist "%_hookPath%\%%#" (set "ierror=Remove Previous Ohook Install [%%#]")
  3163. )
  3164. ​
  3165. if defined ierror goto :oh_hookinstall_error
  3166. ​
  3167. ::======================================
  3168. ​
  3169. mklink "%_hookPath%\sppcs.dll" "%_sppcPath%" %nul%
  3170. if not exist "%_hookPath%\sppcs.dll" (
  3171. set ierror=mklink sppcs.dll
  3172. goto :oh_hookinstall_error
  3173. )
  3174. ​
  3175. set exhook=
  3176. if exist "!_work!\BIN\%_hook%" set exhook=1
  3177. ​
  3178. if not exist "%_hookPath%\sppc.dll" (
  3179. if defined exhook (
  3180. pushd "!_work!\BIN\"
  3181. copy /y /b "%_hook%" "%_hookPath%\sppc.dll" %nul%
  3182. popd
  3183. ) else (
  3184. call :oh_extractdll "%_hookPath%\sppc.dll" "%offset%"
  3185. )
  3186. )
  3187. if not exist "%_hookPath%\sppc.dll" (
  3188. set ierror=Copy
  3189. goto :oh_hookinstall_error
  3190. )
  3191. ​
  3192. echo:
  3193. echo Symlinking System's sppc.dll ["%_hookPath%\sppcs.dll"] [Successful]
  3194. if defined exhook (
  3195. echo Copying Custom %_hook% to ["%_hookPath%\sppc.dll"] [Successful]
  3196. ) else (
  3197. echo Extracting Custom %_hook% to ["%_hookPath%\sppc.dll"] [Successful]
  3198. )
  3199. ​
  3200. goto :oh_hookinstall_error
  3201. ​
  3202. ::========================================================================================================================================
  3203. ​
  3204. :oh_hookinstall_ospp
  3205. ​
  3206. set ierror=
  3207. set hasherror=
  3208. ​
  3209. if defined _hook86 set offset86=2564
  3210. if defined _hook68 set offset68=3076
  3211. ​
  3212. ::======================================
  3213. ​
  3214. :: Remove previous Install
  3215. ​
  3216. for %%# in (OSPPC.DLL sppcs.dll) do (
  3217. for %%A in ("%_osppPath68%\%%#" "%_osppPath86%\%%#") do (
  3218. set size=0
  3219. set size=%%~zA
  3220. if !size! GEQ 1 if !size! LSS 100000 (
  3221. del /f /q "%%~A" %nul%
  3222. if exist "%%~A" (move /y "%%~A" "!_ttemp!\needsToBeDeleted%random%" %nul%)
  3223. if exist "%%~A" (set "ierror=Remove Previous Ohook Install [%%#]")
  3224. )
  3225. )
  3226. )
  3227. ​
  3228. if defined ierror goto :oh_hookinstall_error
  3229. ​
  3230. for %%A in ("%_osppPath68%" "%_osppPath86%") do (
  3231. if exist "%%~A\sppcs.dll" (move /y "%%~A\sppcs.dll" "%%~A\OSPPC.DLL" %nul%)
  3232. if exist "%%~A\sppcs.dll" (
  3233. move /y "%%~A\OSPPC.DLL" "!_ttemp!\needsToBeDeleted%random%" %nul%
  3234. move /y "%%~A\sppcs.dll" "%%~A\OSPPC.DLL" %nul%
  3235. )
  3236. if exist "%%~A\sppcs.dll" (set "ierror=Move sppcs.dll back to OSPPC.DLL")
  3237. )
  3238. ​
  3239. del /f /q "%_hookPath%\sppcs.dll" %nul%
  3240. if exist "%_hookPath%\sppcs.dll" (move /y "%_hookPath%\sppcs.dll" "!_ttemp!\needsToBeDeleted%random%" %nul%)
  3241. if exist "%_hookPath%\sppcs.dll" (set "ierror=Remove Previous Ohook mklink sppcs.dll")
  3242. ​
  3243. if defined ierror goto :oh_hookinstall_error
  3244. ​
  3245. ::======================================
  3246. ​
  3247. if defined _osppPath68 (move /y "%_osppPath68%\OSPPC.DLL" "%_osppPath68%\sppcs.dll" %nul% & if not exist "%_osppPath68%\sppcs.dll" set ierror=1)
  3248. if defined _osppPath86 (move /y "%_osppPath86%\OSPPC.DLL" "%_osppPath86%\sppcs.dll" %nul% & if not exist "%_osppPath86%\sppcs.dll" set ierror=1)
  3249. ​
  3250. if defined ierror (
  3251. set "ierror=Rename OSPPC.DLL"
  3252. goto :oh_hookinstall_error
  3253. )
  3254. ​
  3255. if defined _osppPath68 if defined _osppPath86 (mklink "%_hookPath%\sppcs.dll" "%_osppPath86%\sppcs.dll" %nul%)
  3256. if defined _osppPath68 if not defined _osppPath86 (mklink "%_hookPath%\sppcs.dll" "%_osppPath68%\sppcs.dll" %nul%)
  3257. if defined _osppPath86 if not defined _osppPath68 (mklink "%_hookPath%\sppcs.dll" "%_osppPath86%\sppcs.dll" %nul%)
  3258. ​
  3259. if not exist "%_hookPath%\sppcs.dll" (
  3260. set ierror=mklink sppcs.dll
  3261. goto :oh_hookinstall_error
  3262. )
  3263. ​
  3264. set exhook=
  3265. if exist "!_work!\BIN\%_hook68%" if exist "!_work!\BIN\%_hook86%" set exhook=1
  3266. ​
  3267. if defined exhook (
  3268. pushd "!_work!\BIN\"
  3269. if defined _osppPath68 (copy /y /b "%_hook68%" "%_osppPath68%\OSPPC.DLL" %nul%)
  3270. if defined _osppPath86 (copy /y /b "%_hook86%" "%_osppPath86%\OSPPC.DLL" %nul%)
  3271. popd
  3272. ) else (
  3273. if defined _osppPath68 (set _hook=%_hook68%&call :oh_extractdll "%_osppPath68%\OSPPC.DLL" "%offset68%")
  3274. if defined _osppPath86 (set _hook=%_hook86%&call :oh_extractdll "%_osppPath86%\OSPPC.DLL" "%offset86%")
  3275. )
  3276. ​
  3277. if defined _osppPath68 (if not exist "%_osppPath68%\OSPPC.DLL" set ierror=1)
  3278. if defined _osppPath86 (if not exist "%_osppPath86%\OSPPC.DLL" set ierror=1)
  3279. ​
  3280. if defined ierror (
  3281. set ierror=Copy
  3282. goto :oh_hookinstall_error
  3283. )
  3284. ​
  3285. echo:
  3286. if defined _osppPath68 (echo Renaming OSPPC.DLL to sppcs.dll ["%_osppPath68%\sppcs.dll"])
  3287. if defined _osppPath86 (echo Renaming OSPPC.DLL to sppcs.dll ["%_osppPath86%\sppcs.dll"])
  3288. if defined exhook (
  3289. if defined _osppPath68 (echo Copying Custom %_hook68% to ["%_osppPath68%\OSPPC.DLL"])
  3290. if defined _osppPath86 (echo Copying Custom %_hook86% to ["%_osppPath86%\OSPPC.DLL"])
  3291. ) else (
  3292. if defined _osppPath68 (echo Extracting Custom %_hook68% to ["%_osppPath68%\OSPPC.DLL"])
  3293. if defined _osppPath86 (echo Extracting Custom %_hook86% to ["%_osppPath86%\OSPPC.DLL"])
  3294. )
  3295. ​
  3296. echo Symlinking Renamed sppcs.dll ["%_hookPath%\sppcs.dll"]
  3297. ​
  3298. ::========================================================================================================================================
  3299. ​
  3300. :oh_hookinstall_error
  3301. ​
  3302. if defined ierror (
  3303. set error=1
  3304. call :dk_color %Red% "Installing Ohook [Failed to %ierror%]"
  3305. echo:
  3306. call :oh_checkapps
  3307. if defined checknames (
  3308. call :dk_color %Blue% "Close [!checknames!] and try again."
  3309. call :dk_color %Blue% "If it is still not fixed, reboot your machine using the restart option and try again."
  3310. ) else (
  3311. if /i not "%ierror%"=="Copy" call :dk_color %Blue% "Reboot your machine using the restart option and try again."
  3312. if /i "%ierror%"=="Copy" call :dk_color %Blue% "If you are using any third-party antivirus, check if it is blocking the script."
  3313. )
  3314. echo:
  3315. )
  3316. ​
  3317. if not defined exhook if not defined ierror (
  3318. if defined hasherror (
  3319. set error=1
  3320. set ierror=1
  3321. call :dk_color %Red% "Modifying Hash of Custom sppcs.dll [Failed]"
  3322. ) else (
  3323. echo Modifying Hash of Custom sppcs.dll [Successful]
  3324. )
  3325. )
  3326. ​
  3327. exit /b
  3328. ​
  3329. ::========================================================================================================================================
  3330. ​
  3331. :oh_setspp
  3332. ​
  3333. set isOspp=
  3334. if %winbuild% GEQ 9200 (
  3335. set spp=SoftwareLicensingProduct
  3336. set sps=SoftwareLicensingService
  3337. ) else (
  3338. set isOspp=1
  3339. set spp=OfficeSoftwareProtectionProduct
  3340. set sps=OfficeSoftwareProtectionService
  3341. )
  3342. if "%1"=="14" (
  3343. set isOspp=1
  3344. set spp=OfficeSoftwareProtectionProduct
  3345. set sps=OfficeSoftwareProtectionService
  3346. )
  3347. exit /b
  3348. ​
  3349. ::========================================================================================================================================
  3350. ​
  3351. :oh_process
  3352. ​
  3353. for %%# in (%_oIds%) do (
  3354. ​
  3355. set key=
  3356. set _actid=
  3357. set _lic=
  3358. set _preview=
  3359. set _License=%%#
  3360. ​
  3361. echo %%# | find /i "2024" %nul% && (
  3362. if exist "!_oLPath!\ProPlus2024PreviewVL_*.xrm-ms" if not exist "!_oLPath!\ProPlus2024VL_*.xrm-ms" set _preview=-Preview
  3363. )
  3364. set _prod=%%#!_preview!
  3365. ​
  3366. call :ohookdata getinfo !_prod!
  3367. ​
  3368. if not "!key!"=="" (
  3369. echo "!allapps!" | find /i "!_actid!" %nul1% || call :oh_installlic
  3370. if not %oVer%==14 set generickey=1
  3371. call :dk_inskey "[!key!] [!_prod!] [!_lic!]"
  3372. ) else (
  3373. set error=1
  3374. call :dk_color %Red% "Checking Product In Script [Office %oVer%.0 !_prod! key not found in script]"
  3375. call :dk_color %Blue% "Make sure you are using the latest version of MAS."
  3376. set fixes=%fixes% %mas%
  3377. call :dk_color %_Yellow% "%mas%"
  3378. )
  3379. )
  3380. ​
  3381. :: Add SharedComputerLicensing registry key if Retail Office C2R is installed on Windows Server
  3382. :: https://learn.microsoft.com/en-us/office/troubleshoot/office-suite-issues/click-to-run-office-on-terminal-server
  3383. ​
  3384. if defined winserver if defined _config if exist "%_oLPath%\Word2019VL_KMS_Client_AE*.xrm-ms" (
  3385. echo %_oIds% | find /i "Retail" %nul1% && (
  3386. set scaIsNeeded=1
  3387. reg add %_config% /v SharedComputerLicensing /t REG_SZ /d "1" /f %nul1%
  3388. echo Adding SharedComputerLicensing Reg [Successful] [Needed on Server With Retail Office]"
  3389. )
  3390. )
  3391. ​
  3392. exit /b
  3393. ​
  3394. ::========================================================================================================================================
  3395. ​
  3396. :oh_processmsi
  3397. ​
  3398. :: Process Office MSI Version
  3399. ​
  3400. call :oh_reset
  3401. if "%1"=="14" (
  3402. call :dk_actids 59a52881-a989-479d-af46-f275c6370663
  3403. ) else (
  3404. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  3405. )
  3406. ​
  3407. set oVer=%1
  3408. for /f "skip=2 tokens=2*" %%a in ('"reg query %2\Common\InstallRoot /v Path" %nul6%') do (set "_oRoot=%%b")
  3409. for /f "skip=2 tokens=2*" %%a in ('"reg query %2\Common\ProductVersion /v LastProduct" %nul6%') do (set "_version=%%b")
  3410. if "%_oRoot:~-1%"=="\" set "_oRoot=%_oRoot:~0,-1%"
  3411. ​
  3412. echo "%2" | find /i "Wow6432Node" %nul1% && set _oArch=x86
  3413. if not "%osarch%"=="x86" if not defined _oArch set _oArch=x64
  3414. if "%osarch%"=="x86" set _oArch=x86
  3415. ​
  3416. if /i "%_oArch%"=="x64" (set "_hookPath=%_oRoot%" & set "_hook=sppc64.dll")
  3417. if /i "%_oArch%"=="x86" (set "_hookPath=%_oRoot%" & set "_hook=sppc32.dll")
  3418. ​
  3419. call :oh_ppcpath
  3420. ​
  3421. call :msiofficedata %2
  3422. ​
  3423. echo:
  3424. echo Activating Office... [MSI ^| %_version% ^| %_oArch%]
  3425. ​
  3426. if not defined _oIds (
  3427. set error=1
  3428. call :dk_color %Red% "Checking Installed Products [Product IDs not found, aborting activation...]"
  3429. exit /b
  3430. )
  3431. ​
  3432. if defined noOsppc (
  3433. call :dk_color %Red% "Checking OSPPC.DLL [Not found. Aborting activation...]"
  3434. call :dk_color %Blue% "%_fixmsg%"
  3435. set error=1
  3436. exit /b
  3437. )
  3438. ​
  3439. if %oVer%==14 if defined SingleImage (
  3440. echo Checking Installed Products [SingleImage product found, Professional Retail key will be used for activation]
  3441. )
  3442. ​
  3443. call :oh_process
  3444. if defined isOspp (
  3445. call :oh_hookinstall_ospp
  3446. ) else (
  3447. call :oh_hookinstall
  3448. )
  3449. ​
  3450. exit /b
  3451. ​
  3452. ::========================================================================================================================================
  3453. ​
  3454. :oh_clearblock
  3455. ​
  3456. :: Find remnants of Office vNext/shared/device license block and remove it because it stops other licenses from appearing
  3457. :: https://learn.microsoft.com/en-us/office/troubleshoot/activation/reset-office-365-proplus-activation-state
  3458. ​
  3459. set _sidlist=
  3460. for /f "tokens=* delims=" %%a in ('%psc% "$p = 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList'; Get-ChildItem $p | ForEach-Object { $pi = (Get-ItemProperty """"$p\$($_.PSChildName)"""").ProfileImagePath; if ($pi -like '*\Users\*' -and (Test-Path """"$pi\NTUSER.DAT"""") -and -not ($_.PSChildName -match '\.bak$')) { Split-Path $_.PSPath -Leaf } }" %nul6%') do (if defined _sidlist (set _sidlist=!_sidlist! %%a) else (set _sidlist=%%a))
  3461. ​
  3462. if not defined _sidlist (
  3463. for /f "delims=" %%a in ('%psc% "$explorerProc = Get-Process -Name explorer | Where-Object {$_.SessionId -eq (Get-Process -Id $pid).SessionId} | Select-Object -First 1; $sid = (gwmi -Query ('Select * From Win32_Process Where ProcessID=' + $explorerProc.Id)).GetOwnerSid().Sid; $sid" %nul6%') do (set _sidlist=%%a)
  3464. )
  3465. ​
  3466. ::==========================
  3467. ​
  3468. :: Load the unloaded useraccounts registry
  3469. ​
  3470. set loadedsids=
  3471. set alrloadedsids=
  3472. ​
  3473. for %%# in (%_sidlist%) do (
  3474. reg query HKU\%%#\Software %nul% && (
  3475. call set "alrloadedsids=%%alrloadedsids%% %%#"
  3476. ) || (
  3477. for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%%#" /v ProfileImagePath" %nul6%') do (
  3478. reg load HKU\%%# "%%b\NTUSER.DAT" %nul%
  3479. reg query HKU\%%#\Software %nul% && (
  3480. call set "loadedsids=%%loadedsids%% %%#"
  3481. ) || (
  3482. reg unload HKU\%%# %nul%
  3483. )
  3484. )
  3485. )
  3486. )
  3487. ​
  3488. ::==========================
  3489. ​
  3490. set "_sidlist=%loadedsids% %alrloadedsids%"
  3491. ​
  3492. set /a counter=0
  3493. for %%# in (%_sidlist%) do set /a counter+=1
  3494. ​
  3495. if %counter% EQU 0 (
  3496. set error=1
  3497. call :dk_color %Red% "Checking User Accounts SID [Not Found]"
  3498. exit /b
  3499. )
  3500. ​
  3501. if %counter% GTR 10 (
  3502. call :dk_color %Gray% "Checking Total User Accounts [%counter%]"
  3503. )
  3504. ​
  3505. ::==========================
  3506. ​
  3507. :: Clear the vNext/shared/device license blocks which may prevent ohook activation
  3508. ​
  3509. set vnextexist=
  3510. rmdir /s /q "%ProgramData%\Microsoft\Office\Licenses\" %nul%
  3511. ​
  3512. for %%x in (15 16) do (
  3513. for %%# in (%_sidlist%) do (
  3514. reg query HKU\%%#\Software\Microsoft\Office\%%x.0\Common\Licensing /s %nul2% | findstr /i "CIDToLicenseIdsMapping LicenseIdToEmailMapping @" %nul% && set vnextexist=1
  3515. reg delete HKU\%%#\Software\Microsoft\Office\%%x.0\Common\Licensing /f %nul%
  3516. ​
  3517. for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%%#" /v ProfileImagePath" %nul6%') do (
  3518. rmdir /s /q "%%b\AppData\Local\Microsoft\Office\Licenses\" %nul%
  3519. rmdir /s /q "%%b\AppData\Local\Microsoft\Office\%%x.0\Licensing\" %nul%
  3520. )
  3521. )
  3522. reg delete "HKLM\SOFTWARE\Microsoft\Office\%%x.0\Common\Licensing" /f %nul%
  3523. reg delete "HKLM\SOFTWARE\Microsoft\Office\%%x.0\Common\Licensing" /f /reg:32 %nul%
  3524. reg delete "HKLM\SOFTWARE\Policies\Microsoft\Office\%%x.0\Common\Licensing" /f %nul%
  3525. reg delete "HKLM\SOFTWARE\Policies\Microsoft\Office\%%x.0\Common\Licensing" /f /reg:32 %nul%
  3526. )
  3527. ​
  3528. :: Clear vNext in UWP Office
  3529. ​
  3530. if defined o16uwpapplist (
  3531. for %%# in (%_sidlist%) do (
  3532. for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\%%#" /v ProfileImagePath" %nul6%') do (
  3533. rmdir /s /q "%%b\AppData\Local\Packages\Microsoft.Office.Desktop_8wekyb3d8bbwe\LocalCache\Local\Microsoft\Office\Licenses\" %nul%
  3534. if exist "%%b\AppData\Local\Packages\Microsoft.Office.Desktop_8wekyb3d8bbwe\SystemAppData\Helium\User.dat" (
  3535. set defname=DEFTEMP-%%#
  3536. reg load HKU\!defname! "%%b\AppData\Local\Packages\Microsoft.Office.Desktop_8wekyb3d8bbwe\SystemAppData\Helium\User.dat" %nul%
  3537. reg query HKU\!defname!\Software\Microsoft\Office\16.0\Common\Licensing /s %nul2% | findstr /i "CIDToLicenseIdsMapping LicenseIdToEmailMapping @" %nul% && set vnextexist=1
  3538. reg delete HKU\!defname!\Software\Microsoft\Office\16.0\Common\Licensing /f %nul%
  3539. reg unload HKU\!defname! %nul%
  3540. )
  3541. )
  3542. )
  3543. )
  3544. ​
  3545. if defined vnextexist (
  3546. echo:
  3547. call :dk_color %Gray% "The logged-in Office account has a subscription license."
  3548. call :dk_color %Blue% "If the subscription is active, it overrides other activation methods."
  3549. call :dk_color %Blue% "If it is expiring soon, rerun the activation script after it expires."
  3550. call :dk_color2 %Blue% "If it has already expired and activation fails, get help here - " %_Yellow% " %mas%troubleshoot"
  3551. echo:
  3552. )
  3553. ​
  3554. :: Clear SharedComputerLicensing for office
  3555. :: https://learn.microsoft.com/en-us/deployoffice/overview-shared-computer-activation
  3556. ​
  3557. if not defined scaIsNeeded (
  3558. reg delete HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration /v SharedComputerLicensing /f %nul%
  3559. reg delete HKLM\SOFTWARE\Microsoft\Office\ClickToRun\Configuration /v SharedComputerLicensing /f /reg:32 %nul%
  3560. reg delete HKLM\SOFTWARE\Microsoft\Office\15.0\ClickToRun\Configuration /v SharedComputerLicensing /f %nul%
  3561. reg delete HKLM\SOFTWARE\Microsoft\Office\15.0\ClickToRun\Configuration /v SharedComputerLicensing /f /reg:32 %nul%
  3562. )
  3563. ​
  3564. :: Clear device-based-licensing
  3565. :: https://learn.microsoft.com/en-us/deployoffice/device-based-licensing
  3566. ​
  3567. for /f %%# in ('reg query "%o16c2r_reg%\Configuration" /f *.DeviceBasedLicensing %nul6% ^| findstr REG_') do reg delete "%o16c2r_reg%\Configuration" /v %%# /f %nul%
  3568. ​
  3569. :: Remove OEM registry key
  3570. :: https://support.microsoft.com/en-us/office/office-repeatedly-prompts-you-to-activate-on-a-new-pc-a9a6b05f-f6ce-4d1f-8d49-eb5007b64ba1
  3571. ​
  3572. for %%# in (15 16) do (
  3573. reg delete "HKLM\SOFTWARE\Microsoft\Office\%%#.0\Common\OEM" /f %nul%
  3574. reg delete "HKLM\SOFTWARE\Microsoft\Office\%%#.0\Common\OEM" /f /reg:32 %nul%
  3575. )
  3576. ​
  3577. reg delete "HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Policies\0ff1ce15-a989-479d-af46-f275c6370663" /f %nul%
  3578. reg delete "HKU\S-1-5-20\Software\Microsoft\OfficeSoftwareProtectionPlatform\Policies\0ff1ce15-a989-479d-af46-f275c6370663" /f %nul%
  3579. reg delete "HKU\S-1-5-20\Software\Microsoft\OfficeSoftwareProtectionPlatform\Policies\59a52881-a989-479d-af46-f275c6370663" /f %nul%
  3580. ​
  3581. echo Clearing Office License Blocks [Successfully cleared from all %counter% user accounts]
  3582. ​
  3583. ::==========================
  3584. ​
  3585. :: Some retail products attempt to validate the license and may show a banner "There was a problem checking this device's license status."
  3586. :: Resiliency registry entry can skip this check
  3587. ​
  3588. set defname=DEFTEMP-%random%
  3589. for /f "skip=2 tokens=2*" %%a in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList" /v Default" %nul6%') do call set "defdat=%%b"
  3590. ​
  3591. if defined o16c2r if defined ohookact (
  3592. if exist "%defdat%\NTUSER.DAT" (
  3593. reg load HKU\%defname% "%defdat%\NTUSER.DAT" %nul%
  3594. reg query HKU\%defname%\Software %nul% && (
  3595. reg add HKU\%defname%\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /v "TimeOfLastHeartbeatFailure" /t REG_SZ /d "2040-01-01T00:00:00Z" /f %nul%
  3596. )
  3597. reg unload HKU\%defname% %nul%
  3598. )
  3599. ​
  3600. for %%# in (%_sidlist%) do (
  3601. reg delete HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /f %nul%
  3602. reg add HKU\%%#\Software\Microsoft\Office\16.0\Common\Licensing\Resiliency /v "TimeOfLastHeartbeatFailure" /t REG_SZ /d "2040-01-01T00:00:00Z" /f %nul%
  3603. )
  3604. echo Adding Registry to Skip License Check [Successfully added to all %counter% ^& future new user accounts]
  3605. )
  3606. ​
  3607. ::==========================
  3608. ​
  3609. :: Unload the loaded useraccounts registry
  3610. ​
  3611. for %%# in (%loadedsids%) do (
  3612. reg unload HKU\%%# %nul%
  3613. )
  3614. ​
  3615. exit /b
  3616. ​
  3617. ::========================================================================================================================================
  3618. ​
  3619. :: Uninstall other / grace Keys
  3620. ​
  3621. :oh_uninstkey
  3622. ​
  3623. set upk_result=0
  3624. call :dk_actid 0ff1ce15-a989-479d-af46-f275c6370663
  3625. ​
  3626. if "%_actprojvis%"=="1" (
  3627. for /f "delims=" %%a in ('%psc% "Get-WmiObject -Query 'SELECT ID, Description, LicenseFamily FROM %spp% WHERE ApplicationID=''0ff1ce15-a989-479d-af46-f275c6370663'' AND PartialProductKey IS NOT NULL' | Where-Object { $_.LicenseFamily -notmatch 'Project' -and $_.LicenseFamily -notmatch 'Visio' } | Select-Object -ExpandProperty ID" %nul6%') do call set "_allactid=%%a !_allactid!"
  3628. for /f "delims=" %%a in ('%psc% "Get-WmiObject -Query 'SELECT ID, Description, LicenseFamily FROM %spp% WHERE ApplicationID=''0ff1ce15-a989-479d-af46-f275c6370663'' AND PartialProductKey IS NOT NULL' | Where-Object { '!_allactid!' -contains $_.ID -and ($_.LicenseFamily -match 'Project' -or $_.LicenseFamily -match 'Visio') } | Select-Object -ExpandProperty ID" %nul6%') do call set "_allactid=%%a !_allactid!"
  3629. )
  3630. ​
  3631. for %%# in (%apps%) do (
  3632. echo "%_allactid%" | find /i "%%#" %nul1% || (
  3633. ​
  3634. if %_wmic% EQU 1 wmic path %spp% where ID='%%#' call UninstallProductKey %nul%
  3635. if %_wmic% EQU 0 %psc% "$null=([WMI]'%spp%=''%%#''').UninstallProductKey()" %nul%
  3636. ​
  3637. if !errorlevel!==0 (
  3638. set upk_result=1
  3639. ) else (
  3640. set error=1
  3641. set upk_result=2
  3642. )
  3643. )
  3644. )
  3645. ​
  3646. if defined ohookact if not %upk_result%==0 echo:
  3647. if %upk_result%==1 echo Uninstalling Other/Grace Keys [Successful]
  3648. if %upk_result%==2 (
  3649. call :dk_color %Red% "Uninstalling Other/Grace Keys [Failed]"
  3650. if not defined showfix (
  3651. call :dk_color %Blue% "%_fixmsg%"
  3652. echo:
  3653. set showfix=1
  3654. )
  3655. )
  3656. exit /b
  3657. ​
  3658. ::========================================================================================================================================
  3659. ​
  3660. :: Refresh Windows Insider Preview Licenses
  3661. :: It required in Insider versions otherwise office may not activate
  3662. ​
  3663. :oh_licrefresh
  3664. ​
  3665. if exist "%SysPath%\spp\store_test\2.0\tokens.dat" (
  3666. %psc% "Stop-Service sppsvc -force; $sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses" %nul%
  3667. if !errorlevel! NEQ 0 %psc% "$sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses" %nul%
  3668. )
  3669. exit /b
  3670. ​
  3671. ::========================================================================================================================================
  3672. ​
  3673. :: Check running office apps and notify user
  3674. ​
  3675. :oh_checkapps
  3676. ​
  3677. set checkapps=
  3678. set checknames=
  3679. for /f "tokens=1" %%i in ('tasklist ^| findstr /I ".exe" %nul6%') do (set "checkapps=!checkapps! -%%i-")
  3680. ​
  3681. for %%# in (
  3682. Access_msaccess.exe
  3683. Excel_excel.exe
  3684. Groove_groove.exe
  3685. Lync_lync.exe
  3686. OneNote_onenote.exe
  3687. Outlook_outlook.exe
  3688. PowerPoint_powerpnt.exe
  3689. Project_winproj.exe
  3690. Publisher_mspub.exe
  3691. Visio_visio.exe
  3692. Word_winword.exe
  3693. Lime_lime.exe
  3694. ) do (
  3695. for /f "tokens=1-2 delims=_" %%A in ("%%#") do (
  3696. echo !checkapps! | find /i "-%%B-" %nul1% && (if defined checknames (set "checknames=!checknames! %%A") else (set "checknames=%%A"))
  3697. )
  3698. )
  3699. exit /b
  3700. ​
  3701. ::========================================================================================================================================
  3702. ​
  3703. :: 1st column = Office version number
  3704. :: 2nd column = Activation ID
  3705. :: 3rd column = For Office 2013 and later, the generated keys are listed. For Office 2010, the blocked keys sourced from the Internet are listed.
  3706. :: For Office 2013 and later, key preference is given in this order, Retail:TB:Sub > Retail > OEM:NONSLP > Volume:MAK > Volume:GVLK
  3707. :: For Office 2010, key preference is given in this order, Retail > Volume:MAK
  3708. :: 4th column = Last part of license description
  3709. :: 5th column = Edition
  3710. :: 6th column = Other Edition IDs if they are part of the same primary product (For reference only)
  3711. :: Separator = "_"
  3712. ​
  3713. ::===============
  3714. ​
  3715. :: We couldn't find any keys (blocked/generic doesn't matter) for these Office 2010 products. If you have them, please share with us.
  3716. ​
  3717. 14_4eaff0d0-c6cb-4187-94f3-c7656d49a0aa_Retail________ExcelR_[HSExcelR]
  3718. 14_7004b7f0-6407-4f45-8eac-966e5f868bde_Retail________GrooveR
  3719. 14_133c8359-4e93-4241-8118-30bb18737ea0_Retail________PowerPointR_[HSPowerPointR]
  3720. 14_db3bbc9c-ce52-41d1-a46f-1a1d68059119_Retail________WordR_[HSWordR]
  3721. 14_dbe3aee0-5183-4ff7-8142-66050173cb01_Retail________SmallBusBasicsR_[SmallBusBasicsMSDNR]
  3722. ​
  3723. :: These installers are not publicly available, so it doesn't matter if we don't have their keys.
  3724. ​
  3725. 14_19316117-30a8-4773-8fd9-7f7231f4e060_SubPrepid_____HomeBusinessSubR
  3726. 14_4d06f72e-fd50-4bc2-a24b-d448d7f17ef2_SubPrepid_____ProjectProSubR
  3727. 14_e98ef0c0-71c4-42ce-8305-287d8721e26c_SubPrepid_____ProPlusSubR
  3728. 14_14f5946a-debc-4716-babc-7e2c240fec08_Retail________MondoR
  3729. 14_533b656a-4425-480b-8e30-1a2358898350_MAK___________MondoVL
  3730. ​
  3731. :ohookdata
  3732. ​
  3733. set f=
  3734. for %%# in (
  3735. :: Office 2010
  3736. 14_4d463c2c-0505-4626-8cdb-a4da82e2d8ed_7KTYC-XR43P-C3MRW-BJKFD-XB%f%YPG_Retail________AccessR
  3737. 14_745fb377-0a59-4ca9-b9a9-c359557a2c4e_7XHPQ-BQMYG-YBP49-CY8B2-T8%f%CGQ_ByPass________AccessRuntimeR
  3738. 14_95ab3ec8-4106-4f9d-b632-03c019d1d23f_89RTQ-MT4GK-6CPTX-WWP7C-J9%f%KXR_MAK___________AccessVL
  3739. 14_71dc86ff-f056-40d0-8ffb-9592705c9b76_39TRR-C2F37-9WYJ2-MJQXH-B9%f%38K_MAK___________ExcelVL
  3740. 14_fdad0dfa-417d-4b4f-93e4-64ea8867b7fd_RCGT3-FPQDV-H49CD-PPDBF-TH%f%47G_MAK___________GrooveVL
  3741. 14_7b7d1f17-fdcb-4820-9789-9bec6e377821_3YR9B-D9W79-BY66R-R8XYP-QY%f%YYY_Retail________HomeBusinessR_[HomeBusinessDemoR]
  3742. 14_09e2d37e-474b-4121-8626-58ad9be5776f_3X43R-HHHXX-FRHRW-2M2WJ-8V%f%PHD_Retail________HomeStudentR_[HomeStudentDemoR]
  3743. 14_ef1da464-01c8-43a6-91af-e4e5713744f9_XDGJY-KFHW9-JWX9X-YM4GW-GC%f%8WR_Retail________InfoPathR
  3744. 14_85e22450-b741-430c-a172-a37962c938af_6GKT2-KMJPK-4RRBF-8VQKB-JB%f%6G6_MAK___________InfoPathVL
  3745. 14_3f7aa693-9a7e-44fc-9309-bb3d8e604925_2TG3P-9DB76-4YT99-8RXGD-CW%f%XBP_Retail________OneNoteR_[HSOneNoteR]
  3746. 14_6860b31f-6a67-48b8-84b9-e312b3485c4b_CV64P-F4VRH-BJ33D-PH6MR-X6%f%9RY_MAK___________OneNoteVL
  3747. 14_fbf4ac36-31c8-4340-8666-79873129cf40_9D8FR-7GYBW-4YG8M-V36JK-VD%f%7CM_Retail________OutlookR
  3748. 14_a9aeabd8-63b8-4079-a28e-f531807fd6b8_J8C9M-YXMH2-9CX44-2C3YG-V7%f%692_MAK___________OutlookVL
  3749. 14_acb51361-c0db-4895-9497-1831c41f31a6_GMBWM-WVX26-7WHV4-DB43D-WV%f%DY2_Retail________PersonalR_[PersonalDemoR,PersonalPrepaidR]
  3750. 14_38252940-718c-4aa6-81a4-135398e53851_HPBQP-RJHDR-Q3472-PT9Q6-PB%f%B72_MAK___________PowerPointVL
  3751. 14_8b559c37-0117-413e-921b-b853aeb6e210_367X9-9HP9R-TKHY6-DH4QH-K9%f%PY7_Retail________ProfessionalR_[ProfessionalAcadR,ProfessionalDemoR,OEM-SingleImage]
  3752. 14_725714d7-d58f-4d12-9fa8-35873c6f7215_6JD4G-KRW3J-48MGV-DM6FC-T9%f%WKR_Retail________ProjectProR_[ProjectProMSDNR]
  3753. 14_1cf57a59-c532-4e56-9a7d-ffa2fe94b474_3XDTH-MMGJ6-F9MKX-THP8D-G9%f%BP7_MAK___________ProjectProVL
  3754. 14_688f6589-2bd9-424e-a152-b13f36aa6de1_2W96V-RTQ9R-2BPVT-PT8H9-MV%f%68T_Retail________ProjectStdR
  3755. 14_11b39439-6b93-4642-9570-f2eb81be2238_4DTT4-D4MKX-23KFH-JKR6T-YK%f%G2J_MAK___________ProjectStdVL
  3756. 14_71af7e84-93e6-4363-9b69-699e04e74071_2J9H6-H4D3G-PCXD2-96XVM-TR%f%R73_Retail________ProPlusR_[ProPlusAcadR,ProPlusMSDNR,Sub4R]
  3757. 14_fdf3ecb9-b56f-43b2-a9b8-1b48b6bae1a7_6CD6C-9R8PB-T2D9Y-8RKKX-W7%f%DFK_MAK___________ProPlusVL_[ProPlusAcadVL]
  3758. 14_98677603-a668-4fa4-9980-3f1f05f78f69_CTRJP-P72VV-JBF8Y-4W6WW-HX%f%HVG_Retail________PublisherR
  3759. 14_3d014759-b128-4466-9018-e80f6320d9d0_32YG9-3VX77-YXJVV-PRVFW-TT%f%8BV_MAK___________PublisherVL
  3760. 14_8090771e-d41a-4482-929e-de87f1f47e46_7VKXH-9BWCG-RPTBB-JBRV3-GR%f%HYC_MAK___________SmallBusBasicsVL
  3761. 14_b78df69e-0966-40b1-ae85-30a5134dedd0_H48K6-FB4Y6-P83GH-9J7XG-HD%f%KKX_ByPass________SPDR
  3762. 14_b6d2565c-341d-4768-ad7d-addbe00bb5ce_W3BTX-H6BW7-Q6DFW-BXFFY-8R%f%VJP_Retail________StandardR_[StandardMSDNR][KeyisforMSDNR]
  3763. 14_1f76e346-e0be-49bc-9954-70ec53a4fcfe_2XTQP-GDR7C-GTXPC-6W6PV-4R%f%XGC_MAK___________StandardVL_[StandardAcadVL]
  3764. 14_2745e581-565a-4670-ae90-6bf7c57ffe43_VXHHB-W7HBD-7M342-RJ7P8-CH%f%BD6_ByPass________StarterR
  3765. 14_66cad568-c2dc-459d-93ec-2f3cb967ee34_2RDPT-WPYQM-C2WXF-BTPDW-2J%f%2HM_Retail________VisioSIR_Prem[Pro,Std]
  3766. 14_36756cb8-8e69-4d11-9522-68899507cd6a_7PKFT-X2MKQ-GT6X2-8CB2W-CH%f%C9K_MAK___________VisioSIVL_Prem[Pro,Std]
  3767. 14_98d4050e-9c98-49bf-9be1-85e12eb3ab13_6J3XK-DFKGK-X373V-QJHYM-V3%f%FC2_MAK___________WordVL
  3768. :: Office 2013
  3769. 15_ab4d047b-97cf-4126-a69f-34df08e2f254_B7RFY-7NXPK-Q4342-Y9X2H-3J%f%X4X_Retail________AccessRetail
  3770. 15_259de5be-492b-44b3-9d78-9645f848f7b0_X3XNB-HJB7K-66THH-8DWQ3-XH%f%GJP_Bypass________AccessRuntimeRetail
  3771. 15_4374022d-56b8-48c1-9bb7-d8f2fc726343_9MF9G-CN32B-HV7XT-9XJ8T-9K%f%VF4_MAK___________AccessVolume
  3772. 15_1b1d9bd5-12ea-4063-964c-16e7e87d6e08_NT889-MBH4X-8MD4H-X8R2D-WQ%f%HF8_Retail________ExcelRetail
  3773. 15_ac1ae7fd-b949-4e04-a330-849bc40638cf_Y3N36-YCHDK-XYWBG-KYQVV-BD%f%TJ2_MAK___________ExcelVolume
  3774. 15_cfaf5356-49e3-48a8-ab3c-e729ab791250_BMK4W-6N88B-BP9QR-PHFCK-MG%f%7GF_Retail________GrooveRetail
  3775. 15_4825ac28-ce41-45a7-9e6e-1fed74057601_RN84D-7HCWY-FTCBK-JMXWM-HT%f%7GJ_MAK___________GrooveVolume
  3776. 15_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_2WQNF-GBK4B-XVG6F-BBMX7-M4%f%F2Y_OEM-Perp______HomeBusinessPipcRetail
  3777. 15_a2b90e7a-a797-4713-af90-f0becf52a1dd_YWD4R-CNKVT-VG8VJ-9333B-RC%f%W9F_Subscription__HomeBusinessRetail
  3778. 15_1fdfb4e4-f9c9-41c4-b055-c80daf00697d_B92QY-NKYFQ-6KTKH-VWW2Q-3P%f%B3B_OEM-ARM_______HomeStudentARMRetail
  3779. 15_ebef9f05-5273-404a-9253-c5e252f50555_QPG96-CNT7M-KH36K-KY4HQ-M7%f%TBR_OEM-ARM_______HomeStudentPlusARMRetail
  3780. 15_f2de350d-3028-410a-bfae-283e00b44d0e_6WW3N-BDGM9-PCCHD-9QPP9-P3%f%4QG_Subscription__HomeStudentRetail
  3781. 15_44984381-406e-4a35-b1c3-e54f499556e2_RV7NQ-HY3WW-7CKWH-QTVMW-29%f%VHC_Retail________InfoPathRetail
  3782. 15_9e016989-4007-42a6-8051-64eb97110cf2_C4TGN-QQW6Y-FYKXC-6WJW7-X7%f%3VG_MAK___________InfoPathVolume
  3783. 15_9103f3ce-1084-447a-827e-d6097f68c895_6MDN4-WF3FV-4WH3Q-W699V-RG%f%CMY_PrepidBypass__LyncAcademicRetail
  3784. 15_ff693bf4-0276-4ddb-bb42-74ef1a0c9f4d_N42BF-CBY9F-W2C7R-X397X-DY%f%FQW_PrepidBypass__LyncEntryRetail
  3785. 15_fada6658-bfc6-4c4e-825a-59a89822cda8_89P23-2NK2R-JXM2M-3Q8R8-BW%f%M3Y_Retail________LyncRetail
  3786. 15_e1264e10-afaf-4439-a98b-256df8bb156f_3WKCD-RN489-4M7XJ-GJ2GQ-YB%f%FQ6_MAK___________LyncVolume
  3787. 15_69ec9152-153b-471a-bf35-77ec88683eae_VNWHF-FKFBW-Q2RGD-HYHWF-R3%f%HH2_Subscription__MondoRetail
  3788. 15_f33485a0-310b-4b72-9a0e-b1d605510dbd_2YNYQ-FQMVG-CB8KW-6XKYD-M7%f%RRJ_MAK___________MondoVolume
  3789. 15_3391e125-f6e4-4b1e-899c-a25e6092d40d_4TGWV-6N9P6-G2H8Y-2HWKB-B4%f%FF4_Bypass________OneNoteFreeRetail
  3790. 15_8b524bcc-67ea-4876-a509-45e46f6347e8_3KXXQ-PVN2C-8P7YY-HCV88-GV%f%GQ6_Retail________OneNoteRetail
  3791. 15_b067e965-7521-455b-b9f7-c740204578a2_JDMWF-NJC7B-HRCHY-WFT8G-BP%f%XD9_MAK___________OneNoteVolume
  3792. 15_12004b48-e6c8-4ffa-ad5a-ac8d4467765a_9N4RQ-CF8R2-HBVCB-J3C9V-94%f%P4D_Retail________OutlookRetail
  3793. 15_8d577c50-ae5e-47fd-a240-24986f73d503_HNG29-GGWRG-RFC8C-JTFP4-2J%f%9FH_MAK___________OutlookVolume
  3794. 15_5aab8561-1686-43f7-9ff5-2c861da58d17_9CYB3-NFMRW-YFDG6-XC7TF-BY%f%36J_OEM-Perp______PersonalPipcRetail
  3795. 15_17e9df2d-ed91-4382-904b-4fed6a12caf0_2NCQJ-MFRMH-TXV83-J7V4C-RV%f%RWC_Retail________PersonalRetail
  3796. 15_31743b82-bfbc-44b6-aa12-85d42e644d5b_HVMN2-KPHQH-DVQMK-7B3CM-FG%f%BFC_Retail________PowerPointRetail
  3797. 15_e40dcb44-1d5c-4085-8e8f-943f33c4f004_47DKN-HPJP7-RF9M3-VCYT2-TM%f%Q4G_MAK___________PowerPointVolume
  3798. 15_064383fa-1538-491c-859b-0ecab169a0ab_N3QMM-GKDT3-JQGX6-7X3MQ-4G%f%BG3_Retail________ProPlusRetail
  3799. 15_2b88c4f2-ea8f-43cd-805e-4d41346e18a7_QKHNX-M9GGH-T3QMW-YPK4Q-QR%f%P9V_MAK___________ProPlusVolume
  3800. 15_4e26cac1-e15a-4467-9069-cb47b67fe191_CF9DD-6CNW2-BJWJQ-CVCFX-Y7%f%TXD_OEM-Perp______ProfessionalPipcRetail
  3801. 15_44bc70e2-fb83-4b09-9082-e5557e0c2ede_MBQBN-CQPT6-PXRMC-TYJFR-3C%f%8MY_Retail________ProfessionalRetail
  3802. 15_2f72340c-b555-418d-8b46-355944fe66b8_WPY8N-PDPY4-FC7TF-KMP7P-KW%f%YFY_Subscription__ProjectProRetail
  3803. 15_ed34dc89-1c27-4ecd-8b2f-63d0f4cedc32_WFCT2-NBFQ7-JD7VV-MFJX6-6F%f%2CM_MAK___________ProjectProVolume
  3804. 15_58d95b09-6af6-453d-a976-8ef0ae0316b1_NTHQT-VKK6W-BRB87-HV346-Y9%f%6W8_Subscription__ProjectStdRetail
  3805. 15_2b9e4a37-6230-4b42-bee2-e25ce86c8c7a_3CNQX-T34TY-99RH4-C4YD2-KW%f%YGV_MAK___________ProjectStdVolume
  3806. 15_c3a0814a-70a4-471f-af37-2313a6331111_TWNCJ-YR84W-X7PPF-6DPRP-D6%f%7VC_Retail________PublisherRetail
  3807. 15_38ea49f6-ad1d-43f1-9888-99a35d7c9409_DJPHV-NCJV6-GWPT6-K26JX-C7%f%GX6_MAK___________PublisherVolume
  3808. 15_ba3e3833-6a7e-445a-89d0-7802a9a68588_3NY6J-WHT3F-47BDV-JHF36-23%f%43W_PrepidBypass__SPDRetail
  3809. 15_32255c0a-16b4-4ce2-b388-8a4267e219eb_V6VWN-KC2HR-YYDD6-9V7HQ-7T%f%7VP_Retail________StandardRetail
  3810. 15_a24cca51-3d54-4c41-8a76-4031f5338cb2_9TN6B-PCYH4-MCVDQ-KT83C-TM%f%Q7T_MAK___________StandardVolume
  3811. 15_a56a3b37-3a35-4bbb-a036-eee5f1898eee_NVK2G-2MY4G-7JX2P-7D6F2-VF%f%QBR_Subscription__VisioProRetail
  3812. 15_3e4294dd-a765-49bc-8dbd-cf8b62a4bd3d_YN7CF-XRH6R-CGKRY-GKPV3-BG%f%7WF_MAK___________VisioProVolume
  3813. 15_980f9e3e-f5a8-41c8-8596-61404addf677_NCRB7-VP48F-43FYY-62P3R-36%f%7WK_Subscription__VisioStdRetail
  3814. 15_44a1f6ff-0876-4edb-9169-dbb43101ee89_RX63Y-4NFK2-XTYC8-C6B3W-YP%f%XPJ_MAK___________VisioStdVolume
  3815. 15_191509f2-6977-456f-ab30-cf0492b1e93a_NB77V-RPFQ6-PMMKQ-T87DV-M4%f%D84_Retail________WordRetail
  3816. 15_9cedef15-be37-4ff0-a08a-13a045540641_RPHPB-Y7NC4-3VYFM-DW7VD-G8%f%YJ8_MAK___________WordVolume
  3817. :: Office 365 - 15.0 version
  3818. 15_742178ed-6b28-42dd-b3d7-b7c0ea78741b_Y9NF9-M2QWD-FF6RJ-QJW36-RR%f%F2T_SubTest_______O365BusinessRetail
  3819. 15_a96f8dae-da54-4fad-bdc6-108da592707a_3NMDC-G7C3W-68RGP-CB4MH-4C%f%XCH_SubTest1______O365HomePremRetail
  3820. 15_e3dacc06-3bc2-4e13-8e59-8e05f3232325_H8DN8-Y2YP3-CR9JT-DHDR9-C7%f%GP3_Subscription2_O365ProPlusRetail
  3821. 15_0bc1dae4-6158-4a1c-a893-807665b934b2_2QCNB-RMDKJ-GC8PB-7QGQV-7Q%f%TQJ_Subscription2_O365SmallBusPremRetail
  3822. :: Office 365 - 16.0 version
  3823. 16_dabaa1f2-109b-496d-bf49-1536cc862900_3HYJN-9KG99-F8VG9-V3DT8-JF%f%MHV_Subscription__O365AppsBasicRetail
  3824. 16_742178ed-6b28-42dd-b3d7-b7c0ea78741b_Y9NF9-M2QWD-FF6RJ-QJW36-RR%f%F2T_SubTest_______O365BusinessRetail
  3825. 16_2f5c71b4-5b7a-4005-bb68-f9fac26f2ea3_W62NQ-267QR-RTF74-PF2MH-JQ%f%MTH_Subscription__O365EduCloudRetail
  3826. 16_a96f8dae-da54-4fad-bdc6-108da592707a_3NMDC-G7C3W-68RGP-CB4MH-4C%f%XCH_SubTest1______O365HomePremRetail
  3827. 16_e3dacc06-3bc2-4e13-8e59-8e05f3232325_H8DN8-Y2YP3-CR9JT-DHDR9-C7%f%GP3_Subscription2_O365ProPlusRetail
  3828. 16_0bc1dae4-6158-4a1c-a893-807665b934b2_2QCNB-RMDKJ-GC8PB-7QGQV-7Q%f%TQJ_Subscription2_O365SmallBusPremRetail
  3829. :: Office 2016
  3830. 16_bfa358b0-98f1-4125-842e-585fa13032e6_WHK4N-YQGHB-XWXCC-G3HYC-6J%f%F94_Retail________AccessRetail
  3831. 16_9d9faf9e-d345-4b49-afce-68cb0a539c7c_RNB7V-P48F4-3FYY6-2P3R3-63%f%BQV_PrepidBypass__AccessRuntimeRetail
  3832. 16_3b2fa33f-cd5a-43a5-bd95-f49f3f546b0b_JJ2Y4-N8KM3-Y8KY3-Y22FR-R3%f%KVK_MAK___________AccessVolume
  3833. 16_424d52ff-7ad2-4bc7-8ac6-748d767b455d_RKJBN-VWTM2-BDKXX-RKQFD-JT%f%YQ2_Retail________ExcelRetail
  3834. 16_685062a7-6024-42e7-8c5f-6bb9e63e697f_FVGNR-X82B2-6PRJM-YT4W7-8H%f%V36_MAK___________ExcelVolume
  3835. 16_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_2WQNF-GBK4B-XVG6F-BBMX7-M4%f%F2Y_OEM-Perp______HomeBusinessPipcRetail
  3836. 16_86834d00-7896-4a38-8fae-32f20b86fa2b_HM6FM-NVF78-KV9PM-F36B8-D9%f%MXD_Retail________HomeBusinessRetail
  3837. 16_090896a0-ea98-48ac-b545-ba5da0eb0c9c_PBQPJ-NC22K-69MXD-KWMRF-WF%f%G77_OEM-ARM_______HomeStudentARMRetail
  3838. 16_6bbe2077-01a4-4269-bf15-5bf4d8efc0b2_6F2NY-7RTX4-MD9KM-TJ43H-94%f%TBT_OEM-ARM_______HomeStudentPlusARMRetail
  3839. 16_c28acdb8-d8b3-4199-baa4-024d09e97c99_PNPRV-F2627-Q8JVC-3DGR9-WT%f%YRK_Retail________HomeStudentRetail
  3840. 16_e2127526-b60c-43e0-bed1-3c9dc3d5a468_YWD4R-CNKVT-VG8VJ-9333B-RC%f%3B8_Retail________HomeStudentVNextRetail
  3841. 16_69ec9152-153b-471a-bf35-77ec88683eae_VNWHF-FKFBW-Q2RGD-HYHWF-R3%f%HH2_Subscription__MondoRetail
  3842. 16_2cd0ea7e-749f-4288-a05e-567c573b2a6c_FMTQQ-84NR8-2744R-MXF4P-PG%f%YR3_MAK___________MondoVolume
  3843. 16_436366de-5579-4f24-96db-3893e4400030_XYNTG-R96FY-369HX-YFPHY-F9%f%CPM_Bypass________OneNoteFreeRetail
  3844. 16_83ac4dd9-1b93-40ed-aa55-ede25bb6af38_FXF6F-CNC26-W643C-K6KB7-6X%f%XW3_Retail________OneNoteRetail
  3845. 16_23b672da-a456-4860-a8f3-e062a501d7e8_9TYVN-D76HK-BVMWT-Y7G88-9T%f%PPV_MAK___________OneNoteVolume
  3846. 16_5a670809-0983-4c2d-8aad-d3c2c5b7d5d1_7N4KG-P2QDH-86V9C-DJFVF-36%f%9W9_Retail________OutlookRetail
  3847. 16_50059979-ac6f-4458-9e79-710bcb41721a_7QPNR-3HFDG-YP6T9-JQCKQ-KK%f%XXC_MAK___________OutlookVolume
  3848. 16_5aab8561-1686-43f7-9ff5-2c861da58d17_9CYB3-NFMRW-YFDG6-XC7TF-BY%f%36J_OEM-Perp______PersonalPipcRetail
  3849. 16_a9f645a1-0d6a-4978-926a-abcb363b72a6_FT7VF-XBN92-HPDJV-RHMBY-6V%f%KBF_Retail________PersonalRetail
  3850. 16_f32d1284-0792-49da-9ac6-deb2bc9c80b6_N7GCB-WQT7K-QRHWG-TTPYD-7T%f%9XF_Retail________PowerPointRetail
  3851. 16_9b4060c9-a7f5-4a66-b732-faf248b7240f_X3RT9-NDG64-VMK2M-KQ6XY-DP%f%FGV_MAK___________PowerPointVolume
  3852. 16_de52bd50-9564-4adc-8fcb-a345c17f84f9_GM43N-F742Q-6JDDK-M622J-J8%f%GDV_Retail________ProPlusRetail
  3853. 16_c47456e3-265d-47b6-8ca0-c30abbd0ca36_FNVK8-8DVCJ-F7X3J-KGVQB-RC%f%2QY_MAK___________ProPlusVolume
  3854. 16_4e26cac1-e15a-4467-9069-cb47b67fe191_CF9DD-6CNW2-BJWJQ-CVCFX-Y7%f%TXD_OEM-Perp______ProfessionalPipcRetail
  3855. 16_d64edc00-7453-4301-8428-197343fafb16_NXFTK-YD9Y7-X9MMJ-9BWM6-J2%f%QVH_Retail________ProfessionalRetail
  3856. 16_2f72340c-b555-418d-8b46-355944fe66b8_WPY8N-PDPY4-FC7TF-KMP7P-KW%f%YFY_Subscription__ProjectProRetail
  3857. 16_82f502b5-b0b0-4349-bd2c-c560df85b248_PKC3N-8F99H-28MVY-J4RYY-CW%f%GDH_MAK___________ProjectProVolume
  3858. 16_16728639-a9ab-4994-b6d8-f81051e69833_JBNPH-YF2F7-Q9Y29-86CTG-C9%f%YGV_MAKC2R________ProjectProXVolume
  3859. 16_58d95b09-6af6-453d-a976-8ef0ae0316b1_NTHQT-VKK6W-BRB87-HV346-Y9%f%6W8_Subscription__ProjectStdRetail
  3860. 16_82e6b314-2a62-4e51-9220-61358dd230e6_4TGWV-6N9P6-G2H8Y-2HWKB-B4%f%G93_MAK___________ProjectStdVolume
  3861. 16_431058f0-c059-44c5-b9e7-ed2dd46b6789_N3W2Q-69MBT-27RD9-BH8V3-JT%f%2C8_MAKC2R________ProjectStdXVolume
  3862. 16_6e0c1d99-c72e-4968-bcb7-ab79e03e201e_WKWND-X6G9G-CDMTV-CPGYJ-6M%f%VBF_Retail________PublisherRetail
  3863. 16_fcc1757b-5d5f-486a-87cf-c4d6dedb6032_9QVN2-PXXRX-8V4W8-Q7926-TJ%f%GD8_MAK___________PublisherVolume
  3864. 16_9103f3ce-1084-447a-827e-d6097f68c895_6MDN4-WF3FV-4WH3Q-W699V-RG%f%CMY_PrepidBypass__SkypeServiceBypassRetail
  3865. 16_971cd368-f2e1-49c1-aedd-330909ce18b6_4N4D8-3J7Y3-YYW7C-73HD2-V8%f%RHY_PrepidBypass__SkypeforBusinessEntryRetail
  3866. 16_418d2b9f-b491-4d7f-84f1-49e27cc66597_PBJ79-77NY4-VRGFG-Y8WYC-CK%f%CRC_Retail________SkypeforBusinessRetail
  3867. 16_03ca3b9a-0869-4749-8988-3cbc9d9f51bb_DMTCJ-KNRKR-JV8TQ-V2CR2-VF%f%TFH_MAK___________SkypeforBusinessVolume
  3868. 16_4a31c291-3a12-4c64-b8ab-cd79212be45e_2FPWN-4H6CM-KD8QQ-8HCHC-P9%f%XYW_Retail________StandardRetail
  3869. 16_0ed94aac-2234-4309-ba29-74bdbb887083_WHGMQ-JNMGT-MDQVF-WDR69-KQ%f%BWC_MAK___________StandardVolume
  3870. 16_a56a3b37-3a35-4bbb-a036-eee5f1898eee_NVK2G-2MY4G-7JX2P-7D6F2-VF%f%QBR_Subscription__VisioProRetail
  3871. 16_295b2c03-4b1c-4221-b292-1411f468bd02_NRKT9-C8GP2-XDYXQ-YW72K-MG%f%92B_MAK___________VisioProVolume
  3872. 16_0594dc12-8444-4912-936a-747ca742dbdb_G98Q2-B6N77-CFH9J-K824G-XQ%f%CC4_MAKC2R________VisioProXVolume
  3873. 16_980f9e3e-f5a8-41c8-8596-61404addf677_NCRB7-VP48F-43FYY-62P3R-36%f%7WK_Subscription__VisioStdRetail
  3874. 16_44151c2d-c398-471f-946f-7660542e3369_XNCJB-YY883-JRW64-DPXMX-JX%f%CR6_MAK___________VisioStdVolume
  3875. 16_1d1c6879-39a3-47a5-9a6d-aceefa6a289d_B2HTN-JPH8C-J6Y6V-HCHKB-43%f%MGT_MAKC2R________VisioStdXVolume
  3876. 16_cacaa1bf-da53-4c3b-9700-11738ef1c2a5_P8K82-NQ7GG-JKY8T-6VHVY-88%f%GGD_Retail________WordRetail
  3877. 16_c3000759-551f-4f4a-bcac-a4b42cbf1de2_YHMWC-YN6V9-WJPXD-3WQKP-TM%f%VCV_MAK___________WordVolume
  3878. :: Office 2019
  3879. 16_518687bd-dc55-45b9-8fa6-f918e1082e83_WRYJ6-G3NP7-7VH94-8X7KP-JB%f%7HC_Retail________Access2019Retail
  3880. 16_385b91d6-9c2c-4a2e-86b5-f44d44a48c5f_6FWHX-NKYXK-BW34Q-7XC9F-Q9%f%PX7_MAK-AE________Access2019Volume
  3881. 16_22e6b96c-1011-4cd5-8b35-3c8fb6366b86_FGQNJ-JWJCG-7Q8MG-RMRGJ-9T%f%QVF_PrepidBypass__AccessRuntime2019Retail
  3882. 16_c201c2b7-02a1-41a8-b496-37c72910cd4a_KBPNW-64CMM-8KWCB-23F44-8B%f%7HM_Retail________Excel2019Retail
  3883. 16_05cb4e1d-cc81-45d5-a769-f34b09b9b391_8NT4X-GQMCK-62X4P-TW6QP-YK%f%PYF_MAK-AE________Excel2019Volume
  3884. 16_7fe09eef-5eed-4733-9a60-d7019df11cac_QBN2Y-9B284-9KW78-K48PB-R6%f%2YT_Retail________HomeBusiness2019Retail
  3885. 16_6303d14a-afad-431f-8434-81052a65f575_DJTNY-4HDWM-TDWB2-8PWC2-W2%f%RRT_OEM-ARM_______HomeStudentARM2019Retail
  3886. 16_215c841d-ffc1-4f03-bd11-5b27b6ab64cc_NM8WT-CFHB2-QBGXK-J8W6J-GV%f%K8F_OEM-ARM_______HomeStudentPlusARM2019Retail
  3887. 16_4539aa2c-5c31-4d47-9139-543a868e5741_XNWPM-32XQC-Y7QJC-QGGBV-YY%f%7JK_Retail________HomeStudent2019Retail
  3888. 16_20e359d5-927f-47c0-8a27-38adbdd27124_WR43D-NMWQQ-HCQR2-VKXDR-37%f%B7H_Retail________Outlook2019Retail
  3889. 16_92a99ed8-2923-4cb7-a4c5-31da6b0b8cf3_RN3QB-GT6D7-YB3VH-F3RPB-3G%f%QYB_MAK-AE________Outlook2019Volume
  3890. 16_2747b731-0f1f-413e-a92d-386ec1277dd8_NMBY8-V3CV7-BX6K6-2922Y-43%f%M7T_Retail________Personal2019Retail
  3891. 16_7e63cc20-ba37-42a1-822d-d5f29f33a108_HN27K-JHJ8R-7T7KK-WJYC3-FM%f%7MM_Retail________PowerPoint2019Retail
  3892. 16_13c2d7bf-f10d-42eb-9e93-abf846785434_29GNM-VM33V-WR23K-HG2DT-KT%f%QYR_MAK-AE________PowerPoint2019Volume
  3893. 16_a3072b8f-adcc-4e75-8d62-fdeb9bdfae57_BN4XJ-R9DYY-96W48-YK8DM-MY%f%7PY_Retail________ProPlus2019Retail
  3894. 16_6755c7a7-4dfe-46f5-bce8-427be8e9dc62_T8YBN-4YV3X-KK24Q-QXBD7-T3%f%C63_MAK-AE________ProPlus2019Volume
  3895. 16_1717c1e0-47d3-4899-a6d3-1022db7415e0_9NXDK-MRY98-2VJV8-GF73J-TQ%f%9FK_Retail________Professional2019Retail
  3896. 16_0d270ef7-5aaf-4370-a372-bc806b96adb7_JDTNC-PP77T-T9H2W-G4J2J-VH%f%8JK_Retail________ProjectPro2019Retail
  3897. 16_d4ebadd6-401b-40d5-adf4-a5d4accd72d1_TBXBD-FNWKJ-WRHBD-KBPHH-XD%f%9F2_MAK-AE________ProjectPro2019Volume
  3898. 16_bb7ffe5f-daf9-4b79-b107-453e1c8427b5_R3JNT-8PBDP-MTWCK-VD2V8-HM%f%KF9_Retail________ProjectStd2019Retail
  3899. 16_fdaa3c03-dc27-4a8d-8cbf-c3d843a28ddc_RBRFX-MQNDJ-4XFHF-7QVDR-JH%f%XGC_MAK-AE________ProjectStd2019Volume
  3900. 16_f053a7c7-f342-4ab8-9526-a1d6e5105823_4QC36-NW3YH-D2Y9D-RJPC7-VV%f%B9D_Retail________Publisher2019Retail
  3901. 16_40055495-be00-444e-99cc-07446729b53e_K8F2D-NBM32-BF26V-YCKFJ-29%f%Y9W_MAK-AE________Publisher2019Volume
  3902. 16_b639e55c-8f3e-47fe-9761-26c6a786ad6b_JBDKF-6NCD6-49K3G-2TV79-BK%f%P73_Retail________SkypeforBusiness2019Retail
  3903. 16_15a430d4-5e3f-4e6d-8a0a-14bf3caee4c7_9MNQ7-YPQ3B-6WJXM-G83T3-CB%f%BDK_MAK-AE________SkypeforBusiness2019Volume
  3904. 16_f88cfdec-94ce-4463-a969-037be92bc0e7_N9722-BV9H6-WTJTT-FPB93-97%f%8MK_PrepidBypass__SkypeforBusinessEntry2019Retail
  3905. 16_fdfa34dd-a472-4b85-bee6-cf07bf0aaa1c_NDGVM-MD27H-2XHVC-KDDX2-YK%f%P74_Retail________Standard2019Retail
  3906. 16_beb5065c-1872-409e-94e2-403bcfb6a878_NT3V6-XMBK7-Q66MF-VMKR4-FC%f%33M_MAK-AE________Standard2019Volume
  3907. 16_a6f69d68-5590-4e02-80b9-e7233dff204e_2NWVW-QGF4T-9CPMB-WYDQ9-7X%f%P79_Retail________VisioPro2019Retail
  3908. 16_f41abf81-f409-4b0d-889d-92b3e3d7d005_33YF4-GNCQ3-J6GDM-J67P3-FM%f%7QP_MAK-AE________VisioPro2019Volume
  3909. 16_4a582021-18c2-489f-9b3d-5186de48f1cd_263WK-3N797-7R437-28BKG-3V%f%8M8_Retail________VisioStd2019Retail
  3910. 16_933ed0e3-747d-48b0-9c2c-7ceb4c7e473d_BGNHX-QTPRJ-F9C9G-R8QQG-8T%f%27F_MAK-AE________VisioStd2019Volume
  3911. 16_72cee1c2-3376-4377-9f25-4024b6baadf8_JXR8H-NJ3MK-X66W8-78CWD-QR%f%VR2_Retail________Word2019Retail
  3912. 16_fe5fe9d5-3b06-4015-aa35-b146f85c4709_9F36R-PNVHH-3DXGQ-7CD2H-R9%f%D3V_MAK-AE________Word2019Volume
  3913. :: Office 2021
  3914. 16_f634398e-af69-48c9-b256-477bea3078b5_P286B-N3XYP-36QRQ-29CMP-RV%f%X9M_Retail________Access2021Retail
  3915. 16_ae17db74-16b0-430b-912f-4fe456e271db_JBH3N-P97FP-FRTJD-MGK2C-VF%f%WG6_MAK-AE________Access2021Volume
  3916. 16_844c36cb-851c-49e7-9079-12e62a049e2a_MNX9D-PB834-VCGY2-K2RW2-2D%f%P3D_Bypass________AccessRuntime2021Retail
  3917. 16_fb099c19-d48b-4a2f-a160-4383011060aa_V6QFB-7N7G9-PF7W9-M8FQM-MY%f%8G9_Retail________Excel2021Retail
  3918. 16_9da1ecdb-3a62-4273-a234-bf6d43dc0778_WNYR4-KMR9H-KVC8W-7HJ8B-K7%f%9DQ_MAK-AE________Excel2021Volume
  3919. 16_38b92b63-1dff-4be7-8483-2a839441a2bc_JM99N-4MMD8-DQCGJ-VMYFY-R6%f%3YK_Subscription__HomeBusiness2021Retail
  3920. 16_2f258377-738f-48dd-9397-287e43079958_N3CWD-38XVH-KRX2Y-YRP74-6R%f%BB2_Subscription__HomeStudent2021Retail
  3921. 16_279706f4-3a4b-4877-949b-f8c299cf0cc5_NB2TQ-3Y79C-77C6M-QMY7H-7Q%f%Y8P_Retail________OneNote2021Retail
  3922. 16_0c7af60d-0664-49fc-9b01-41b2dea81380_THNKC-KFR6C-Y86Q9-W8CB3-GF%f%7PD_MAK-AE________OneNote2021Volume
  3923. 16_778ccb9a-2f6a-44e5-853c-eb22b7609643_CNM3W-V94GB-QJQHH-BDQ3J-33%f%Y8H_Bypass________OneNoteFree2021Retail
  3924. 16_ecea2cfa-d406-4a7f-be0d-c6163250d126_4NCWR-9V92Y-34VB2-RPTHR-YT%f%GR7_Retail________Outlook2021Retail
  3925. 16_45bf67f9-0fc8-4335-8b09-9226cef8a576_JQ9MJ-QYN6B-67PX9-GYFVY-QJ%f%6TB_MAK-AE________Outlook2021Volume
  3926. 16_8f89391e-eedb-429d-af90-9d36fbf94de6_RRRYB-DN749-GCPW4-9H6VK-HC%f%HPT_Retail________Personal2021Retail
  3927. 16_c9bf5e86-f5e3-4ac6-8d52-e114a604d7bf_3KXXQ-PVN2C-8P7YY-HCV88-GV%f%M96_Retail1_______PowerPoint2021Retail
  3928. 16_716f2434-41b6-4969-ab73-e61e593a3875_39G2N-3BD9C-C4XCM-BD4QG-FV%f%YDY_MAK-AE________PowerPoint2021Volume
  3929. 16_c2f04adf-a5de-45c5-99a5-f5fddbda74a8_8WXTP-MN628-KY44G-VJWCK-C7%f%PCF_Retail________ProPlus2021Retail
  3930. 16_3f180b30-9b05-4fe2-aa8d-0c1c4790f811_RNHJY-DTFXW-HW9F8-4982D-MD%f%2CW_MAK-AE1_______ProPlus2021Volume
  3931. 16_96097a68-b5c5-4b19-8600-2e8d6841a0db_JRJNJ-33M7C-R73X3-P9XF7-R9%f%F6M_MAK-AE________ProPlusSPLA2021Volume
  3932. 16_711e48a6-1a79-4b00-af10-73f4ca3aaac4_DJPHV-NCJV6-GWPT6-K26JX-C7%f%PBG_Retail________Professional2021Retail
  3933. 16_3747d1d5-55a8-4bc3-b53d-19fff1913195_QKHNX-M9GGH-T3QMW-YPK4Q-QR%f%WMV_Retail________ProjectPro2021Retail
  3934. 16_17739068-86c4-4924-8633-1e529abc7efc_HVC34-CVNPG-RVCMT-X2JRF-CR%f%7RK_MAK-AE1_______ProjectPro2021Volume
  3935. 16_4ea64dca-227c-436b-813f-b6624be2d54c_2B96V-X9NJY-WFBRC-Q8MP2-7C%f%HRR_Retail________ProjectStd2021Retail
  3936. 16_84313d1e-47c8-4e27-8ced-0476b7ee46c4_3CNQX-T34TY-99RH4-C4YD2-KW%f%6WH_MAK-AE________ProjectStd2021Volume
  3937. 16_b769b746-53b1-4d89-8a68-41944dafe797_CDNFG-77T8D-VKQJX-B7KT3-KK%f%28V_Retail1_______Publisher2021Retail
  3938. 16_a0234cfe-99bd-4586-a812-4f296323c760_2KXJH-3NHTW-RDBPX-QFRXJ-MT%f%GXF_MAK-AE________Publisher2021Volume
  3939. 16_c3fb48b2-1fd4-4dc8-af39-819edf194288_DVBXN-HFT43-CVPRQ-J89TF-VM%f%MHG_Retail________SkypeforBusiness2021Retail
  3940. 16_6029109c-ceb8-4ee5-b324-f8eb2981e99a_R3FCY-NHGC7-CBPVP-8Q934-YT%f%GXG_MAK-AE________SkypeforBusiness2021Volume
  3941. 16_9e7e7b8e-a0e7-467b-9749-d0de82fb7297_HXNXB-J4JGM-TCF44-2X2CV-FJ%f%VVH_Retail________Standard2021Retail
  3942. 16_223a60d8-9002-4a55-abac-593f5b66ca45_2CJN4-C9XK2-HFPQ6-YH498-82%f%TXH_MAK-AE________Standard2021Volume
  3943. 16_b99ba8c4-e257-4b70-a31a-8bd308ce7073_BQWDW-NJ9YF-P7Y79-H6DCT-MK%f%Q9C_MAK-AE________StandardSPLA2021Volume
  3944. 16_814014d3-c30b-4f63-a493-3708e0dc0ba8_T6P26-NJVBR-76BK8-WBCDY-TX%f%3BC_Retail________VisioPro2021Retail
  3945. 16_c590605a-a08a-4cc7-8dc2-f1ffb3d06949_JNKBX-MH9P4-K8YYV-8CG2Y-VQ%f%2C8_MAK-AE________VisioPro2021Volume
  3946. 16_16d43989-a5ef-47e2-9ff1-272784caee24_89NYY-KB93R-7X22F-93QDF-DJ%f%6YM_Retail________VisioStd2021Retail
  3947. 16_d55f90ee-4ba2-4d02-b216-1300ee50e2af_BW43B-4PNFP-V637F-23TR2-J4%f%7TX_MAK-AE________VisioStd2021Volume
  3948. 16_fb33d997-4aa3-494e-8b58-03e9ab0f181d_VNCC4-CJQVK-BKX34-77Y8H-CY%f%XMR_Retail________Word2021Retail
  3949. 16_0c728382-95fb-4a55-8f12-62e605f91727_BJG97-NW3GM-8QQQ7-FH76G-68%f%6XM_MAK-AE________Word2021Volume
  3950. :: Office 2024
  3951. 16_8fdb1f1e-663f-4f2e-8fdb-7c35aee7d5ea_GNXWX-DF797-B2JT3-82W27-KH%f%PXT_MAK-AE________ProPlus2024Volume-Preview
  3952. 16_33b11b14-91fd-4f7b-b704-e64a055cf601_X86XX-N3QMW-B4WGQ-QCB69-V2%f%6KW_MAK-AE________ProjectPro2024Volume-Preview
  3953. 16_eb074198-7384-4bdd-8e6c-c3342dac8435_DW99Y-H7NT6-6B29D-8JQ8F-R3%f%QT7_MAK-AE________VisioPro2024Volume-Preview
  3954. 16_e563d108-7b0e-418a-8390-20e1d133d6bb_P6NMW-JMTRC-R6MQ6-HH3F2-BT%f%HKB_Retail________Access2024Retail
  3955. 16_f748e2f7-5951-4bc2-8a06-5a1fbe42f5f4_CXNJT-98HPP-92HX7-MX6GY-2P%f%VFR_MAK-AE________Access2024Volume
  3956. 16_f3a5e86a-e4f8-4d88-8220-1440c3bbcefa_82CNJ-W82TW-BY23W-BVJ6W-W4%f%8GP_Retail________Excel2024Retail
  3957. 16_523fbbab-c290-460d-a6c9-48e49709cb8e_7Y287-9N2KC-8MRR3-BKY82-2D%f%QRV_MAK-AE________Excel2024Volume
  3958. 16_885f83e0-5e18-4199-b8be-56697d0debfb_N69X7-73KPT-899FD-P8HQ4-QG%f%TP4_Retail________Home2024Retail
  3959. 16_acd4eccb-ff89-4e6a-9350-d2d56276ec69_PRKQM-YNPQR-77QT6-328D7-BD%f%223_Retail________HomeBusiness2024Retail
  3960. 16_6f5fd645-7119-44a4-91b4-eccfeeb738bf_2CFK4-N44KG-7XG89-CWDG6-P7%f%P27_Retail________Outlook2024Retail
  3961. 16_9a1e1bac-2d8b-4890-832f-0a68b27c16e0_NQPXP-WVB87-H3MMB-FYBW2-9Q%f%FPB_MAK-AE________Outlook2024Volume
  3962. 16_da9a57ae-81a8-4cb3-b764-5840e6b5d0bf_CT2KT-GTNWH-9HFGW-J2PWJ-XW%f%7KJ_Retail________PowerPoint2024Retail
  3963. 16_eca0d8a6-e21b-4622-9a87-a7103ff14012_RRXFN-JJ26R-RVWD2-V7WMP-27%f%PWQ_MAK-AE________PowerPoint2024Volume
  3964. 16_295dcc21-151a-4b4d-8f50-2b627ea197f6_GNJ6P-Y4RBM-C32WW-2VJKJ-MT%f%HKK_Retail________ProjectPro2024Retail
  3965. 16_2141d341-41aa-4e45-9ca1-201e117d6495_WNFMR-HK4R7-7FJVM-VQ3JC-76%f%HF6_MAK-AE1_______ProjectPro2024Volume
  3966. 16_ead42f74-817d-45b4-af6b-3beeb36ba650_C2PNM-2GQFC-CY3XR-WXCP4-GX%f%3XM_Retail________ProjectStd2024Retail
  3967. 16_4b6d9b9b-c16e-429d-babe-8bb84c3c27d6_F2VNW-MW8TT-K622Q-4D96H-PW%f%J8X_MAK-AE________ProjectStd2024Volume
  3968. 16_db249714-bb54-4422-8c78-2cc8d4c4a19f_VWCNX-7FKBD-FHJYG-XBR4B-88%f%KC6_Retail________ProPlus2024Retail
  3969. 16_d77244dc-2b82-4f0a-b8ae-1fca00b7f3e2_4YV2J-VNG7W-YGTP3-443TK-TF%f%8CP_MAK-AE1_______ProPlus2024Volume
  3970. 16_3046a03e-2277-4a51-8ccd-a6609eae8c19_XKRBW-KN2FF-G8CKY-HXVG6-FV%f%Y2V_MAK-AE________SkypeforBusiness2024Volume
  3971. 16_44a07f51-8263-4b2f-b2a5-70340055c646_GVG6N-6WCHH-K2MVP-RQ78V-3J%f%7GJ_MAK-AE1_______Standard2024Volume
  3972. 16_282d8f34-1111-4a6f-80fe-c17f70dec567_HGRBX-N68QF-6DY8J-CGX4W-XW%f%7KP_Retail________VisioPro2024Retail
  3973. 16_4c2f32bf-9d0b-4d8c-8ab1-b4c6a0b9992d_GBNHB-B2G3Q-G42YB-3MFC2-7C%f%JCX_MAK-AE________VisioPro2024Volume
  3974. 16_8504167d-887a-41ae-bd1d-f849d834352d_VBXPJ-38NR3-C4DKF-C8RT7-RG%f%HKQ_Retail________VisioStd2024Retail
  3975. 16_0978336b-5611-497c-9414-96effaff4938_YNFTY-63K7P-FKHXK-28YYT-D3%f%2XB_MAK-AE________VisioStd2024Volume
  3976. 16_f6b24e61-6aa7-4fd2-ab9b-4046cee4230a_XN33R-RP676-GMY2F-T3MH7-GC%f%VKR_Retail________Word2024Retail
  3977. 16_06142aa2-e935-49ca-af5d-08069a3d84f3_WD8CQ-6KNQM-8W2CX-2RT63-KK%f%3TP_MAK-AE________Word2024Volume
  3978. ) do (
  3979. for /f "tokens=1-5 delims=_" %%A in ("%%#") do (
  3980. ​
  3981. if %1==getinfo if not defined key (
  3982. if %oVer%==%%A if /i "%2"=="%%E" (
  3983. set key=%%C
  3984. set _actid=%%B
  3985. set _allactid=!_allactid! %%B
  3986. set _lic=%%D
  3987. if %oVer%==16 (echo "%%D" | find /i "Subscription" %nul% && set _sublic=1)
  3988. )
  3989. )
  3990. ​
  3991. )
  3992. )
  3993. exit /b
  3994. ​
  3995. ::========================================================================================================================================
  3996. ​
  3997. :: Extract the embedded DLL unchanged. No timestamp or checksum randomization.
  3998. ​
  3999. :oh_extractdll
  4000. ​
  4001. %psc% "try { $f=[System.IO.File]::ReadAllText('!_batp!') -split ':%_hook%\:.*'; $encoded=($f[1]) -replace '-', 'A' -replace '_', 'a'; [System.IO.File]::WriteAllBytes('%~1', [Convert]::FromBase64String($encoded)) } catch { Write-Error $_; exit 1 }" %nul%
  4002. if errorlevel 1 set hasherror=1
  4003. exit /b
  4004. ​
  4005. ::========================================================================================================================================
  4006. ::
  4007. :: This below blocks of text is encoded in base64 format
  4008. :: The blocks in labels "sppc32.dll" and "sppc64.dll" contains below files
  4009. ::
  4010. :: 09865ea5993215965e8f27a74b8a41d15fd0f60f5f404cb7a8b3c7757acdab02 *sppc32.dll
  4011. :: 393a1fa26deb3663854e41f2b687c188a9eacd87b23f17ea09422c4715cb5a9f *sppc64.dll
  4012. ::
  4013. :: The files are encoded in base64 to make AIO version.
  4014. ::
  4015. :: mass{}grave{dot}dev/ohook
  4016. :: Here you can find the files source code and info on how to rebuild the identical sppc.dll files
  4017. ::
  4018. :: stackoverflow.com/a/35335273
  4019. :: Here you can check how to extract sppc.dll files from base64
  4020. ::
  4021. :: For any further question, feel free to contact us on mass{}grave{dot}dev/contactus
  4022. ::
  4023. ::========================================================================================================================================
  4024. ::
  4025. :: If you want to use a different sppc.dll or without base64 format, then create a folder named "BIN" where this script is located and
  4026. :: place these two files in that "BIN" folder. sppc32.dll, sppc64.dll
  4027. :: Script will auto pick that instead of using the below from base64 section. You can also delete the below code in that case.
  4028. ::
  4029. ::========================================================================================================================================
  4030. ::
  4031. :: Replace "-" with "A" and "_" with "a" before base64 conversion
  4032. :: It was changed to prevent antiviruses from detecting and flagging base64 encoding
  4033. ​
  4034. :sppc32.dll:
  4035. TVqQ--M----E----//8--Lg---------Q-----------------------------------------------g-----4fug4-t-nNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4g_W4gRE9TIG1vZGUuDQ0KJ---------BQRQ--T-EH-MDc0GQ----------O--
  4036. DiML-QIo--I----e--------RxE----Q----------C-_g-Q-----g--B-----E----G----------CQ----B---+dY---I-Q-E--C---B------E---E--------B------Q---jR----Bg---Y-Q---H---HgD-------------------------I---BQ---------
  4037. ----------------------------------------------------------BsY---H------------------------------------C50ZXh0----c-E----Q-----g----Q------------------C---G-ucmRhdGE--Bg-----I-----I----G----------------
  4038. --B---B-LmVoX2ZyYW2------D-----C----C-------------------Q---QC5lZGF0YQ--jR----B-----Eg----o------------------E---E-u_WRhdGE--BgB----Y-----I----c------------------B---D-LnJzcmM---B4-w---H-----E----Hg--
  4039. ----------------Q---wC5yZWxvYw--F-----C------g---CI------------------E---EI-----------------------------------------------------------------------------------------------------------------------------
  4040. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4041. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------FWJ5VZTjUXwg+wwx0Xw-----IlEJBSNRfSJ
  4042. RCQQi0UMx0QkD-----CJRCQEi0UIx0QkC--ggGqJBCTHRfQ-----6-oB--CLNXhggGqD7BiFwInDi0Xwd-qJBCQx2//WUesyi1X0x0QkB-oggGqJBCSJVCQI/xW-YIBqg+wMhcCLRfCJBCR0Cv/WuwE---BS6wP/1lCNZfiJ2FteXcNVieVXVlOD7DyLRRiLdRyJRCQQ
  4043. i0UUiXQkFIlEJ-yLRRCJRCQIi0UMiUQkBItFCIkEJOiE----McmD7BiJx4X-dVyLRRg5CHZV_9koiwYB2IN4E-B0RYlEJ-SLRQiJTeSJBCTo+/7//4tN5IX-dSwDHsdDE-E---DHQxQ-----x0MY-----MdDH-----DHQy------x0Mk-----EHrpI1l9In4W15fXcIY
  4044. -LgB----wgw-kP8lcGC-_pCQ/yVsYIBqkJD/////-----P////8-----------------------------------------------------------------------------------------------------------------------------------------------------
  4045. ------------------------------------------------TgBh-G0-ZQ---Ec-cgBh-GM-ZQ------------------------------------------------------------------------------------------------------------------------------
  4046. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4047. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4048. -----------------------------------------------------------------------------------------------------------------------------------U----------F6Ug-Bf-gBGwwEBIgB---k----H----ODf//+d-----EEOCIUCQg0FSIYD
  4049. gwQCj8NBxkHFD-QEK----EQ---BV4P//qg----BBDgiF-kINBU_H-4YEgwUCm8NBxkHHQcUMB-QQ----c----NPg//8I------------------------------------------------------------------------------------------------------------
  4050. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4051. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4052. ------------------D-3NBk-----MZC---B----Qw---EM----oQ---NEE--EBC--DPQg--70I---VD---pQw--XUM--KFD--DpQw--F0Q--DVE--BnR---nUQ--ONE---tRQ--YUU--J9F--DTRQ--DUY--DtG--BxRg--r0Y--M9G--D7Rg--nR---FFH--BvRw--
  4053. n0c--NNH---RS---TUg--G9I--ClS---zUg---VJ--BBSQ--bUk--KdJ--C7SQ--+0k--DlK--BPSg--dUo--J1K--DTSg--B0s--D1L--BpSw--pUs--ONL---NT---OUw--IlM--DRT---EU0--FlN--CjTQ--8U0--BtO--BHTg--h04--LtO--DnTg--K08--FtP
  4054. --C1Tw--608--CdQ--BdU---4kI--P1C---_Qw--RkM--IJD--DIQw---0Q--ClE--BRR---hUQ--MNE---LRQ--SkU--INF--C8RQ--80U--CdG--BZRg--k0Y--MJG--DoRg--GUc--DFH--BjRw--ikc--LxH--D1Rw--Mkg--GFI--CNS---vEg--OxI---mSQ--
  4055. Wkk--I1J--C0SQ--3kk--B1K--BHSg--ZUo--IxK--C7Sg--8Eo--CVL--BWSw--iks--MdL--D7Sw--Jkw--GRM--CwT---9Ew--DhN--CBTQ--zU0---lO---0Tg--_k4--KRO--DUTg--DE8--EZP--CLTw--008---xQ--BFU---eF-------Q-C--M-B--F--Y-
  4056. Bw-I--k-Cg-L--w-DQ-O--8-E--R-BI-Ew-U-BU-Fg-X-Bg-GQ-_-Bs-H--d-B4-Hw-g-CE-Ig-j-CQ-JQ-m-Cc-K--p-Co-Kw-s-C0-Lg-v-D--MQ-y-DM-N--1-DY-Nw-4-Dk-Og-7-Dw-PQ-+-D8-Q-BB-EI-c3BwYy5kbGw-U1BQQ1MuU0xDYWxsU2VydmVy-FNM
  4057. Q2FsbFNlcnZlcgBTUFBDUy5TTENsb3Nl-FNMQ2xvc2U-U1BQQ1MuU0xDb25zdW1lUmln_HQ-U0xDb25zdW1lUmln_HQ-U1BQQ1MuU0xEZXBvc2l0TWlncmF0_W9uQmxvYgBTTERlcG9z_XRN_WdyYXRpb25CbG9i-FNQUENTLlNMRGVwb3NpdE9mZmxpbmVDb25m_XJt
  4058. YXRpb25JZ-BTTERlcG9z_XRPZmZs_W5lQ29uZmlybWF0_W9uSWQ-U1BQQ1MuU0xEZXBvc2l0T2ZmbGluZUNvbmZpcm1hdGlvbklkRXg-U0xEZXBvc2l0T2ZmbGluZUNvbmZpcm1hdGlvbklkRXg-U1BQQ1MuU0xEZXBvc2l0U3RvcmVUb2tlbgBTTERlcG9z_XRTdG9y
  4059. ZVRv_2Vu-FNQUENTLlNMRmlyZUV2ZW50-FNMRmlyZUV2ZW50-FNQUENTLlNMR2F0_GVyTWlncmF0_W9uQmxvYgBTTEdhdGhlck1pZ3JhdGlvbkJsb2I-U1BQQ1MuU0xHYXRoZXJN_WdyYXRpb25CbG9iRXg-U0xHYXRoZXJN_WdyYXRpb25CbG9iRXg-U1BQQ1MuU0xH
  4060. ZW5lcmF0ZU9mZmxpbmVJbnN0YWxsYXRpb25JZ-BTTEdlbmVyYXRlT2ZmbGluZUluc3RhbGxhdGlvbklk-FNQUENTLlNMR2VuZXJhdGVPZmZs_W5lSW5zdGFsbGF0_W9uSWRFe-BTTEdlbmVyYXRlT2ZmbGluZUluc3RhbGxhdGlvbklkRXg-U1BQQ1MuU0xHZXRBY3Rp
  4061. dmVM_WNlbnNlSW5mbwBTTEdldEFjdGl2ZUxpY2Vuc2VJbmZv-FNQUENTLlNMR2V0QXBwbGljYXRpb25JbmZvcm1hdGlvbgBTTEdldEFwcGxpY2F0_W9uSW5mb3JtYXRpb24-U1BQQ1MuU0xHZXRBcHBs_WNhdGlvblBvbGljeQBTTEdldEFwcGxpY2F0_W9uUG9s_WN5
  4062. -FNQUENTLlNMR2V0QXV0_GVudGljYXRpb25SZXN1bHQ-U0xHZXRBdXRoZW50_WNhdGlvblJlc3Vsd-BTUFBDUy5TTEdldEVuY3J5cHRlZFBJREV4-FNMR2V0RW5jcnlwdGVkUElERXg-U1BQQ1MuU0xHZXRHZW51_W5lSW5mb3JtYXRpb24-U0xHZXRHZW51_W5lSW5m
  4063. b3JtYXRpb24-U1BQQ1MuU0xHZXRJbnN0YWxsZWRQcm9kdWN0S2V5SWRz-FNMR2V0SW5zdGFsbGVkUHJvZHVjdEtleUlkcwBTUFBDUy5TTEdldExpY2Vuc2U-U0xHZXRM_WNlbnNl-FNQUENTLlNMR2V0TGljZW5zZUZpbGVJZ-BTTEdldExpY2Vuc2VG_WxlSWQ-U1BQ
  4064. Q1MuU0xHZXRM_WNlbnNlSW5mb3JtYXRpb24-U0xHZXRM_WNlbnNlSW5mb3JtYXRpb24-U0xHZXRM_WNlbnNpbmdTdGF0dXNJbmZvcm1hdGlvbgBTUFBDUy5TTEdldFBLZXlJZ-BTTEdldFBLZXlJZ-BTUFBDUy5TTEdldFBLZXlJbmZvcm1hdGlvbgBTTEdldFBLZXlJ
  4065. bmZvcm1hdGlvbgBTUFBDUy5TTEdldFBvbGljeUluZm9ybWF0_W9u-FNMR2V0UG9s_WN5SW5mb3JtYXRpb24-U1BQQ1MuU0xHZXRQb2xpY3lJbmZvcm1hdGlvbkRXT1JE-FNMR2V0UG9s_WN5SW5mb3JtYXRpb25EV09SR-BTUFBDUy5TTEdldFByb2R1Y3RT_3VJbmZv
  4066. cm1hdGlvbgBTTEdldFByb2R1Y3RT_3VJbmZvcm1hdGlvbgBTUFBDUy5TTEdldFNMSURM_XN0-FNMR2V0U0xJRExpc3Q-U1BQQ1MuU0xHZXRTZXJ2_WNlSW5mb3JtYXRpb24-U0xHZXRTZXJ2_WNlSW5mb3JtYXRpb24-U1BQQ1MuU0xJbnN0YWxsTGljZW5zZQBTTElu
  4067. c3RhbGxM_WNlbnNl-FNQUENTLlNMSW5zdGFsbFByb29mT2ZQdXJj_GFzZQBTTEluc3RhbGxQcm9vZk9mUHVyY2hhc2U-U1BQQ1MuU0xJbnN0YWxsUHJvb2ZPZlB1cmNoYXNlRXg-U0xJbnN0YWxsUHJvb2ZPZlB1cmNoYXNlRXg-U1BQQ1MuU0xJc0dlbnVpbmVMb2Nh
  4068. bEV4-FNMSXNHZW51_W5lTG9jYWxFe-BTUFBDUy5TTExvYWRBcHBs_WNhdGlvblBvbGlj_WVz-FNMTG9hZEFwcGxpY2F0_W9uUG9s_WNpZXM-U1BQQ1MuU0xPcGVu-FNMT3BlbgBTUFBDUy5TTFBlcnNpc3RBcHBs_WNhdGlvblBvbGlj_WVz-FNMUGVyc2lzdEFwcGxp
  4069. Y2F0_W9uUG9s_WNpZXM-U1BQQ1MuU0xQZXJz_XN0UlRTUGF5bG9hZE92ZXJy_WRl-FNMUGVyc2lzdFJUU1BheWxvYWRPdmVycmlkZQBTUFBDUy5TTFJlQXJt-FNMUmVBcm0-U1BQQ1MuU0xSZWdpc3RlckV2ZW50-FNMUmVn_XN0ZXJFdmVud-BTUFBDUy5TTFJlZ2lz
  4070. dGVyUGx1Z2lu-FNMUmVn_XN0ZXJQbHVn_W4-U1BQQ1MuU0xTZXRBdXRoZW50_WNhdGlvbkRhdGE-U0xTZXRBdXRoZW50_WNhdGlvbkRhdGE-U1BQQ1MuU0xTZXRDdXJyZW50UHJvZHVjdEtleQBTTFNldEN1cnJlbnRQcm9kdWN0S2V5-FNQUENTLlNMU2V0R2VudWlu
  4071. ZUluZm9ybWF0_W9u-FNMU2V0R2VudWluZUluZm9ybWF0_W9u-FNQUENTLlNMVW5pbnN0YWxsTGljZW5zZQBTTFVu_W5zdGFsbExpY2Vuc2U-U1BQQ1MuU0xVbmluc3RhbGxQcm9vZk9mUHVyY2hhc2U-U0xVbmluc3RhbGxQcm9vZk9mUHVyY2hhc2U-U1BQQ1MuU0xV
  4072. bmxvYWRBcHBs_WNhdGlvblBvbGlj_WVz-FNMVW5sb2FkQXBwbGljYXRpb25Qb2xpY2llcwBTUFBDUy5TTFVucmVn_XN0ZXJFdmVud-BTTFVucmVn_XN0ZXJFdmVud-BTUFBDUy5TTFVucmVn_XN0ZXJQbHVn_W4-U0xVbnJlZ2lzdGVyUGx1Z2lu-FNQUENTLlNMcEF1
  4073. dGhlbnRpY2F0ZUdlbnVpbmVU_WNrZXRSZXNwb25zZQBTTHBBdXRoZW50_WNhdGVHZW51_W5lVGlj_2V0UmVzcG9uc2U-U1BQQ1MuU0xwQmVn_W5HZW51_W5lVGlj_2V0VHJhbnNhY3Rpb24-U0xwQmVn_W5HZW51_W5lVGlj_2V0VHJhbnNhY3Rpb24-U1BQQ1MuU0xw
  4074. Q2xlYXJBY3RpdmF0_W9uSW5Qcm9ncmVzcwBTTHBDbGVhckFjdGl2YXRpb25JblByb2dyZXNz-FNQUENTLlNMcERlcG9z_XREb3dubGV2ZWxHZW51_W5lVGlj_2V0-FNMcERlcG9z_XREb3dubGV2ZWxHZW51_W5lVGlj_2V0-FNQUENTLlNMcERlcG9z_XRUb2tlbkFj
  4075. dGl2YXRpb25SZXNwb25zZQBTTHBEZXBvc2l0VG9rZW5BY3RpdmF0_W9uUmVzcG9uc2U-U1BQQ1MuU0xwR2VuZXJhdGVUb2tlbkFjdGl2YXRpb25D_GFsbGVuZ2U-U0xwR2VuZXJhdGVUb2tlbkFjdGl2YXRpb25D_GFsbGVuZ2U-U1BQQ1MuU0xwR2V0R2VudWluZUJs
  4076. b2I-U0xwR2V0R2VudWluZUJsb2I-U1BQQ1MuU0xwR2V0R2VudWluZUxvY2Fs-FNMcEdldEdlbnVpbmVMb2Nhb-BTUFBDUy5TTHBHZXRM_WNlbnNlQWNxdWlz_XRpb25JbmZv-FNMcEdldExpY2Vuc2VBY3F1_XNpdGlvbkluZm8-U1BQQ1MuU0xwR2V0TVNQ_WRJbmZv
  4077. cm1hdGlvbgBTTHBHZXRNU1BpZEluZm9ybWF0_W9u-FNQUENTLlNMcEdldE1hY2hpbmVVR1VJR-BTTHBHZXRNYWNo_W5lVUdVSUQ-U1BQQ1MuU0xwR2V0VG9rZW5BY3RpdmF0_W9uR3JhbnRJbmZv-FNMcEdldFRv_2VuQWN0_XZhdGlvbkdyYW50SW5mbwBTUFBDUy5T
  4078. THBJQUFjdGl2YXRlUHJvZHVjd-BTTHBJQUFjdGl2YXRlUHJvZHVjd-BTUFBDUy5TTHBJc0N1cnJlbnRJbnN0YWxsZWRQcm9kdWN0S2V5RGVmYXVsdEtleQBTTHBJc0N1cnJlbnRJbnN0YWxsZWRQcm9kdWN0S2V5RGVmYXVsdEtleQBTUFBDUy5TTHBQcm9jZXNzVk1Q
  4079. _XBlTWVzc2FnZQBTTHBQcm9jZXNzVk1Q_XBlTWVzc2FnZQBTUFBDUy5TTHBTZXRBY3RpdmF0_W9uSW5Qcm9ncmVzcwBTTHBTZXRBY3RpdmF0_W9uSW5Qcm9ncmVzcwBTUFBDUy5TTHBUcmlnZ2VyU2VydmljZVdvcmtlcgBTTHBUcmlnZ2VyU2VydmljZVdvcmtlcgBT
  4080. UFBDUy5TTHBWTEFjdGl2YXRlUHJvZHVjd-BTTHBWTEFjdGl2YXRlUHJvZHVjd-------------------------------------------------------------------------------------------------------------------------------------------
  4081. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4082. -------------------------------------------------------------------------------------------------------------------------------------------------------------FBg-------------Ohg--BsY---XG--------------
  4083. +G---Hhg--BkY--------------MYQ--gG------------------------------iG---Kpg--------yG--------DUY--------Ihg--CqY--------Mhg--------1G---------C-FNMR2V0TGljZW5z_W5nU3RhdHVzSW5mb3JtYXRpb24--QBTTEdldFByb2R1
  4084. Y3RT_3VJbmZvcm1hdGlvbg--3QNMb2NhbEZyZWU-RwFTdHJTdHJOSVc--G----Bg--BzcHBjcy5kbGw----UY---S0VSTkVMMzIuZGxs-----Chg--BTSExXQVBJLmRsb-----------------------------------------------------------------------
  4085. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4086. -----------------------------------------------------------B-B-----Y--C--------------------B--E----w--C--------------------B--kE--BI----WH---BwD-------------BwDN----FY-UwBf-FY-RQBS-FM-SQBP-E4-XwBJ-E4-
  4087. RgBP------C9BO/+---B--U---------BQ--------------------Q-B--C--------------------f-I---E-UwB0-HI-_QBu-Gc-RgBp-Gw-ZQBJ-G4-ZgBv----W-I---E-M--0-D--OQ-w-DQ-RQ-0----eg-t--E-QwBv-G0-c-Bh-G4-eQBO-GE-bQBl----
  4088. --BB-G4-bwBt-GE-b-Bv-HU-cw-g-FM-bwBm-HQ-dwBh-HI-ZQ-g-EQ-ZQB0-GU-cgBp-G8-cgBh-HQ-_QBv-G4-I-BD-G8-cgBw-G8-cgBh-HQ-_QBv-G4------D4-Cw-B-EY-_QBs-GU-R-Bl-HM-YwBy-Gk-c-B0-Gk-bwBu------Bv-Gg-bwBv-Gs-I-BT-F--
  4089. U-BD-------w--g--QBG-Gk-b-Bl-FY-ZQBy-HM-_QBv-G4------D--Lg-1-C4-M--u-D-----q--U--QBJ-G4-d-Bl-HI-bgBh-Gw-TgBh-G0-ZQ---HM-c-Bw-GM------Iw-N--B-Ew-ZQBn-GE-b-BD-G8-c-B5-HI-_QBn-Gg-d----Kk-I--y-D--Mg-0-C--
  4090. QQBu-G8-bQBh-Gw-bwB1-HM-I-BT-G8-ZgB0-Hc-YQBy-GU-I-BE-GU-d-Bl-HI-_QBv-HI-YQB0-Gk-bwBu-C--QwBv-HI-c-Bv-HI-YQB0-Gk-bwBu----Og-J--E-TwBy-Gk-ZwBp-G4-YQBs-EY-_QBs-GU-bgBh-G0-ZQ---HM-c-Bw-GM-LgBk-Gw-b-------
  4091. L--G--E-U-By-G8-Z-B1-GM-d-BO-GE-bQBl------Bv-Gg-bwBv-Gs----0--g--QBQ-HI-bwBk-HU-YwB0-FY-ZQBy-HM-_QBv-G4----w-C4-NQ-u-D--Lg-w----R-----E-VgBh-HI-RgBp-Gw-ZQBJ-G4-ZgBv-------k--Q---BU-HI-YQBu-HM-b-Bh-HQ-
  4092. _QBv-G4-------kE5-Q-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4093. -------Q---U----MzBIMGkwdjBSMVox------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4094. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4095. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4096. ----------------------------------------------------------------------------------------
  4097. :sppc32.dll:
  4098. ​
  4099. :========================================================================================================================================
  4100. ​
  4101. :: Replace "-" with "A" and "_" with "a" before base64 conversion
  4102. :: It was changed to prevent antiviruses from detecting and flagging base64 encoding
  4103. ​
  4104. :sppc64.dll:
  4105. TVqQ--M----E----//8--Lg---------Q-----------------------------------------------g-----4fug4-t-nNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4g_W4gRE9TIG1vZGUuDQ0KJ---------BQRQ--ZIYH-MDc0GQ----------P--
  4106. LiIL-gIo--I----e--------ExE----Q-----JIx-g-----Q-----g--B----------G----------CQ----B---LeY---I-Y-E--C---------Q-----------Q--------E--------------Q-----F---I0Q----c---U-E---C---B4-w---D---CQ---------
  4107. --------------------------------------------------------------------------------iH---Dg------------------------------------udGV4d----H-B----E-----I----E-------------------g--BgLnJkYXRh---g-----C-----C
  4108. ----Bg------------------Q---QC5wZGF0YQ--J------w-----g----g------------------E---E-ueGRhdGE--CQ-----Q-----I----K------------------B---B-LmVkYXRh--CNE----F-----S----D-------------------Q---QC5pZGF0YQ--
  4109. U-E---Bw-----g---B4------------------E---M-ucnNyYw---HgD----g-----Q----g------------------B---D---------------------------------------------------------------------------------------------------------
  4110. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4111. ---------------------------------------------------------------------------------------------------------------------------------------------------------------------EFUU0iD7EhFMclMjQXvDw--SI1EJDjHRCQ0
  4112. -----EiJRCQoSI1EJDRIiUQkIEjHRCQ4-----OgF-Q--SItMJDhIix1ZY---hcBBicR0B//TRTHk6yhEi0QkNEiNF_kP--D/FUlg--BIi0wkOEiFwHQK/9NBv-E---Dr-v/TRIngSIPESFtBXMNBVUFUVVdWU0iD7Dgx9kyLrCSQ----SIusJJg---BMiWwkIEiJz0iJ
  4113. bCQo6J----BBicSFwHVEQTl1-HY+SGveKEiLVQBI-dqDeh--dChIifnoIv///4X-dRxI-10-SMdDE-E---BIx0MY-----EjHQy------SP/G67xEieBIg8Q4W15fXUFcQV3Du-E---DDkJCQkJCQkP8lel8--JCQDx+E------D/JXpf--CQk-8fh-------/yVKXw--
  4114. kJD/JTpf--CQkP//////////----------D//////////w----------------------------------------------------------------------------------------------------------------------------------------------------------
  4115. ------------------------------------------------TgBh-G0-ZQ---Ec-cgBh-GM-ZQ------------------------------------------------------------------------------------------------------------------------------
  4116. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4117. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4118. ------------------------------------------------------------------------------------------------------------------------------------E---iB----B---CIE---ExE---x----TEQ--GRE--CB-------------------------
  4119. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4120. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4121. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4122. --------------EH-w-HggMw-s----EMBw-MYggwB2-Gc-VQBM-C0----Q----------------------------------------------------------------------------------------------------------------------------------------------
  4123. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4124. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4125. -----------------------------------------------------------------------------------------------------MDc0GQ-----xlI---E---BD----Qw---ChQ---0UQ--QFI--M9S--DvUg--BVM--ClT--BdUw--oVM--OlT---XV---NVQ--GdU
  4126. --CdV---41Q--C1V--BhVQ--n1U--NNV---NVg--O1Y--HFW--CvVg--z1Y--PtW--CIE---UVc--G9X--CfVw--01c--BFY--BNW---b1g--KVY--DNW---BVk--EFZ--BtWQ--p1k--LtZ--D7WQ--OVo--E9_--B1Wg--nVo--NN_---HWw--PVs--Glb--ClWw--
  4127. 41s---1c---5X---iVw--NFc---RXQ--WV0--KNd--DxXQ--G14--Ede--CHXg--u14--Ode---rXw--W18--LVf--DrXw--J2---F1g--DiUg--/VI--BpT--BGUw--glM--MhT---DV---KVQ--FFU--CFV---w1Q---tV--BKVQ--g1U--LxV--DzVQ--J1Y--FlW
  4128. --CTVg--wlY--OhW---ZVw--MVc--GNX--CKVw--vFc--PVX---yW---YVg--I1Y--C8W---7Fg--CZZ--B_WQ--jVk--LRZ--DeWQ--HVo--Ed_--BlWg--jFo--Lt_--DwWg--JVs--FZb--CKWw--x1s--Ptb---mX---ZFw--LBc--D0X---OF0--IFd--DNXQ--
  4129. CV4--DRe--BqXg--pF4--NRe---MXw--Rl8--Itf--DTXw--DG---EVg--B4Y------B--I--w-E--U-Bg-H--g-CQ-K--s-D--N--4-Dw-Q-BE-Eg-T-BQ-FQ-W-Bc-G--Z-Bo-Gw-c-B0-Hg-f-C--IQ-i-CM-J--l-CY-Jw-o-Ck-Kg-r-Cw-LQ-u-C8-M--x-DI-
  4130. Mw-0-DU-Ng-3-Dg-OQ-6-Ds-P--9-D4-PwB--EE-QgBzcHBjLmRsb-BTUFBDUy5TTENhbGxTZXJ2ZXI-U0xDYWxsU2VydmVy-FNQUENTLlNMQ2xvc2U-U0xDbG9zZQBTUFBDUy5TTENvbnN1bWVS_Wdod-BTTENvbnN1bWVS_Wdod-BTUFBDUy5TTERlcG9z_XRN_Wdy
  4131. YXRpb25CbG9i-FNMRGVwb3NpdE1pZ3JhdGlvbkJsb2I-U1BQQ1MuU0xEZXBvc2l0T2ZmbGluZUNvbmZpcm1hdGlvbklk-FNMRGVwb3NpdE9mZmxpbmVDb25m_XJtYXRpb25JZ-BTUFBDUy5TTERlcG9z_XRPZmZs_W5lQ29uZmlybWF0_W9uSWRFe-BTTERlcG9z_XRP
  4132. ZmZs_W5lQ29uZmlybWF0_W9uSWRFe-BTUFBDUy5TTERlcG9z_XRTdG9yZVRv_2Vu-FNMRGVwb3NpdFN0b3JlVG9rZW4-U1BQQ1MuU0xG_XJlRXZlbnQ-U0xG_XJlRXZlbnQ-U1BQQ1MuU0xHYXRoZXJN_WdyYXRpb25CbG9i-FNMR2F0_GVyTWlncmF0_W9uQmxvYgBT
  4133. UFBDUy5TTEdhdGhlck1pZ3JhdGlvbkJsb2JFe-BTTEdhdGhlck1pZ3JhdGlvbkJsb2JFe-BTUFBDUy5TTEdlbmVyYXRlT2ZmbGluZUluc3RhbGxhdGlvbklk-FNMR2VuZXJhdGVPZmZs_W5lSW5zdGFsbGF0_W9uSWQ-U1BQQ1MuU0xHZW5lcmF0ZU9mZmxpbmVJbnN0
  4134. YWxsYXRpb25JZEV4-FNMR2VuZXJhdGVPZmZs_W5lSW5zdGFsbGF0_W9uSWRFe-BTUFBDUy5TTEdldEFjdGl2ZUxpY2Vuc2VJbmZv-FNMR2V0QWN0_XZlTGljZW5zZUluZm8-U1BQQ1MuU0xHZXRBcHBs_WNhdGlvbkluZm9ybWF0_W9u-FNMR2V0QXBwbGljYXRpb25J
  4135. bmZvcm1hdGlvbgBTUFBDUy5TTEdldEFwcGxpY2F0_W9uUG9s_WN5-FNMR2V0QXBwbGljYXRpb25Qb2xpY3k-U1BQQ1MuU0xHZXRBdXRoZW50_WNhdGlvblJlc3Vsd-BTTEdldEF1dGhlbnRpY2F0_W9uUmVzdWx0-FNQUENTLlNMR2V0RW5jcnlwdGVkUElERXg-U0xH
  4136. ZXRFbmNyeXB0ZWRQSURFe-BTUFBDUy5TTEdldEdlbnVpbmVJbmZvcm1hdGlvbgBTTEdldEdlbnVpbmVJbmZvcm1hdGlvbgBTUFBDUy5TTEdldEluc3RhbGxlZFByb2R1Y3RLZXlJZHM-U0xHZXRJbnN0YWxsZWRQcm9kdWN0S2V5SWRz-FNQUENTLlNMR2V0TGljZW5z
  4137. ZQBTTEdldExpY2Vuc2U-U1BQQ1MuU0xHZXRM_WNlbnNlRmlsZUlk-FNMR2V0TGljZW5zZUZpbGVJZ-BTUFBDUy5TTEdldExpY2Vuc2VJbmZvcm1hdGlvbgBTTEdldExpY2Vuc2VJbmZvcm1hdGlvbgBTTEdldExpY2Vuc2luZ1N0YXR1c0luZm9ybWF0_W9u-FNQUENT
  4138. LlNMR2V0UEtleUlk-FNMR2V0UEtleUlk-FNQUENTLlNMR2V0UEtleUluZm9ybWF0_W9u-FNMR2V0UEtleUluZm9ybWF0_W9u-FNQUENTLlNMR2V0UG9s_WN5SW5mb3JtYXRpb24-U0xHZXRQb2xpY3lJbmZvcm1hdGlvbgBTUFBDUy5TTEdldFBvbGljeUluZm9ybWF0
  4139. _W9uRFdPUkQ-U0xHZXRQb2xpY3lJbmZvcm1hdGlvbkRXT1JE-FNQUENTLlNMR2V0UHJvZHVjdFNrdUluZm9ybWF0_W9u-FNMR2V0UHJvZHVjdFNrdUluZm9ybWF0_W9u-FNQUENTLlNMR2V0U0xJRExpc3Q-U0xHZXRTTElETGlzd-BTUFBDUy5TTEdldFNlcnZpY2VJ
  4140. bmZvcm1hdGlvbgBTTEdldFNlcnZpY2VJbmZvcm1hdGlvbgBTUFBDUy5TTEluc3RhbGxM_WNlbnNl-FNMSW5zdGFsbExpY2Vuc2U-U1BQQ1MuU0xJbnN0YWxsUHJvb2ZPZlB1cmNoYXNl-FNMSW5zdGFsbFByb29mT2ZQdXJj_GFzZQBTUFBDUy5TTEluc3RhbGxQcm9v
  4141. Zk9mUHVyY2hhc2VFe-BTTEluc3RhbGxQcm9vZk9mUHVyY2hhc2VFe-BTUFBDUy5TTElzR2VudWluZUxvY2FsRXg-U0xJc0dlbnVpbmVMb2NhbEV4-FNQUENTLlNMTG9hZEFwcGxpY2F0_W9uUG9s_WNpZXM-U0xMb2FkQXBwbGljYXRpb25Qb2xpY2llcwBTUFBDUy5T
  4142. TE9wZW4-U0xPcGVu-FNQUENTLlNMUGVyc2lzdEFwcGxpY2F0_W9uUG9s_WNpZXM-U0xQZXJz_XN0QXBwbGljYXRpb25Qb2xpY2llcwBTUFBDUy5TTFBlcnNpc3RSVFNQYXlsb2FkT3ZlcnJpZGU-U0xQZXJz_XN0UlRTUGF5bG9hZE92ZXJy_WRl-FNQUENTLlNMUmVB
  4143. cm0-U0xSZUFybQBTUFBDUy5TTFJlZ2lzdGVyRXZlbnQ-U0xSZWdpc3RlckV2ZW50-FNQUENTLlNMUmVn_XN0ZXJQbHVn_W4-U0xSZWdpc3RlclBsdWdpbgBTUFBDUy5TTFNldEF1dGhlbnRpY2F0_W9uRGF0YQBTTFNldEF1dGhlbnRpY2F0_W9uRGF0YQBTUFBDUy5T
  4144. TFNldEN1cnJlbnRQcm9kdWN0S2V5-FNMU2V0Q3VycmVudFByb2R1Y3RLZXk-U1BQQ1MuU0xTZXRHZW51_W5lSW5mb3JtYXRpb24-U0xTZXRHZW51_W5lSW5mb3JtYXRpb24-U1BQQ1MuU0xVbmluc3RhbGxM_WNlbnNl-FNMVW5pbnN0YWxsTGljZW5zZQBTUFBDUy5T
  4145. TFVu_W5zdGFsbFByb29mT2ZQdXJj_GFzZQBTTFVu_W5zdGFsbFByb29mT2ZQdXJj_GFzZQBTUFBDUy5TTFVubG9hZEFwcGxpY2F0_W9uUG9s_WNpZXM-U0xVbmxvYWRBcHBs_WNhdGlvblBvbGlj_WVz-FNQUENTLlNMVW5yZWdpc3RlckV2ZW50-FNMVW5yZWdpc3Rl
  4146. ckV2ZW50-FNQUENTLlNMVW5yZWdpc3RlclBsdWdpbgBTTFVucmVn_XN0ZXJQbHVn_W4-U1BQQ1MuU0xwQXV0_GVudGljYXRlR2VudWluZVRpY2tldFJlc3BvbnNl-FNMcEF1dGhlbnRpY2F0ZUdlbnVpbmVU_WNrZXRSZXNwb25zZQBTUFBDUy5TTHBCZWdpbkdlbnVp
  4147. bmVU_WNrZXRUcmFuc2FjdGlvbgBTTHBCZWdpbkdlbnVpbmVU_WNrZXRUcmFuc2FjdGlvbgBTUFBDUy5TTHBDbGVhckFjdGl2YXRpb25JblByb2dyZXNz-FNMcENsZWFyQWN0_XZhdGlvbkluUHJvZ3Jlc3M-U1BQQ1MuU0xwRGVwb3NpdERvd25sZXZlbEdlbnVpbmVU
  4148. _WNrZXQ-U0xwRGVwb3NpdERvd25sZXZlbEdlbnVpbmVU_WNrZXQ-U1BQQ1MuU0xwRGVwb3NpdFRv_2VuQWN0_XZhdGlvblJlc3BvbnNl-FNMcERlcG9z_XRUb2tlbkFjdGl2YXRpb25SZXNwb25zZQBTUFBDUy5TTHBHZW5lcmF0ZVRv_2VuQWN0_XZhdGlvbkNoYWxs
  4149. ZW5nZQBTTHBHZW5lcmF0ZVRv_2VuQWN0_XZhdGlvbkNoYWxsZW5nZQBTUFBDUy5TTHBHZXRHZW51_W5lQmxvYgBTTHBHZXRHZW51_W5lQmxvYgBTUFBDUy5TTHBHZXRHZW51_W5lTG9jYWw-U0xwR2V0R2VudWluZUxvY2Fs-FNQUENTLlNMcEdldExpY2Vuc2VBY3F1
  4150. _XNpdGlvbkluZm8-U0xwR2V0TGljZW5zZUFjcXVpc2l0_W9uSW5mbwBTUFBDUy5TTHBHZXRNU1BpZEluZm9ybWF0_W9u-FNMcEdldE1TUGlkSW5mb3JtYXRpb24-U1BQQ1MuU0xwR2V0TWFj_GluZVVHVUlE-FNMcEdldE1hY2hpbmVVR1VJR-BTUFBDUy5TTHBHZXRU
  4151. b2tlbkFjdGl2YXRpb25HcmFudEluZm8-U0xwR2V0VG9rZW5BY3RpdmF0_W9uR3JhbnRJbmZv-FNQUENTLlNMcElBQWN0_XZhdGVQcm9kdWN0-FNMcElBQWN0_XZhdGVQcm9kdWN0-FNQUENTLlNMcElzQ3VycmVudEluc3RhbGxlZFByb2R1Y3RLZXlEZWZhdWx0S2V5
  4152. -FNMcElzQ3VycmVudEluc3RhbGxlZFByb2R1Y3RLZXlEZWZhdWx0S2V5-FNQUENTLlNMcFByb2Nlc3NWTVBpcGVNZXNzYWdl-FNMcFByb2Nlc3NWTVBpcGVNZXNzYWdl-FNQUENTLlNMcFNldEFjdGl2YXRpb25JblByb2dyZXNz-FNMcFNldEFjdGl2YXRpb25JblBy
  4153. b2dyZXNz-FNQUENTLlNMcFRy_WdnZXJTZXJ2_WNlV29y_2Vy-FNMcFRy_WdnZXJTZXJ2_WNlV29y_2Vy-FNQUENTLlNMcFZMQWN0_XZhdGVQcm9kdWN0-FNMcFZMQWN0_XZhdGVQcm9kdWN0--------------------------------------------------------
  4154. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4155. --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  4156. ----------------------------------------UH--------------IHE--Ihw--Boc--------------wcQ--oH---Hhw-------------ERx--Cwc-----------------------------D-c--------OJw--------------------cQ------------------
  4157. DHE------------------MBw--------4n--------------------Bx-------------------McQ-------------------gBTTEdldExpY2Vuc2luZ1N0YXR1c0luZm9ybWF0_W9u--E-U0xHZXRQcm9kdWN0U2t1SW5mb3JtYXRpb24--OgDTG9jYWxGcmVl-FEB
  4158. U3RyU3RyTklX--Bw----c---c3BwY3MuZGxs----FH---EtFUk5FTDMyLmRsb------oc---U0hMV0FQSS5kbGw-----------------------------------------------------------------------------------------------------------------
  4159. ----------------------------------------------------------------------------------------------------------------------------------------------E-E----Bg--I--------------------E--Q---D---I--------------
  4160. ------E-CQQ--Eg---BYg---H-M-------------H-M0----VgBT-F8-VgBF-FI-UwBJ-E8-TgBf-Ek-TgBG-E8------L0E7/4---E-BQ---------F--------------------B--E--I-------------------B8-g---QBT-HQ-cgBp-G4-ZwBG-Gk-b-Bl-Ek-
  4161. bgBm-G8---BY-g---Q-w-DQ-M--5-D--N-BF-DQ---B6-C0--QBD-G8-bQBw-GE-bgB5-E4-YQBt-GU------EE-bgBv-G0-YQBs-G8-dQBz-C--UwBv-GY-d-B3-GE-cgBl-C--R-Bl-HQ-ZQBy-Gk-bwBy-GE-d-Bp-G8-bg-g-EM-bwBy-H--bwBy-GE-d-Bp-G8-
  4162. bg------Pg-L--E-RgBp-Gw-ZQBE-GU-cwBj-HI-_QBw-HQ-_QBv-G4------G8-_-Bv-G8-_w-g-FM-U-BQ-EM------D--C--B-EY-_QBs-GU-VgBl-HI-cwBp-G8-bg------M--u-DU-Lg-w-C4-M----Co-BQ-B-Ek-bgB0-GU-cgBu-GE-b-BO-GE-bQBl----
  4163. cwBw-H--Yw------j--0--E-T-Bl-Gc-YQBs-EM-bwBw-Hk-cgBp-Gc-_-B0----qQ-g-DI-M--y-DQ-I-BB-G4-bwBt-GE-b-Bv-HU-cw-g-FM-bwBm-HQ-dwBh-HI-ZQ-g-EQ-ZQB0-GU-cgBp-G8-cgBh-HQ-_QBv-G4-I-BD-G8-cgBw-G8-cgBh-HQ-_QBv-G4-
  4164. ---6--k--QBP-HI-_QBn-Gk-bgBh-Gw-RgBp-Gw-ZQBu-GE-bQBl----cwBw-H--Yw-u-GQ-b-Bs-------s--Y--QBQ-HI-bwBk-HU-YwB0-E4-YQBt-GU------G8-_-Bv-G8-_w---DQ-C--B-F--cgBv-GQ-dQBj-HQ-VgBl-HI-cwBp-G8-bg---D--Lg-1-C4-
  4165. M--u-D----BE-----QBW-GE-cgBG-Gk-b-Bl-Ek-bgBm-G8------CQ-B----FQ-cgBh-G4-cwBs-GE-d-Bp-G8-bg------CQTkB---------------------------------------------------------------------------------------------------
  4166. ----------------------------------------------------------------------------------------
  4167. :sppc64.dll:
  4168. ​
  4169. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  4170. ​
  4171. :TSforgeActivation
  4172. ​
  4173. :: To activate Windows, run the script with "/Z-Windows" parameter or change 0 to 1 in below line
  4174. set _actwin=0
  4175. ​
  4176. :: To activate Windows ESU, run the script with "/Z-ESU" parameter or change 0 to 1 in below line
  4177. set _actesu=0
  4178. ​
  4179. :: To activate all Office apps (including Project/Visio), run the script with "/Z-Office" parameter or change 0 to 1 in below line
  4180. set _actoff=0
  4181. ​
  4182. :: To activate only Project/Visio, run the script with "/Z-ProjectVisio" parameter or change 0 to 1 in below line
  4183. set _actprojvis=0
  4184. ​
  4185. :: To activate all Windows/ESU/Office, run the script with "/Z-WindowsESUOffice" parameter or change 0 to 1 in below line
  4186. set _actwinesuoff=0
  4187. ​
  4188. :: Advanced options:
  4189. :: To activate Windows K-M-S host (csvlk), run the script with "/Z-WinHost" parameter or change 0 to 1 in below line
  4190. set _actwinhost=0
  4191. ​
  4192. :: To activate Office K-M-S host (csvlk), run the script with "/Z-OffHost" parameter or change 0 to 1 in below line
  4193. set _actoffhost=0
  4194. ​
  4195. :: To activate Windows 8/8.1 APPX Sideloading (APPXLOB), run the script with "/Z-APPX" parameter or change 0 to 1 in below line
  4196. set _actappx=0
  4197. ​
  4198. :: To activate certain activation IDs, change 0 to 1 in below line and set activation IDs in "tsids" variable, you can enter multiple by adding a space after each of them
  4199. :: or run the script with "/Z-ID-ActivationIdGoesHere" parameter. If you want to add multiple through parameter, pass each of them in separate parameters
  4200. set _actman=
  4201. set tsids=
  4202. ​
  4203. :: To reset rearm counter, evaluation period and clear the tamper state, key lock, run the script with "/Z-Reset" parameter or change 0 to 1 in below line
  4204. set _resall=0
  4205. ​
  4206. :: Choose activation method:
  4207. :: In builds 26100 and later, the script will auto select StaticCID (requires internet). If no internet is detected, it will then auto select the KMS4k method. For builds lower than 26100, the script will auto select ZeroCID.
  4208. :: To change the activation method, run the script with the parameters "/Z-SCID", "/Z-ZCID", or "/Z-KMS4k", or modify the option from Auto to SCID, ZCID, or KMS4k in the line below.
  4209. set _actmethod=Auto
  4210. ​
  4211. :: Debug Mode:
  4212. :: To run the script in debug mode, change 0 to any parameter above that you want to run, in below line
  4213. set "_debug=0"
  4214. ​
  4215. :: Script will run in unattended mode if parameters are used OR value is changed in above lines.
  4216. :: If multiple options are selected then script will only pick one from the advanced option.
  4217. ​
  4218. ​
  4219. ​
  4220. ::========================================================================================================================================
  4221. ​
  4222. cls
  4223. color 07
  4224. set KS=K%blank%MS
  4225. title TSforge Activation %masver%
  4226. ​
  4227. set _args=
  4228. set _elev=
  4229. set _unattended=0
  4230. ​
  4231. set _args=%*
  4232. if defined _args set _args=%_args:"=%
  4233. if defined _args for %%A in (%_args%) do (
  4234. if /i "%%A"=="-el" (set _elev=1)
  4235. if /i "%%A"=="/Z-Windows" (set _actwin=1)
  4236. if /i "%%A"=="/Z-ESU" (set _actesu=1)
  4237. if /i "%%A"=="/Z-Office" (set _actoff=1)
  4238. if /i "%%A"=="/Z-ProjectVisio" (set _actprojvis=1)
  4239. if /i "%%A"=="/Z-WindowsESUOffice" (set _actwinesuoff=1)
  4240. if /i "%%A"=="/Z-WinHost" (set _actwinhost=1)
  4241. if /i "%%A"=="/Z-OffHost" (set _actoffhost=1)
  4242. if /i "%%A"=="/Z-APPX" (set _actappx=1)
  4243. echo "%%A" | find /i "/Z-ID-" >nul && (set _actman=1& set "filtsids=%%A" & call set "filtsids=%%filtsids:~6%%" & if defined filtsids call set tsids=%%filtsids%% %%tsids%%)
  4244. if /i "%%A"=="/Z-Reset" (set _resall=1)
  4245. if /i "%%A"=="/Z-SCID" (set _actmethod=SCID)
  4246. if /i "%%A"=="/Z-ZCID" (set _actmethod=ZCID)
  4247. if /i "%%A"=="/Z-KMS4k" (set _actmethod=KMS4k)
  4248. )
  4249. ​
  4250. if not defined tsids set _actman=0
  4251. for %%A in (%_actwin% %_actesu% %_actoff% %_actprojvis% %_actwinesuoff% %_actwinhost% %_actoffhost% %_actappx% %_actman% %_resall%) do (if "%%A"=="1" set _unattended=1)
  4252. if /i not %_actmethod%==Auto set _unattended=1
  4253. ​
  4254. if %winbuild% LSS 7600 (
  4255. reg query "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" /v Install %nul2% | find /i "0x1" %nul1% || (
  4256. %eline%
  4257. echo .NET 3.5 Framework is not installed in your system.
  4258. echo Install it using the following URL.
  4259. echo:
  4260. echo https://www.microsoft.com/en-us/download/details.aspx?id=25150
  4261. if %_unattended%==0 start https://www.microsoft.com/en-us/download/details.aspx?id=25150
  4262. goto dk_done
  4263. )
  4264. )
  4265. ​
  4266. ::========================================================================================================================================
  4267. ​
  4268. :ts_menu
  4269. ​
  4270. if %_unattended%==0 (
  4271. cls
  4272. if not defined terminal mode 76, 33
  4273. title TSforge Activation %masver%
  4274. ​
  4275. echo:
  4276. echo:
  4277. echo:
  4278. echo ______________________________________________________________
  4279. echo:
  4280. echo [1] Activate - Windows
  4281. echo [2] Activate - ESU
  4282. echo [3] Activate - Office [All]
  4283. echo [4] Activate - Office [Project/Visio]
  4284. echo [5] Activate - All
  4285. echo _______________________________________________
  4286. echo:
  4287. echo Advanced Options:
  4288. echo:
  4289. echo [A] Activate - Windows %KS% Host
  4290. echo [B] Activate - Office %KS% Host
  4291. echo [C] Activate - Windows 8/8.1 APPX Sideloading
  4292. echo [D] Activate - Manually Select Products
  4293. if defined _vis (
  4294. echo [E] Reset - Rearm/Timers
  4295. ) else (
  4296. echo [E] Reset - Rearm/Timers/Tamper/Lock
  4297. )
  4298. echo [F] Change - Activation Method [%_actmethod%]
  4299. echo _______________________________________________
  4300. echo:
  4301. echo [6] Remove TSforge Activation
  4302. echo [0] %_exitmsg%
  4303. echo ______________________________________________________________
  4304. echo:
  4305. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard..."
  4306. choice /C:12345ABCDEF60 /N
  4307. set _el=!errorlevel!
  4308. ​
  4309. if !_el!==13 exit /b
  4310. if !_el!==12 call :ts_remove & cls & goto :ts_menu
  4311. if !_el!==11 goto :ts_changemethod
  4312. if !_el!==10 cls & setlocal & set "_resall=1" & call :ts_start & endlocal & cls & goto :ts_menu
  4313. if !_el!==9 cls & setlocal & set "_actman=1" & call :ts_start & endlocal & cls & goto :ts_menu
  4314. if !_el!==8 cls & setlocal & set "_actappx=1" & call :ts_start & endlocal & cls & goto :ts_menu
  4315. if !_el!==7 cls & setlocal & set "_actoffhost=1" & call :ts_start & endlocal & cls & goto :ts_menu
  4316. if !_el!==6 cls & setlocal & set "_actwinhost=1" & call :ts_start & endlocal & cls & goto :ts_menu
  4317. if !_el!==5 cls & setlocal & set "_actwinesuoff=1" & call :ts_start & endlocal & cls & goto :ts_menu
  4318. if !_el!==4 cls & setlocal & set "_actprojvis=1" & call :ts_start & endlocal & cls & goto :ts_menu
  4319. if !_el!==3 cls & setlocal & set "_actoff=1" & call :ts_start & endlocal & cls & goto :ts_menu
  4320. if !_el!==2 cls & setlocal & set "_actesu=1" & call :ts_start & endlocal & cls & goto :ts_menu
  4321. if !_el!==1 cls & setlocal & set "_actwin=1" & call :ts_start & endlocal & cls & goto :ts_menu
  4322. goto :ts_menu
  4323. )
  4324. ​
  4325. goto :ts_start
  4326. ​
  4327. ::========================================================================================================================================
  4328. ​
  4329. :ts_changemethod
  4330. ​
  4331. cls
  4332. if not defined terminal mode 76, 36
  4333. ​
  4334. echo:
  4335. echo:
  4336. echo:
  4337. echo ______________________________________________________________
  4338. echo:
  4339. call :dk_color2 %_White% " [1] " %_Green% "Auto"
  4340. echo Builds ^>= 26100 - StaticCID (KMS4k if offline)
  4341. echo Builds ^< 26100 - ZeroCID
  4342. echo __________________________________________________
  4343. echo:
  4344. echo [2] StaticCID
  4345. echo Needs Internet
  4346. echo Not for Windows 7 or older
  4347. echo __________________________________________________
  4348. echo:
  4349. echo [3] ZeroCID
  4350. echo Works reliably on builds below 26100
  4351. echo Does not work on builds above 26100.4188
  4352. echo __________________________________________________
  4353. echo:
  4354. echo [4] KMS4k
  4355. echo Volume licenses only
  4356. echo Activates for 4000+ years
  4357. echo __________________________________________________
  4358. echo:
  4359. echo [0] %_exitmsg%
  4360. echo ______________________________________________________________
  4361. echo:
  4362. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard..."
  4363. choice /C:12340 /N
  4364. set _el=!errorlevel!
  4365. ​
  4366. if !_el!==5 goto :ts_menu
  4367. if !_el!==4 cls & set "_actmethod=KMS4k" & goto :ts_menu
  4368. if !_el!==3 cls & set "_actmethod=ZCID" & goto :ts_menu
  4369. if !_el!==2 cls & set "_actmethod=SCID" & goto :ts_menu
  4370. if !_el!==1 cls & set "_actmethod=Auto" & goto :ts_menu
  4371. goto :ts_changemethod
  4372. ​
  4373. ::========================================================================================================================================
  4374. ​
  4375. :ts_start
  4376. ​
  4377. cls
  4378. ​
  4379. if %_actwinesuoff%==1 (set height=38) else (set height=32)
  4380. if not defined terminal (
  4381. mode 125, %height%
  4382. if exist "%SysPath%\spp\store_test\" mode 134, %height%
  4383. %psc% "&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=%height%;$B.Height=300;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}" %nul%
  4384. )
  4385. title TSforge Activation %masver%
  4386. ​
  4387. echo:
  4388. echo Initializing...
  4389. call :dk_chkmal
  4390. ​
  4391. if not exist %SysPath%\%_slexe% (
  4392. %eline%
  4393. echo [%SysPath%\%_slexe%] file is missing, aborting...
  4394. echo:
  4395. if not defined results (
  4396. call :dk_color %Blue% "Go back to Main Menu, select Troubleshoot and run DISM Restore and SFC Scan options."
  4397. call :dk_color %Blue% "After that, restart system and try activation again."
  4398. set fixes=%fixes% %mas%in-place_repair_upgrade
  4399. call :dk_color2 %Blue% "If it still shows the same error, do this - " %_Yellow% " %mas%in-place_repair_upgrade"
  4400. )
  4401. goto dk_done
  4402. )
  4403. ​
  4404. for /f "delims=" %%a in ('%psc% "[System.Environment]::Version.Major" %nul6%') do if "%%a"=="2" (
  4405. reg query "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" /v Install %nul2% | find /i "0x1" %nul1% || (
  4406. %eline%
  4407. echo .NET 3.5 Framework is corrupt or missing. Aborting...
  4408. if exist "%SysPath%\spp\tokens\skus\Security-SPP-Component-SKU-Embedded" (
  4409. echo Install .NET Framework 4.8 and Windows Management Framework 5.1
  4410. )
  4411. set fixes=%fixes% %mas%troubleshoot
  4412. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  4413. goto dk_done
  4414. )
  4415. )
  4416. ​
  4417. if %winbuild% LSS 9200 if exist "%SysPath%\wlms\wlms.exe" (
  4418. sc query wlms | find /i "RUNNING" %nul% && (
  4419. sc stop %_slser% %nul%
  4420. if !errorlevel! EQU 1051 (
  4421. %eline%
  4422. echo Evaluation WLMS service is running, %_slser% service can not be stopped. Aborting...
  4423. echo Install Non-Eval version for Windows build %winbuild%.
  4424. set fixes=%fixes% %mas%troubleshoot
  4425. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  4426. goto dk_done
  4427. )
  4428. )
  4429. )
  4430. ​
  4431. ::========================================================================================================================================
  4432. ​
  4433. if %_actwinesuoff%==1 (set "_actwin=1" & set "_actesu=1" & set "_actoff=1")
  4434. if %_actprojvis%==1 (set "_actoff=1")
  4435. ​
  4436. set spp=SoftwareLicensingProduct
  4437. set sps=SoftwareLicensingService
  4438. ​
  4439. call :dk_ckeckwmic
  4440. call :dk_checksku
  4441. call :dk_product
  4442. call :dk_sppissue
  4443. ​
  4444. ::========================================================================================================================================
  4445. ​
  4446. set error=
  4447. ​
  4448. cls
  4449. echo:
  4450. call :dk_showosinfo
  4451. ​
  4452. if /i %_actmethod%==SCID set tsmethod=StaticCID
  4453. if /i %_actmethod%==ZCID set tsmethod=ZeroCID
  4454. if /i %_actmethod%==KMS4k set tsmethod=KMS4k
  4455. ​
  4456. if /i %_actmethod%==Auto (
  4457. if %winbuild% GEQ 26100 (
  4458. set tsmethod=StaticCID
  4459. ) else (
  4460. set tsmethod=ZeroCID
  4461. )
  4462. )
  4463. ​
  4464. if %winbuild% LSS 9200 if /i %tsmethod%==StaticCID (
  4465. %eline%
  4466. echo StaticCID method is supported only on Windows 8 and later.
  4467. goto dk_done
  4468. )
  4469. ​
  4470. ::========================================================================================================================================
  4471. ​
  4472. :: Check Internet connection
  4473. ​
  4474. if /i %tsmethod%==StaticCID (
  4475. set _int=
  4476. for %%a in (download.windowsupdate.com) do if not defined _int (
  4477. for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do (if not "%%#"=="" set _int=1)
  4478. )
  4479. ​
  4480. if not defined _int (
  4481. %psc% "If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}"
  4482. if !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)
  4483. )
  4484. ​
  4485. if defined _int (
  4486. echo Checking Internet Connection [Connected!ping_f!]
  4487. ) else (
  4488. if /i %_actmethod%==Auto if not %_actman%==1 set tsmethod=KMS4k
  4489. if /i !tsmethod!==KMS4k (
  4490. call :dk_color %Red% "Checking Internet Connection [Not Connected]"
  4491. call :dk_color %Blue% "Switching To KMS4k activation because Internet is needed for StaticCID method."
  4492. ) else (
  4493. set error=1
  4494. call :dk_color %Red% "Checking Internet Connection [Not Connected]"
  4495. call :dk_color %Blue% "Internet is required for TSforge StaticCID option."
  4496. )
  4497. echo:
  4498. )
  4499. )
  4500. ​
  4501. ::========================================================================================================================================
  4502. ​
  4503. echo Initiating Diagnostic Tests...
  4504. ​
  4505. set "_serv=%_slser% Winmgmt"
  4506. ​
  4507. :: Software Protection
  4508. :: Windows Management Instrumentation
  4509. ​
  4510. call :dk_errorcheck
  4511. ​
  4512. call :ts_getedition
  4513. if not defined tsedition (
  4514. call :dk_color %Red% "Checking Windows Edition ID [Not found in installed licenses, aborting...]"
  4515. set fixes=%fixes% %mas%troubleshoot
  4516. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  4517. goto :dk_done
  4518. )
  4519. ​
  4520. if /i !tsmethod!==KMS4k (
  4521. call :_taskclear-cache
  4522. echo Clearing %KS% Cache [Successful]
  4523. )
  4524. ​
  4525. ::========================================================================================================================================
  4526. ​
  4527. if %_resall%==1 goto :ts_resetall
  4528. if %_actman%==1 goto :ts_actman
  4529. if %_actappx%==1 goto :ts_appxlob
  4530. if %_actwinhost%==1 goto :ts_whost
  4531. if %_actoffhost%==1 goto :ts_ohost
  4532. if not %_actwin%==1 goto :ts_esu
  4533. ​
  4534. ::========================================================================================================================================
  4535. ​
  4536. :: Process Windows
  4537. :: Check if system is permanently activated or not
  4538. ​
  4539. echo:
  4540. echo Processing Windows...
  4541. ​
  4542. echo %tsedition% | find /i "Eval" %nul1% && (
  4543. goto :ts_wineval
  4544. )
  4545. ​
  4546. set /a UBR=0
  4547. if %winbuild% EQU 26100 (
  4548. for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v UBR %nul6%') do if not errorlevel 1 set /a UBR=%%b
  4549. if !UBR! LSS 4188 (set dontcheckact=1)
  4550. )
  4551. ​
  4552. if not defined dontcheckact call :ts_checkwinperm
  4553. if defined _perm (
  4554. call :dk_color %Gray% "Checking OS Activation [Windows is already permanently activated]"
  4555. goto :ts_esu
  4556. )
  4557. ​
  4558. if %winbuild% LSS 9200 if /i %tsmethod%==KMS4k goto :ts_oldks
  4559. if defined _vis goto :ts_winvista
  4560. ​
  4561. set tempid=
  4562. if /i %tsmethod%==KMS4k (set keytype=ks) else (set keytype=zero)
  4563. for /f "delims=" %%a in ('%psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':wintsid\:.*';. ([scriptblock]::Create($f[1]))" %nul6%') do (
  4564. echo "%%a" | findstr /r ".*-.*-.*-.*-.*" %nul1% && (set tsids=!tsids! %%a& set tempid=%%a)
  4565. )
  4566. ​
  4567. if defined tempid (
  4568. echo Checking Activation ID [%tempid%] [%tsedition%]
  4569. ) else (
  4570. call :dk_color %Red% "Checking Activation ID [Not Found] [%tsedition%] [%osSKU%]"
  4571. set error=1
  4572. if /i %tsmethod%==KMS4k (
  4573. if /i %_actmethod%==Auto (
  4574. call :dk_color %Blue% "Connect to the Internet and try again. Script will use the StaticCID activation method."
  4575. ) else (
  4576. call :dk_color %Blue% "Use non-KMS4K activation options from the previous menu."
  4577. )
  4578. )
  4579. goto :ts_esu
  4580. )
  4581. ​
  4582. if defined winsub (
  4583. call :dk_color %Blue% "Windows Subscription [SKU ID-%slcSKU%] found. Script will activate base edition [SKU ID-%regSKU%]."
  4584. echo:
  4585. )
  4586. ​
  4587. goto :ts_esu
  4588. ​
  4589. ::========================================================================================================================================
  4590. ​
  4591. :ts_oldks
  4592. ​
  4593. :: KMS keys for KMS4k method because TSforge cannot install KMS key on Windows Vista and 7
  4594. ​
  4595. :: 1st column = Activation ID
  4596. :: 2nd column = Generic key
  4597. :: 3rd column = Edition ID
  4598. :: Separator = _
  4599. ​
  4600. set f=
  4601. set key=
  4602. set tempid=
  4603. if not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  4604. ​
  4605. for %%# in (
  4606. :: Windows 7
  4607. ae2ee509-1b34-41c0-acb7-6d4650168915_33PXH-7Y6KF-2VJC9-XBBR8-HV%f%THH_Enterprise
  4608. 1cb6d605-11b3-4e14-bb30-da91c8e3983a_YDRBP-3D83W-TY26F-D46B2-XC%f%KRJ_EnterpriseN
  4609. b92e9980-b9d5-4821-9c94-140f632f6312_FJ82H-XT6CR-J8D7P-XQJJ2-GP%f%DD4_Professional
  4610. 54a09a0d-d57b-4c10-8b69-a842d6590ad5_MRPKT-YTG23-K7D7T-X2JMM-QY%f%7MG_ProfessionalN
  4611. db537896-376f-48ae-a492-53d0547773d0_YBYF6-BHCR3-JPKRB-CDW7B-F9%f%BK4_Embedded_POSReady
  4612. aa6dd3aa-c2b4-40e2-a544-a6bbb3f5c395_73KQT-CD9G6-K7TQG-66MRP-CQ%f%22C_Embedded_ThinPC
  4613. 5a041529-fef8-4d07-b06f-b59b573b32d2_W82YF-2Q76Y-63HXB-FGJG9-GF%f%7QX_ProfessionalE
  4614. 46bbed08-9c7b-48fc-a614-95250573f4ea_C29WB-22CC8-VJ326-GHFJW-H9%f%DH4_EnterpriseE
  4615. :: Windows Server 2008 R2
  4616. 68531fb9-5511-4989-97be-d11a0f55633f_YC6KT-GKW9T-YTKYR-T4X34-R7%f%VHC_ServerStandard
  4617. 7482e61b-c589-4b7f-8ecc-46d455ac3b87_74YFP-3QFB3-KQT8W-PMXWJ-7M%f%648_ServerDatacenter
  4618. 620e2b3d-09e7-42fd-802a-17a13652fe7a_489J6-VHDMP-X63PK-3K798-CP%f%X3Y_ServerEnterprise
  4619. 7482e61b-c589-4b7f-8ecc-46d455ac3b87_74YFP-3QFB3-KQT8W-PMXWJ-7M%f%648_ServerDatacenterCore
  4620. 68531fb9-5511-4989-97be-d11a0f55633f_YC6KT-GKW9T-YTKYR-T4X34-R7%f%VHC_ServerStandardCore
  4621. 620e2b3d-09e7-42fd-802a-17a13652fe7a_489J6-VHDMP-X63PK-3K798-CP%f%X3Y_ServerEnterpriseCore
  4622. 8a26851c-1c7e-48d3-a687-fbca9b9ac16b_GT63C-RJFQ3-4GMB6-BRFB9-CB%f%83V_ServerEnterpriseIA64
  4623. a78b8bd9-8017-4df5-b86a-09f756affa7c_6TPJF-RBVHG-WBW2R-86QPH-6R%f%TM4_ServerWeb
  4624. cda18cf3-c196-46ad-b289-60c072869994_TT8MH-CG224-D3D7Q-498W2-9Q%f%CTX_ServerHPC
  4625. a78b8bd9-8017-4df5-b86a-09f756affa7c_6TPJF-RBVHG-WBW2R-86QPH-6R%f%TM4_ServerWebCore
  4626. f772515c-0e87-48d5-a676-e6962c3e1195_736RG-XDKJK-V34PF-BHK87-J6%f%X3K_ServerEmbeddedSolution
  4627. :: Windows Vista
  4628. cfd8ff08-c0d7-452b-9f60-ef5c70c32094_VKK3X-68KWM-X2YGT-QR4M6-4B%f%WMV_Enterprise
  4629. 4f3d1606-3fea-4c01-be3c-8d671c401e3b_YFKBB-PQJJV-G996G-VWGXY-2V%f%3X8_Business
  4630. 2c682dc2-8b68-4f63-a165-ae291d4cf138_HMBQG-8H2RH-C77VX-27R82-VM%f%QBT_BusinessN
  4631. d4f54950-26f2-4fb4-ba21-ffab16afcade_VTC42-BM838-43QHV-84HX6-XJ%f%XKV_EnterpriseN
  4632. :: Windows Server 2008
  4633. ad2542d4-9154-4c6d-8a44-30f11ee96989_TM24T-X9RMF-VWXK6-X8JC9-BF%f%GM2_ServerStandard
  4634. 68b6e220-cf09-466b-92d3-45cd964b9509_7M67G-PC374-GR742-YH8V4-TC%f%BY3_ServerDatacenter
  4635. c1af4d90-d1bc-44ca-85d4-003ba33db3b9_YQGMW-MPWTJ-34KDK-48M3W-X4%f%Q6V_ServerEnterprise
  4636. 01ef176b-3e0d-422a-b4f8-4ea880035e8f_4DWFP-JF3DJ-B7DTH-78FJB-PD%f%RHK_ServerEnterpriseIA64
  4637. ddfa9f7c-f09e-40b9-8c1a-be877a9a7f4b_WYR28-R7TFJ-3X2YQ-YCY4H-M2%f%49D_ServerWeb
  4638. 7afb1156-2c1d-40fc-b260-aab7442b62fe_RCTX3-KWVHP-BR6TB-RB6DM-6X%f%7HP_ServerComputeCluster
  4639. 2401e3d0-c50a-4b58-87b2-7e794b7d2607_W7VD6-7JFBR-RX26B-YKQ3Y-6F%f%FFJ_ServerStandardV
  4640. fd09ef77-5647-4eff-809c-af2b64659a45_22XQ2-VRXRG-P8D42-K34TD-G3%f%QQC_ServerDatacenterV
  4641. 8198490a-add0-47b2-b3ba-316b12d647b4_39BXF-X8Q23-P2WWT-38T2F-G3%f%FPG_ServerEnterpriseV
  4642. ) do (
  4643. for /f "tokens=1-3 delims=_" %%A in ("%%#") do if %tsedition%==%%C if not defined key (
  4644. echo "%allapps%" | find /i "%%A" %nul1% && (
  4645. set key=%%B
  4646. set tempid=%%A
  4647. )
  4648. )
  4649. )
  4650. ​
  4651. if not defined key (
  4652. call :dk_color %Red% "Checking Activation ID [%tsedition% SKU-%osSKU% %KS% key is not available]"
  4653. call :dk_color %Blue% "Use ZeroCID activation method from the previous menu."
  4654. goto :ts_esu
  4655. )
  4656. ​
  4657. echo Checking Activation ID [%tempid%] [%tsedition%]
  4658. ​
  4659. set oldks=1
  4660. set generickey=1
  4661. call :dk_inskey "[%key%]"
  4662. set tsids=%tsids% %tempid%
  4663. goto :ts_esu
  4664. ​
  4665. ::========================================================================================================================================
  4666. ​
  4667. :ts_winvista
  4668. ​
  4669. :: Process Windows Vista
  4670. ​
  4671. :: 1st column = Activation ID
  4672. :: 2nd column = Generic key
  4673. :: 3rd column = Key channel
  4674. :: 4th column = Edition ID
  4675. :: Separator = _
  4676. ​
  4677. :: Keys aren't available for these editions, but since these editions aren't publicly available, it doesn't matter
  4678. :: a797d61e-1475-470b-86c8-f737a72c188d StarterN
  4679. :: 5e9f548a-c8a9-44e6-a6c2-3f8d0a7a99dd ServerComputeClusterV
  4680. ​
  4681. set f=
  4682. set key=
  4683. set tempid=
  4684. if not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  4685. ​
  4686. for %%# in (
  4687. :: WindowsVista
  4688. 9de9abe2-d01d-4538-af84-4498bdbc2ba3_4D2XH-PRBMM-8Q22B-K8BM3-MR%f%W4W_____Retail_Business
  4689. db442be4-81ed-4ab3-9d66-2417e8a5c81c_76884-QXFY2-6Q2WX-2QTQ8-QX%f%X44_____Retail_BusinessN
  4690. b51791c2-b562-4b73-97b0-735a0e4429a6_YQPQV-RW8R3-XMPFG-RXG9R-JG%f%TVF_____Retail_Enterprise
  4691. 58c37517-42f8-4723-bb44-30b05791ff2a_Q7J9R-G63R4-BFMHF-FWM9R-RW%f%DMV_____Retail_EnterpriseN
  4692. 95c6e80a-0ff8-4bd0-95f2-c4a39b79d09e_RCG7P-TX42D-HM8FM-TCFCW-3V%f%4VD_____Retail_HomeBasic
  4693. d0333dad-c14e-46f2-b62a-8b47a1b9768b_HY2VV-XC6FF-MD6WV-FPYBQ-GF%f%JBT_____Retail_HomeBasicN
  4694. 9e042223-03bf-49ae-808f-ff37f128d40d_X9HTF-MKJQQ-XK376-TJ7T4-76%f%PKF_____Retail_HomePremium
  4695. 92d8977c-d506-4e63-b500-6d39283b6cd5_KJ6TP-PF9W2-23T3Q-XTV7M-PX%f%DT2_____Retail_HomePremiumN
  4696. 89e51a3c-76c0-4beb-a650-53d34c8f8186_X9PYV-YBQRV-9BXWV-TQDMK-QD%f%WK4_____Retail_Starter
  4697. 30fab9cc-8614-4339-989f-7ce61fb7a5c4_VMCB9-FDRV6-6CDQM-RV23K-RP%f%8F7_____Retail_Ultimate
  4698. 1eefed20-8ac0-478c-8774-70cd44782ea1_CVX38-P27B4-2X8BT-RXD4J-V7%f%CKX_____Retail_UltimateN
  4699. :: WindowsServer2008
  4700. c9ad502b-ef48-41d1-a2a0-38a38e82fed0_24FV9-H7JW8-C8Q6X-BQKMK-K9%f%77J_____Retail_ServerComputeCluster
  4701. 866e924e-c2a3-4872-aca1-6b48c13962d5_6QBHY-DXTPJ-T9W3P-DTJXX-4V%f%QMB_____Retail_ServerDatacenter
  4702. d020c729-07f0-4f8f-87ce-bf803275c786_83TWG-TD3TC-HRDP2-K93FJ-Y3%f%4YC_OEM:NONSLP_ServerDatacenterV
  4703. 32b40e5e-0c6d-4c6f-ab12-a031933fd2c6_MRB7H-QJRHG-FXTBR-B2Q2M-8W%f%MTJ_____Retail_ServerEnterprise
  4704. 256cc990-1692-4ea8-965c-2d423d5dd24e_H4VB6-QPRWH-VDCYM-996P8-MH%f%KFY_OEM:NONSLP_ServerEnterpriseIA64
  4705. 1ba5e036-e386-42c4-b7eb-16bdb4fa1945_H8H7M-HDPQT-PJHQF-M7B83-9C%f%VGV_____Retail_ServerEnterpriseV
  4706. 8df04457-07c8-4301-bce9-d61eb76cb2d6_RGBMC-PQBVF-94Q9K-HD63B-VY%f%6MP_____Retail_ServerHomePremium
  4707. 5bd23b19-aa71-4a5b-8b68-c8801c2baff6_6C8KR-MD3QK-9GWFW-44CY2-W9%f%CBM_____Retail_ServerHomeStandard
  4708. b86c7736-91ff-4de9-bfa9-b32b8a09acac_7XRBY-6MP2K-VQPT8-F37JV-YY%f%Q83_____Retail_ServerMediumBusinessManagement
  4709. d3f5642f-081d-40b2-a4b9-efd3054d4584_6PDTD-JK48J-662TF-8J2QV-R4%f%CRB_____Retail_ServerMediumBusinessMessaging
  4710. c6936a36-69f3-4994-9857-3069c7b9ec7a_D694V-CMWKH-PY92X-PFQKQ-JC%f%B69_____Retail_ServerMediumBusinessSecurity
  4711. cc4c2cf8-ef29-4d8e-b168-2b65a3db3309_MRDK3-YYQF3-88BQJ-D6FJG-69%f%YJY_____Retail_ServerSBSPremium
  4712. b3827b27-bd38-4284-98af-e4f4d1c051a0_2KB23-GJRBD-W3T9C-6CH2W-39%f%B7V_____Retail_ServerSBSPrime
  4713. 5dad0eff-3f6f-4310-8844-422f9dc7c84b_H4XDD-B27GY-667P6-XWVV7-GY%f%G8J_____Retail_ServerSBSStandard
  4714. 603504f9-109f-49f0-9271-8c66f7878f58_8YVM4-YQBDH-7WDQM-R27WR-WV%f%CWG_____Retail_ServerStandard
  4715. 65ab7338-9ad0-43fe-af1b-190b577495e2_H9MW3-6V7GK-94P9G-7FTPJ-VK%f%CKF_____Retail_ServerStandardV
  4716. 2be204da-24a0-4943-b66c-81e8464acd7e_2264C-TD9T8-P8HPW-CC9GH-MH%f%M2V_____Retail_ServerStorageEnterprise
  4717. 60207eba-8b4a-486c-a013-023b4b742c2f_RCYMT-YX342-8T6YY-XYHYC-3D%f%D7X_____Retail_ServerStorageExpress
  4718. 368856e9-43f7-4601-8358-e561f36c7dd8_FKFT2-WXYY9-WBPY7-6YMY4-X4%f%8JF_____Retail_ServerStorageStandard
  4719. 4bf433fa-ab04-4c6c-b55b-00170e14b8cd_8X9J7-HCJ7J-3WDJT-QM7D8-46%f%4YH_____Retail_ServerStorageWorkgroup
  4720. a77a6806-f59e-4953-97d7-229317b8e6a6_BGT39-9FYH7-X2CYD-T628F-QP%f%QPW_____Retail_ServerWeb
  4721. f92f836d-4d3e-4e90-a08f-2d612d65e716_HPH76-FHFPP-DRW9D-7W2V4-HW%f%GKT_____Retail_ServerWinSB
  4722. 3059a9fd-b068-4f0d-acaf-66324dca67ac_2V8G6-KRXYR-MMGXJ-6RWM3-GX%f%CCG_____Retail_ServerWinSBV
  4723. ) do (
  4724. for /f "tokens=1-4 delims=_" %%A in ("%%#") do if %tsedition%==%%D if not defined key (
  4725. echo "%allapps%" | find /i "%%A" %nul1% && (
  4726. set key=%%B
  4727. set tempid=%%A
  4728. )
  4729. )
  4730. )
  4731. ​
  4732. if not defined key (
  4733. set error=1
  4734. call :dk_color %Red% "Checking Activation ID [%tsedition% SKU-%osSKU% not found in the system]"
  4735. call :dk_color %Blue% "%_fixmsg%"
  4736. goto :ts_esu
  4737. )
  4738. ​
  4739. echo Checking Activation ID [%tempid%] [%tsedition%]
  4740. ​
  4741. set generickey=1
  4742. call :dk_inskey "[%key%]"
  4743. set tsids=%tsids% %tempid%
  4744. goto :ts_esu
  4745. ​
  4746. ::========================================================================================================================================
  4747. ​
  4748. :ts_wineval
  4749. ​
  4750. call :dk_color %Gray% "Checking OS Edition [%tsedition%] [Evaluation edition found]"
  4751. call :dk_color %Blue% "Evaluation editions cannot be activated outside of evaluation period."
  4752. ​
  4753. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" (
  4754. call :dk_color %Blue% "Script will reset evaluation period, but to permanently activate Windows,"
  4755. call :dk_color %Blue% "Go back to main menu and use [Change Edition] option and change to Non-eval edition."
  4756. ) else (
  4757. call :dk_color %Blue% "Script will reset evaluation period, but to permanently activate Windows, install Non-eval edition."
  4758. call :dk_color %_Yellow% "%mas%evaluation_editions"
  4759. )
  4760. ​
  4761. :: Check Internet connection
  4762. ​
  4763. set _int=
  4764. for %%a in (download.windowsupdate.com) do if not defined _int (
  4765. for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do (if not "%%#"=="" set _int=1)
  4766. )
  4767. ​
  4768. if not defined _int (
  4769. %psc% "If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}"
  4770. if !errorlevel!==0 (set _int=1&set ping_f= But Ping Failed)
  4771. )
  4772. ​
  4773. if defined _int (
  4774. echo Checking Internet Connection [Connected%ping_f%]
  4775. ) else (
  4776. set error=1
  4777. call :dk_color %Red% "Checking Internet Connection [Not Connected]"
  4778. call :dk_color %Blue% "Internet is required for Windows Evaluation activation."
  4779. )
  4780. ​
  4781. :: List of products lacking activable evaluation keys and ISOs
  4782. ​
  4783. :: c4b908d2-c4b9-439d-8ff0-48b656a24da4_EmbeddedIndustryEEval_8.1
  4784. :: 9b74255b-afe1-4da7-a143-98d1874b2a6c_EnterpriseNEval_8
  4785. :: 7fd0a88b-fb89-415f-9b79-84adc6a7cd56_EnterpriseNEval_8.1
  4786. :: 994578eb-193c-4c99-bea0-2483274c9afd_EnterpriseSNEval_2015
  4787. :: b9f3109c-bfa9-4f37-9824-6dba9ee62056_ServerStorageStandardEval_2012R2
  4788. :: 2d3b7269-65f4-467d-9d51-dbe0e5a4e668_ServerStorageWorkgroupEval_2012R2
  4789. ​
  4790. :: --------
  4791. ​
  4792. :: 1st column = Activation ID
  4793. :: 2nd column = Activable evaluation key
  4794. :: 3rd column = Edition ID
  4795. :: 4th column = Windows version (for reference only)
  4796. :: 5th column = NoAct = activation is not working
  4797. :: Separator = _
  4798. ​
  4799. set f=
  4800. set key=
  4801. set eval=
  4802. if not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  4803. ​
  4804. for %%# in (
  4805. d9eea459-1e6b-499d-8486-e68163f2a8be_N3QJR-YCWKK-RVJGK-GQFMX-T8%f%2BF_EmbeddedIndustryEval_8.1
  4806. fbd4c5c6-adc6-4740-bc65-b2dc6dc249c1_MJ8TN-42JH8-886MT-8THCF-36%f%67B_EnterpriseEval_8_NoAct_ REM New time based activation not available
  4807. 0eebbb45-29d4-49cb-ba87-a23db0cce40a_76FKW-8NR3K-QDH4P-3C87F-JH%f%TTW_EnterpriseEval_8.1
  4808. 3f4c0546-36c6-46a8-a37f-be13cdd0cf25_7HBDQ-QNKVG-K4RBF-HMBY6-YG%f%9R6_EnterpriseEval_10
  4809. 1f8dbfe8-defa-4676-b5a6-f76949a01540_4N8VT-7Y686-43DGV-THTW9-M9%f%8W7_EnterpriseNEval_10
  4810. 57a4ebb6-8e0c-41f8-b79e-8872ddc971ef_W63GF-7N4D9-GQH3K-K4FP7-9B%f%T6C_EnterpriseSEval_2015
  4811. b47dd250-fd6a-44c8-9217-03aca6e4812e_N4DMT-RJKDQ-XR6H7-3DKKP-3Y%f%JWT_EnterpriseSEval_2016
  4812. 267bf82d-08e8-4046-b061-9ef3f8ac2b5a_N7HMH-MK36Q-M4X93-76KQ2-6J%f%HWR_EnterpriseSEval_2019
  4813. aff25f1f-fb53-4e27-95ef-b8e5aca10ac6_9V4NK-624Y3-VK47R-Q27GP-27%f%PGF_EnterpriseSEval_2021
  4814. 399f0697-886b-4881-894c-4ff6c52e7d8f_CYPB3-XNV9V-QR4G4-Q3B8K-KQ%f%FGJ_EnterpriseSEval_2024
  4815. 6162e8c2-3c30-46e1-b964-0de603498e2d_R34N9-HJ6Q3-GBX4F-Q24KQ-49%f%DF7_EnterpriseSNEval_2016
  4816. aed14fc8-907d-44fb-a3a1-d5d8e638acb3_MHN9Q-RD9PW-BFHDQ-9FTWQ-WQ%f%PF8_EnterpriseSNEval_2019
  4817. 5dd0c869-eae9-40ce-af48-736692cd8e43_XCN62-29X92-C4T8X-WP82X-DY%f%MJ8_EnterpriseSNEval_2021
  4818. 522cc0dc-3c7b-4258-ae68-f297ca63b64e_Y8DJM-NPXF3-QG4MH-W7WJK-KQ%f%FGM_EnterpriseSNEval_2024
  4819. aa708397-8618-42de-b120-a44190ef456d_R63DV-9NPDX-QVWJF-HMR8V-M4%f%K7D_IoTEnterpriseSEval_2024
  4820. cd25b1e8-5839-4a96-a769-b6abe3aa5dee_73BMN-332G9-DX6B8-FGDT3-GF%f%YT6_ServerDatacenterEval_2012
  4821. e628c5e8-2300-4429-8b80-a8b21bd7ce0a_WPR94-KN3J7-MRB7X-JPJV8-RX%f%7J2_ServerDatacenterEval_2012R2
  4822. 01398239-85ff-487f-9e90-0e3cc5bcc92e_QVTQ9-GNRBH-JQ9G7-W7FBW-RX%f%9QR_ServerDatacenterEval_2016
  4823. 5ea4af9e-fd59-4691-b61c-1fc1ff3e309e_KNW3G-22YD2-7QKQJ-2RF2X-H6%f%F8M_ServerDatacenterEval_2019
  4824. 1d02774d-66ab-4c57-8b14-e254fdce09d4_PK7JN-24236-FH7JP-V792F-37%f%CYR_ServerDatacenterEval_2021
  4825. 96794a98-097f-42fe-8f28-2c38ea115229_M4RNW-CRTHF-TY7BG-DDHG6-J2%f%T92_ServerDatacenterEval_2025
  4826. 38d172c7-36b3-4e4b-b435-fd0b06b95c6e_RNFGD-WFFQR-XQ8BG-K7QQK-GJ%f%CP9_ServerStandardEval_2012
  4827. 4fc45a88-26b5-4cf9-9eef-769ee3f0a016_79M8M-N36BX-8YGJY-2G9KP-3Y%f%GPC_ServerStandardEval_2012R2
  4828. 9dfa8ec0-7665-4b9d-b2cb-bfc2dc37c9f4_9PBKX-4NHGT-QWV4C-4JD94-TV%f%KQ6_ServerStandardEval_2016
  4829. 7783a126-c108-4cf7-b59f-13c78c7a7337_J4WNC-H9BG3-6XRX4-3XD8K-Y7%f%XRX_ServerStandardEval_2019
  4830. c1a197b6-ba5e-4394-b9bf-b659a6c1b873_7PBJM-MNVPD-MBQD7-TYTY4-W8%f%JDY_ServerStandardEval_2021
  4831. 753c53a2-4274-4339-8c2e-f66c0b9646c5_YPBVM-HFNWQ-CTF9M-FR4RR-7H%f%9YG_ServerStandardEval_2025
  4832. 0de5ff31-2d62-4912-b1a8-3ea01d2461fd_3CKBN-3GJ8X-7YT4X-D8DDC-D6%f%69B_ServerStorageStandardEval_2012
  4833. fb08f53a-e597-40dc-9f08-8bbf99f19b92_NCJ6J-J23VR-DBYB3-QQBJF-W8%f%CP7_ServerStorageWorkgroupEval_2012
  4834. ) do (
  4835. for /f "tokens=1-5 delims=_" %%A in ("%%#") do if %tsedition%==%%C if not defined key (
  4836. echo "%allapps%" | find /i "%%A" %nul1% && (
  4837. set key=%%B
  4838. set eval=1
  4839. if /i "%%E"=="NoAct" set noact=1
  4840. echo Checking Activation ID [%%A] [%%C]
  4841. )
  4842. )
  4843. )
  4844. ​
  4845. if not defined key (
  4846. set error=1
  4847. call :dk_color %Red% "Checking Activation ID [%tsedition% not found in the script]"
  4848. call :dk_color %Blue% "Make sure you are using the updated version of the script."
  4849. goto :ts_esu
  4850. )
  4851. ​
  4852. set resetstuff=1
  4853. %psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':tsforge\:.*';. ([scriptblock]::Create($f[1]))"
  4854. set resetstuff=
  4855. if !errorlevel!==3 (
  4856. set error=1
  4857. call :dk_color %Red% "Resetting Rearm / GracePeriod [Failed]"
  4858. call :dk_color %Blue% "%_fixmsg%"
  4859. goto :ts_esu
  4860. ) else (
  4861. echo Resetting Rearm / GracePeriod [Successful]
  4862. )
  4863. ​
  4864. set generickey=1
  4865. call :dk_inskey "[%key%]"
  4866. ​
  4867. ::========================================================================================================================================
  4868. ​
  4869. :ts_esu
  4870. ​
  4871. if not %_actesu%==1 goto :ts_off
  4872. if /i %tsmethod%==KMS4k (
  4873. call :dk_color %Red% "Skipping Windows ESU [KMS4k method is not supported with Windows ESU]"
  4874. if /i %_actmethod%==Auto (
  4875. call :dk_color %Blue% "Connect to the Internet and try again. Script will use the StaticCID activation method."
  4876. ) else (
  4877. call :dk_color %Blue% "Use non-KMS4K activation options from the previous menu."
  4878. )
  4879. goto :ts_off
  4880. )
  4881. ​
  4882. :: Process Windows ESU
  4883. ​
  4884. echo:
  4885. echo Processing Windows ESU...
  4886. ​
  4887. set esuexist=
  4888. set esuexistsup=
  4889. set esueditionlist=
  4890. set esuexistbutnosup=
  4891. ​
  4892. for %%# in (EnterpriseS IoTEnterpriseS IoTEnterpriseSK) do (if /i %tsedition%==%%# set isltsc=1)
  4893. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" set isServer=1
  4894. ​
  4895. if /i %tsedition%==Embedded (
  4896. if exist "%SystemRoot%\Servicing\Packages\WinEmb-Branding-Embedded-ThinPC-Package*.mum" set isThinpc=1
  4897. if exist "%SystemRoot%\Servicing\Packages\WinEmb-Branding-Embedded-POSReady7-Package*.mum" set subEdition=[POS]
  4898. if exist "%SystemRoot%\Servicing\Packages\WinEmb-Branding-Embedded-Standard-Package*.mum" set subEdition=[Standard]
  4899. )
  4900. if not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  4901. ​
  4902. set w10EsuEditions=Education-EducationN-Enterprise-EnterpriseN-Professional-ProfessionalEducation-ProfessionalEducationN-ProfessionalN-ProfessionalWorkstation-ProfessionalWorkstationN
  4903. ​
  4904. set minbuild=0
  4905. if /i %tsedition%==ServerRdsh set minbuild=5552
  4906. for %%# in (Core CoreN CoreCountrySpecific CoreSingleLanguage IoTEnterprise) do (if /i %tsedition%==%%# set minbuild=6156)
  4907. if /i %tsedition%==PPIPro set minbuild=6388
  4908. ​
  4909. set /a UBR=0
  4910. for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v UBR %nul6%') do if not errorlevel 1 set /a UBR=%%b
  4911. if %winbuild% EQU 19045 if %minbuild% GTR 0 if %UBR% GEQ %minbuild% (
  4912. set w10EsuEditionsLaterAdded=%tsedition%-
  4913. )
  4914. ​
  4915. if not defined isThinpc if not defined isltsc for %%# in (
  4916. REM Windows7
  4917. 4220f546-f522-46df-8202-4d07afd26454_Client-ESU-Year3[1-3y]_-Enterprise-EnterpriseE-EnterpriseN-Professional-ProfessionalE-ProfessionalN-Ultimate-UltimateE-UltimateN-
  4918. 7e94be23-b161-4956-a682-146ab291774c_Client-ESU-Year6[4-6y]_-Enterprise-EnterpriseE-EnterpriseN-Professional-ProfessionalE-ProfessionalN-Ultimate-UltimateE-UltimateN-
  4919. REM Windows7EmbeddedPOSReady7
  4920. 4f1f646c-1e66-4908-acc7-d1606229b29e_POS-ESU-Year3[1-3y]_-Embedded[POS]-
  4921. REM Windows7EmbeddedStandard
  4922. 6aaf1c7d-527f-4ed5-b908-9fc039dfc654_WES-ESU-Year3[1-3y]_-Embedded[Standard]-
  4923. REM WindowsServer2008/WindowsServer2008R2
  4924. 8e7bfb1e-acc1-4f56-abae-b80fce56cd4b_Server-ESU-PA[1-6y]_-ServerDatacenter-ServerDatacenterCore-ServerDatacenterV-ServerDatacenterVCore-ServerStandard-ServerStandardCore-ServerStandardV-ServerStandardVCore-ServerEnterprise-ServerEnterpriseCore-ServerEnterpriseV-ServerEnterpriseVCore-
  4925. REM Windows8.1
  4926. 4afc620f-12a4-48ad-8015-2aebfbd6e47c_Client-ESU-Year3[1-3y]_-Enterprise-EnterpriseN-Professional-ProfessionalN-
  4927. 11be7019-a309-4763-9a09-091d1722ffe3_Client-FES-ESU-Year3[1-3y]_-EmbeddedIndustry-EmbeddedIndustryE-
  4928. REM WindowsServer2012/2012R2
  4929. 55b1dd2d-2209-4ea0-a805-06298bad25b3_Server-ESU-Year3[1-3y]_-ServerDatacenter-ServerDatacenterCore-ServerDatacenterV-ServerDatacenterVCore-ServerStandard-ServerStandardCore-ServerStandardV-ServerStandardVCore-
  4930. REM Windows10
  4931. f520e45e-7413-4a34-a497-d2765967d094_Client-ESU-Year1_-%w10EsuEditions%-%w10EsuEditionsLaterAdded%
  4932. 1043add5-23b1-4afb-9a0f-64343c8f3f8d_Client-ESU-Year2_-%w10EsuEditions%-%w10EsuEditionsLaterAdded%
  4933. 83d49986-add3-41d7-ba33-87c7bfb5c0fb_Client-ESU-Year3_-%w10EsuEditions%-%w10EsuEditionsLaterAdded%
  4934. 0b533b5e-08b6-44f9-b885-c2de291ba456_Client-ESU-Year6[4-6y]_-%w10EsuEditions%-%w10EsuEditionsLaterAdded%
  4935. REM WindowsServer2016
  4936. 91bcac0a-d7d3-4d2b-bd0c-72fed675f01b_Server-ESU-Year3[1-3y]_-ServerDatacenter-ServerDatacenterCore-ServerDatacenterV-ServerDatacenterVCore-ServerStandard-ServerStandardCore-ServerStandardV-ServerStandardVCore-
  4937. 4cd0ab30-73a4-4dde-972c-512f05be31df_Server-ESU-Year6[4-6y]_-ServerDatacenter-ServerDatacenterCore-ServerDatacenterV-ServerDatacenterVCore-ServerStandard-ServerStandardCore-ServerStandardV-ServerStandardVCore-
  4938. ) do (
  4939. for /f "tokens=1-3 delims=_" %%A in ("%%#") do (
  4940. echo "%allapps%" | find /i "%%A" %nul1% && (
  4941. set esuexist=1
  4942. echo "%%C" | find /i "-%tsedition%%subEdition%-" %nul1% && (
  4943. set esuexistsup=1
  4944. set esueditionlist=
  4945. set esuexistbutnosup=
  4946. set tsids=!tsids! %%A
  4947. echo Checking Activation ID [%%A] [%%B]
  4948. ) || (
  4949. if not defined esueditionlist set esueditionlist=%%C
  4950. set esuexistbutnosup=1
  4951. )
  4952. )
  4953. )
  4954. )
  4955. ​
  4956. if defined esuexistsup if defined _vis (
  4957. set key=9FPV7-MWGT8-7XPDF-JC23W-WT7TW
  4958. REM This is a non-generic blocked MAK key for Server-ESU-PA
  4959. call :dk_inskey "[!key!]"
  4960. goto :ts_off
  4961. )
  4962. ​
  4963. if defined esuexistsup (
  4964. echo "%tsids%" | find /i "4220f546-f522-46df-8202-4d07afd26454" %nul1% && (
  4965. echo "%tsids%" | find /i "7e94be23-b161-4956-a682-146ab291774c" %nul1% || (
  4966. call :dk_color %Gray% "To get Client-ESU-Year6[4-6y] license, install updates from the below URL."
  4967. call :dk_color %Blue% "%mas%tsforge#windows-esu"
  4968. )
  4969. )
  4970. goto :ts_off
  4971. )
  4972. ​
  4973. if defined isltsc (
  4974. call :dk_color %Gray% "Checking Activation ID [%tsedition% LTSC already has longer support, ESU is not applicable]"
  4975. goto :ts_off
  4976. )
  4977. ​
  4978. if defined esuexistbutnosup (
  4979. call :dk_color %Red% "Checking Activation ID [Currently installed ESU License is not supported for %tsedition%]"
  4980. echo:
  4981. if %winbuild% EQU 19045 if not defined w10EsuEditionsLaterAdded (
  4982. call :dk_color %Blue% "To get latest version, go to Windows settings and run Windows Update. After that, try the script again."
  4983. goto :ts_off
  4984. )
  4985. call :dk_color %Blue% "Go back to Main Menu, select Change Windows Edition option and change to any of the below listed editions."
  4986. echo [%esueditionlist%]
  4987. goto :ts_off
  4988. )
  4989. ​
  4990. set esuavail=
  4991. if defined _vis if defined isServer set esuavail=1
  4992. if %winbuild% LEQ 7602 if not defined _vis if not defined isThinpc set esuavail=1
  4993. if %winbuild% GTR 7602 if %winbuild% LSS 14393 if defined isServer set esuavail=1
  4994. if %winbuild% GEQ 10240 if %winbuild% LEQ 19045 if not defined isServer set esuavail=1
  4995. if %winbuild% EQU 9600 set esuavail=1
  4996. ​
  4997. if defined esuavail (
  4998. call :dk_color %Red% "Checking Activation ID [ESU license is not found, make sure Windows is fully updated]"
  4999. set fixes=%fixes% %mas%tsforge#windows-esu
  5000. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%tsforge#windows-esu"
  5001. ) else (
  5002. call :dk_color %Gray% "Checking Activation ID [ESU is not available for %winos%]"
  5003. )
  5004. ​
  5005. ::========================================================================================================================================
  5006. ​
  5007. :ts_off
  5008. ​
  5009. if not %_actoff%==1 goto :ts_act
  5010. ​
  5011. if %winbuild% LSS 9200 (
  5012. echo:
  5013. call :dk_color %Gray% "Checking Supported Office [TSforge for Office is supported on Windows 8 and later versions]"
  5014. call :dk_color %Blue% "On Windows Vista / 7, use Ohook activation option for Office instead."
  5015. goto :ts_act
  5016. )
  5017. ​
  5018. :: Check ohook install
  5019. ​
  5020. set ohook=
  5021. for %%# in (15 16) do (
  5022. for %%A in ("%ProgramFiles%" "%ProgramW6432%" "%ProgramFiles(x86)%") do (
  5023. if exist "%%~A\Microsoft Office\Office%%#\sppc*dll" set ohook=1
  5024. )
  5025. )
  5026. ​
  5027. for %%# in (System SystemX86) do (
  5028. for %%G in ("Office 15" "Office") do (
  5029. for %%A in ("%ProgramFiles%" "%ProgramW6432%" "%ProgramFiles(x86)%") do (
  5030. if exist "%%~A\Microsoft %%~G\root\vfs\%%#\sppc*dll" set ohook=1
  5031. )
  5032. )
  5033. )
  5034. ​
  5035. if defined ohook (
  5036. echo:
  5037. call :dk_color %Gray% "Checking Ohook [Ohook activation is already installed for Office]"
  5038. )
  5039. ​
  5040. :: Check unsupported office versions
  5041. ​
  5042. set o14msi=
  5043. set o14c2r=
  5044. ​
  5045. set _68=HKLM\SOFTWARE\Microsoft\Office
  5046. set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office
  5047. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set o14msi=Office 2010 MSI )
  5048. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set o14msi=Office 2010 MSI )
  5049. %nul% reg query %_68%\14.0\CVH /f Click2run /k && set o14c2r=Office 2010 C2R
  5050. %nul% reg query %_86%\14.0\CVH /f Click2run /k && set o14c2r=Office 2010 C2R
  5051. ​
  5052. if not "%o14msi%%o14c2r%"=="" (
  5053. echo:
  5054. call :dk_color %Red% "Checking Unsupported Office Install [ %o14msi%%o14c2r%]"
  5055. if defined o14msi call :dk_color %Blue% "Use Ohook activation option for Office 2010."
  5056. )
  5057. ​
  5058. if %winbuild% GEQ 10240 %psc% "Get-AppxPackage -name "Microsoft.MicrosoftOfficeHub"" | find /i "Office" %nul1% && (
  5059. set ohub=1
  5060. )
  5061. ​
  5062. ::========================================================================================================================================
  5063. ​
  5064. :: Check supported office versions
  5065. ​
  5066. call :ts_getpath
  5067. ​
  5068. set o16uwp=
  5069. set o16uwp_path=
  5070. ​
  5071. if %winbuild% GEQ 10240 (
  5072. for /f "delims=" %%a in ('%psc% "(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty InstallLocation)" %nul6%') do (if exist "%%a\Integration\Integrator.exe" (set o16uwp=1&set "o16uwp_path=%%a"))
  5073. )
  5074. ​
  5075. sc query ClickToRunSvc %nul%
  5076. set error1=%errorlevel%
  5077. ​
  5078. if defined o16c2r if %error1% EQU 1060 (
  5079. echo:
  5080. call :dk_color %Red% "Checking ClickToRun Service [Not found, Office 16.0 files found]"
  5081. set o16c2r=
  5082. set error=1
  5083. )
  5084. ​
  5085. sc query OfficeSvc %nul%
  5086. set error2=%errorlevel%
  5087. ​
  5088. if defined o15c2r if %error1% EQU 1060 if %error2% EQU 1060 (
  5089. echo:
  5090. call :dk_color %Red% "Checking ClickToRun Service [Not found, Office 15.0 files found]"
  5091. set o15c2r=
  5092. set error=1
  5093. )
  5094. ​
  5095. if "%o16uwp%%o16c2r%%o15c2r%%o16msi%%o15msi%"=="" (
  5096. set error=1
  5097. set showfix=1
  5098. echo:
  5099. if not "%o14msi%%o14c2r%"=="" (
  5100. call :dk_color %Red% "Checking Supported Office Install [Not Found]"
  5101. ) else (
  5102. if %_actwin%==0 (
  5103. call :dk_color %Red% "Checking Installed Office [Not Found]"
  5104. ) else (
  5105. call :dk_color %Gray% "Checking Installed Office [Not Found]"
  5106. )
  5107. )
  5108. ​
  5109. if defined ohub (
  5110. echo:
  5111. echo You only have the Office Dashboard app installed; you need to install the full version of Office.
  5112. )
  5113. call :dk_color %Blue% "Download and install Office from the URL below, then try again."
  5114. if %_actwin%==0 set fixes=%fixes% %mas%genuine-installation-media
  5115. call :dk_color %_Yellow% "%mas%genuine-installation-media"
  5116. goto :ts_act
  5117. )
  5118. ​
  5119. set multioffice=
  5120. if not "%o16uwp%%o16c2r%%o15c2r%%o16msi%%o15msi%"=="1" set multioffice=1
  5121. if not "%o14c2r%%o14msi%"=="" set multioffice=1
  5122. ​
  5123. if defined multioffice (
  5124. echo:
  5125. call :dk_color %Gray% "Checking Multiple Office Install [Found. Recommended to install one version only]"
  5126. )
  5127. ​
  5128. ::========================================================================================================================================
  5129. ​
  5130. :: Check Windows Server
  5131. ​
  5132. set winserver=
  5133. reg query "HKLM\SYSTEM\CurrentControlSet\Control\ProductOptions" /v ProductType %nul2% | find /i "WinNT" %nul1% || set winserver=1
  5134. if not defined winserver (
  5135. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul2% | find /i "Server" %nul1% && set winserver=1
  5136. )
  5137. ​
  5138. ::========================================================================================================================================
  5139. ​
  5140. :: Process Office UWP
  5141. ​
  5142. if not defined o16uwp goto :ts_starto15c2r
  5143. ​
  5144. call :ts_reset
  5145. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  5146. ​
  5147. set oVer=16
  5148. set "_oLPath=%o16uwp_path%\Licenses16"
  5149. set "pkeypath=%o16uwp_path%\Office16\pkeyconfig-office.xrm-ms"
  5150. for /f "delims=" %%a in ('%psc% "(Get-AppxPackage -name 'Microsoft.Office.Desktop' | Select-Object -ExpandProperty Dependencies) | Select-Object PackageFullName" %nul6%') do (set "o16uwpapplist=!o16uwpapplist! %%a")
  5151. ​
  5152. echo "%o16uwpapplist%" | findstr /i "Access Excel OneNote Outlook PowerPoint Publisher SkypeForBusiness Word" %nul% && set "_oIds=O365HomePremRetail"
  5153. ​
  5154. for %%# in (Project Visio) do (
  5155. echo "%o16uwpapplist%" | findstr /i "%%#" %nul% && (
  5156. set _lat=
  5157. if exist "%_oLPath%\%%#Pro2024VL*.xrm-ms" set "_oIds= !_oIds! %%#Pro2024Retail " & set _lat=1
  5158. if not defined _lat if exist "%_oLPath%\%%#Pro2021VL*.xrm-ms" set "_oIds= !_oIds! %%#Pro2021Retail " & set _lat=1
  5159. if not defined _lat if exist "%_oLPath%\%%#Pro2019VL*.xrm-ms" set "_oIds= !_oIds! %%#Pro2019Retail " & set _lat=1
  5160. if not defined _lat set "_oIds= !_oIds! %%#ProRetail "
  5161. )
  5162. )
  5163. ​
  5164. set uwpinfo=%o16uwp_path:C:\Program Files\WindowsApps\Microsoft.Office.Desktop_=%
  5165. ​
  5166. echo:
  5167. echo Processing Office... [UWP ^| %uwpinfo%]
  5168. ​
  5169. if not defined _oIds (
  5170. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  5171. set error=1
  5172. goto :ts_starto15c2r
  5173. )
  5174. ​
  5175. call :ts_process
  5176. ​
  5177. ::========================================================================================================================================
  5178. ​
  5179. :ts_starto15c2r
  5180. ​
  5181. :: Process Office 15.0 C2R
  5182. ​
  5183. if not defined o15c2r goto :ts_starto16c2r
  5184. ​
  5185. call :ts_reset
  5186. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  5187. ​
  5188. set oVer=15
  5189. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg% /v InstallPath" %nul6%') do (set "_oRoot=%%b\root")
  5190. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\Configuration /v Platform" %nul6%') do (set "_oArch=%%b")
  5191. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\Configuration /v VersionToReport" %nul6%') do (set "_version=%%b")
  5192. for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\Configuration /v ProductReleaseIds" %nul6%') do (set "_prids=%o15c2r_reg%\Configuration /v ProductReleaseIds" & set "_config=%o15c2r_reg%\Configuration")
  5193. if not defined _oArch for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\propertyBag /v Platform" %nul6%') do (set "_oArch=%%b")
  5194. if not defined _version for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\propertyBag /v version" %nul6%') do (set "_version=%%b")
  5195. if not defined _prids for /f "skip=2 tokens=2*" %%a in ('"reg query %o15c2r_reg%\propertyBag /v ProductReleaseId" %nul6%') do (set "_prids=%o15c2r_reg%\propertyBag /v ProductReleaseId" & set "_config=%o15c2r_reg%\propertyBag")
  5196. ​
  5197. echo "%o15c2r_reg%" | find /i "Wow6432Node" %nul1% && (set _tok=10) || (set _tok=9)
  5198. for /f "tokens=%_tok% delims=\" %%a in ('reg query %o15c2r_reg%\ProductReleaseIDs\Active %nul6% ^| findstr /i "Retail Volume"') do (
  5199. echo "!_oIds!" | find /i " %%a " %nul1% || (set "_oIds= !_oIds! %%a ")
  5200. )
  5201. ​
  5202. set "_oLPath=%_oRoot%\Licenses"
  5203. set "pkeypath=%_oRoot%\Office15\pkeyconfig-office.xrm-ms"
  5204. set "_oIntegrator=%_oRoot%\integration\integrator.exe"
  5205. ​
  5206. echo:
  5207. echo Processing Office... [C2R ^| %_version% ^| %_oArch%]
  5208. ​
  5209. if not defined _oIds (
  5210. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  5211. set error=1
  5212. goto :ts_starto16c2r
  5213. )
  5214. ​
  5215. call :oh_expiredpreview 2013
  5216. if "%_actprojvis%"=="0" call :oh_fixprids
  5217. call :ts_process
  5218. ​
  5219. ::========================================================================================================================================
  5220. ​
  5221. :ts_starto16c2r
  5222. ​
  5223. :: Process Office 16.0 C2R
  5224. ​
  5225. if not defined o16c2r goto :ts_startmsi
  5226. ​
  5227. call :ts_reset
  5228. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  5229. ​
  5230. set oVer=16
  5231. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg% /v InstallPath" %nul6%') do (set "_oRoot=%%b\root")
  5232. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v Platform" %nul6%') do (set "_oArch=%%b")
  5233. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v VersionToReport" %nul6%') do (set "_version=%%b")
  5234. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v AudienceData" %nul6%') do (set "_AudienceData=^| %%b ")
  5235. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v ProductReleaseIds" %nul6%') do (set "_prids=%o16c2r_reg%\Configuration /v ProductReleaseIds" & set "_config=%o16c2r_reg%\Configuration")
  5236. ​
  5237. echo "%o16c2r_reg%" | find /i "Wow6432Node" %nul1% && (set _tok=9) || (set _tok=8)
  5238. for /f "tokens=%_tok% delims=\" %%a in ('reg query "%o16c2r_reg%\ProductReleaseIDs" /s /f ".16" /k %nul6% ^| findstr /i "Retail Volume"') do (
  5239. echo "!_oIds!" | find /i " %%a " %nul1% || (set "_oIds= !_oIds! %%a ")
  5240. )
  5241. set _oIds=%_oIds:.16=%
  5242. set _o16c2rIds=%_oIds%
  5243. ​
  5244. set "_oLPath=%_oRoot%\Licenses16"
  5245. set "pkeypath=%_oRoot%\Office16\pkeyconfig-office.xrm-ms"
  5246. set "_oIntegrator=%_oRoot%\integration\integrator.exe"
  5247. ​
  5248. echo:
  5249. echo Processing Office... [C2R ^| %_version% %_AudienceData%^| %_oArch%]
  5250. ​
  5251. if not defined _oIds (
  5252. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  5253. set error=1
  5254. goto :ts_startmsi
  5255. )
  5256. ​
  5257. call :oh_expiredpreview 2016 2019 2021 2024
  5258. if "%_actprojvis%"=="0" call :oh_fixprids
  5259. call :ts_process
  5260. ​
  5261. ::========================================================================================================================================
  5262. ​
  5263. :: mass{}grave{dot}dev/office-license-is-not-genuine
  5264. :: Add registry keys for volume products so that 'non-genuine' banner won't appear
  5265. ​
  5266. set "kmskey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\0ff1ce15-a989-479d-af46-f275c6370663"
  5267. if /i %tsmethod%==KMS4k (
  5268. if %winbuild% GEQ 9200 (
  5269. if not "%osarch%"=="x86" (
  5270. reg delete "%kmskey%" /f /reg:32 %nul%
  5271. reg add "%kmskey%" /f /v KeyManagementServiceName /t REG_SZ /d "127.0.0.1" /reg:32 %nul%
  5272. )
  5273. reg delete "%kmskey%" /f %nul%
  5274. reg add "%kmskey%" /f /v KeyManagementServiceName /t REG_SZ /d "127.0.0.1" %nul%
  5275. echo Adding a Registry to Prevent Banner [Successful]
  5276. )
  5277. )
  5278. ​
  5279. ::========================================================================================================================================
  5280. ​
  5281. :ts_startmsi
  5282. ​
  5283. if defined o15msi call :ts_processmsi 15 %o15msi_reg%
  5284. if defined o16msi call :ts_processmsi 16 %o16msi_reg%
  5285. ​
  5286. ::========================================================================================================================================
  5287. ​
  5288. echo:
  5289. call :oh_clearblock
  5290. if "%o16msi%%o15msi%"=="" if not "%o16uwp%%o16c2r%%o15c2r%"=="" call :oh_uninstkey
  5291. call :oh_licrefresh
  5292. ​
  5293. goto :ts_act
  5294. ​
  5295. ::========================================================================================================================================
  5296. ​
  5297. :ts_whost
  5298. ​
  5299. :: Process Windows K-M-S host
  5300. ​
  5301. echo:
  5302. echo Processing Windows %KS% Host...
  5303. ​
  5304. if /i %tsmethod%==KMS4k (
  5305. echo:
  5306. call :dk_color %Red% "Skipping Windows %KS% Host [KMS4k method is not supported with Windows %KS% Host]"
  5307. if /i %_actmethod%==Auto (
  5308. call :dk_color %Blue% "Connect to the Internet and try again. Script will use the StaticCID activation method."
  5309. ) else (
  5310. call :dk_color %Blue% "Use non-KMS4K activation options from the previous menu."
  5311. )
  5312. goto :ts_act
  5313. )
  5314. ​
  5315. echo:
  5316. if %winbuild% GEQ 10586 (
  5317. call :dk_color %Gray% "With %KS% Host license, system may randomly change Windows Edition later. It is a Windows issue and can be safely ignored."
  5318. )
  5319. call :dk_color %Gray% "%KS% Host [Not to be confused with %KS% Client] license causes the %_slser% service to run continuously."
  5320. call :dk_color %Blue% "Only use this activation when necessary, you can revert to normal activation from the previous menu."
  5321. ​
  5322. if %_unattended%==0 (
  5323. echo:
  5324. choice /C:0F /N /M "> [0] Go back [F] Continue : "
  5325. if !errorlevel!==1 exit /b
  5326. echo:
  5327. )
  5328. ​
  5329. set _arr=
  5330. set tempid=
  5331. set keytype=kmshost
  5332. ​
  5333. if defined _vis goto :ts_whost_vista
  5334. ​
  5335. :: Install current edition csvlk license so that correct edition can reflect for csvlk
  5336. ​
  5337. if %winbuild% GEQ 10586 (
  5338. for %%# in ("%SysPath%\spp\tokens\skus\%tsedition%\*CSVLK*.xrm-ms") do (
  5339. if defined _arr (set "_arr=!_arr!;"%SysPath%\spp\tokens\skus\%tsedition%\%%~nx#"") else (set "_arr="%SysPath%\spp\tokens\skus\%tsedition%\%%~nx#"")
  5340. )
  5341. if defined _arr %psc% "$sls = Get-WmiObject %sps%; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\:.*';. ([scriptblock]::Create($f[1])); InstallLicenseArr '!_arr!'" %nul%
  5342. )
  5343. ​
  5344. for /f "delims=" %%a in ('%psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':wintsid\:.*';. ([scriptblock]::Create($f[1]))" %nul6%') do (
  5345. echo "%%a" | findstr /r ".*-.*-.*-.*-.*" %nul1% && (set tsids=!tsids! %%a& set tempid=%%a)
  5346. )
  5347. ​
  5348. if defined tempid (
  5349. echo Checking Activation ID [%tempid%] [%tsedition%]
  5350. ) else (
  5351. call :dk_color %Red% "Checking Activation ID [Not Found] [%tsedition%] [%osSKU%]"
  5352. call :dk_color %Blue% "%KS% Host license is not found on your system. It is available for the below editions."
  5353. call :dk_color %Blue% "Professional, Education, ProfessionalWorkstation, Enterprise, EnterpriseS, and Server editions, etc."
  5354. goto :ts_act
  5355. )
  5356. ​
  5357. if defined winsub (
  5358. echo:
  5359. call :dk_color %Blue% "Windows Subscription [SKU ID-%slcSKU%] found. Script will activate base edition [SKU ID-%regSKU%]."
  5360. )
  5361. ​
  5362. goto :ts_act
  5363. ​
  5364. ::========================================================================================================================================
  5365. ​
  5366. :ts_whost_vista
  5367. ​
  5368. :: Process Windows K-M-S host for Vista
  5369. ​
  5370. :: 1st column = Activation ID
  5371. :: 2nd column = CSVLK key
  5372. :: 3rd column = Edition IDs
  5373. :: Separator = _
  5374. ​
  5375. set f=
  5376. set key=
  5377. set tempid=
  5378. if not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  5379. ​
  5380. for %%# in (
  5381. :: WindowsVista
  5382. 212a64dc-43b1-4d3d-a30c-2fc69d2095c6_TWVG3-9Q4P8-W9XJF-Y76FJ-DW%f%Q4R_-Business-BusinessN-Enterprise-EnterpriseN-
  5383. :: WindowsServer2008
  5384. c90d1b4e-8aa8-439e-8b9e-b6d6b6a6d975_BHC4Q-6D7B7-QMVH7-4MKQH-Y9%f%VK7_-ServerComputeCluster-ServerDatacenter-ServerDatacenterV-ServerEnterprise-ServerEnterpriseIA64-ServerEnterpriseV-ServerStandard-ServerStandardV-ServerWeb-
  5385. 56df4151-1f9f-41bf-acaa-2941c071872b_PVGKG-2R7XQ-7WTFD-FXTJR-DQ%f%BQ3_-ServerComputeCluster-ServerEnterprise-ServerEnterpriseV-ServerStandard-ServerStandardV-ServerWeb-
  5386. c448fa06-49d1-44ec-82bb-0085545c3b51_KH4PC-KJFX6-XFVHQ-GDK2G-JC%f%JY9_-ServerComputeCluster-ServerWeb-
  5387. ) do (
  5388. for /f "tokens=1-3 delims=_" %%A in ("%%#") do if not defined key (
  5389. echo "%allapps%" | find /i "%%A" %nul1% && (
  5390. echo "%%C" | find /i "-%tsedition%-" %nul1% && (
  5391. set key=%%B
  5392. set tempid=%%A
  5393. )
  5394. )
  5395. )
  5396. )
  5397. ​
  5398. if defined key (
  5399. echo Checking Activation ID [%tempid%] [%tsedition%]
  5400. ) else (
  5401. call :dk_color %Red% "Checking Activation ID [Not Found] [%tsedition%] [%osSKU%]"
  5402. call :dk_color %Blue% "%KS% Host license is not found on your system. It is available for the below editions."
  5403. call :dk_color %Blue% "Business, BusinessN, Enterprise, EnterpriseN, and Server editions, etc."
  5404. goto :ts_act
  5405. )
  5406. ​
  5407. call :dk_inskey "[%key%]"
  5408. set tsids=%tsids% %tempid%
  5409. goto :ts_act
  5410. ​
  5411. ::========================================================================================================================================
  5412. ​
  5413. :ts_ohost
  5414. ​
  5415. :: Process Office K-M-S host
  5416. ​
  5417. echo:
  5418. echo Processing Office %KS% Host...
  5419. ​
  5420. if defined _vis (
  5421. echo:
  5422. call :dk_color %Blue% "Windows Vista and Server 2008 do not support the installation of Office KMS Host."
  5423. goto :ts_act
  5424. )
  5425. ​
  5426. if /i %tsmethod%==KMS4k (
  5427. echo:
  5428. call :dk_color %Red% "Skipping Office %KS% Host [KMS4k method is not supported with Office %KS% Host]"
  5429. if /i %_actmethod%==Auto (
  5430. call :dk_color %Blue% "Connect to the Internet and try again. Script will use the StaticCID activation method."
  5431. ) else (
  5432. call :dk_color %Blue% "Use non-KMS4K activation options from the previous menu."
  5433. )
  5434. goto :ts_act
  5435. )
  5436. ​
  5437. set ohostexist=
  5438. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  5439. set ohostids=%allapps%
  5440. call :dk_actids 59a52881-a989-479d-af46-f275c6370663
  5441. set ohostids=%ohostids% %allapps%
  5442. ​
  5443. for %%# in (
  5444. bfe7a195-4f8f-4f0b-a622-cf13c7d16864_KMSHost2010-ProPlusVL
  5445. f3d89bbf-c0ec-47ce-a8fa-e5a5f97e447f_KMSHost2024Volume
  5446. 47f3b983-7c53-4d45-abc6-bcd91e2dd90a_KMSHost2021Volume
  5447. 70512334-47b4-44db-a233-be5ea33b914c_KMSHost2019Volume
  5448. 98ebfe73-2084-4c97-932c-c0cd1643bea7_KMSHost2016Volume
  5449. 2e28138a-847f-42bc-9752-61b03fff33cd_KMSHost2013Volume
  5450. ) do (
  5451. for /f "tokens=1-2 delims=_" %%A in ("%%#") do (
  5452. echo "%ohostids%" | find /i "%%A" %nul1% && (
  5453. set ohostexist=1
  5454. set tsids=!tsids! %%A
  5455. echo Checking Activation ID [%%A] [%%B]
  5456. )
  5457. )
  5458. )
  5459. ​
  5460. if not defined ohostexist (
  5461. call :dk_color %Gray% "Checking Activation ID [Not found for Office %KS% Host]"
  5462. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%tsforge#office-kms-host"
  5463. )
  5464. ​
  5465. echo:
  5466. call :dk_color %Gray% "%KS% Host [Not to be confused with %KS% Client] license causes the sppsvc service to run continuously."
  5467. call :dk_color %Gray% "Only use this activation when necessary."
  5468. ​
  5469. goto :ts_act
  5470. ​
  5471. ::========================================================================================================================================
  5472. ​
  5473. :ts_appxlob
  5474. ​
  5475. :: Process Windows 8/8.1 APPX Sideloading
  5476. ​
  5477. echo:
  5478. echo Processing Windows 8/8.1 APPX Sideloading...
  5479. ​
  5480. if %winbuild% LSS 9200 set noappx=1
  5481. if %winbuild% GTR 9600 set noappx=1
  5482. ​
  5483. echo:
  5484. if defined noappx (
  5485. call :dk_color %Gray% "Checking Activation ID [APPX Sideloading feature is available only on Windows 8/8.1]"
  5486. goto :dk_done
  5487. )
  5488. ​
  5489. if /i %tsmethod%==KMS4k (
  5490. echo:
  5491. call :dk_color %Red% "Skipping Windows 8/8.1 APPX [KMS4k method is not supported with Windows 8/8.1 APPX]"
  5492. if /i %_actmethod%==Auto (
  5493. call :dk_color %Blue% "Connect to the Internet and try again. Script will use the StaticCID activation method."
  5494. ) else (
  5495. call :dk_color %Blue% "Use non-KMS4K activation options from the previous menu."
  5496. )
  5497. goto :dk_done
  5498. )
  5499. ​
  5500. set appxexist=
  5501. if not defined allapps call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  5502. ​
  5503. for %%# in (
  5504. ec67814b-30e6-4a50-bf7b-d55daf729d1e_APPXLOB-Client
  5505. 251ef9bf-2005-442f-94c4-86307de7bb32_APPXLOB-Embedded-Industry
  5506. 1e58c9d7-e3f1-4f69-9039-1f162463ac2c_APPXLOB-Embedded-Standard
  5507. 3502d53e-5d43-436a-84af-714e8d334f8d_APPXLOB-Server
  5508. ) do (
  5509. for /f "tokens=1-2 delims=_" %%A in ("%%#") do (
  5510. echo "%allapps%" | find /i "%%A" %nul1% && (
  5511. set appxexist=1
  5512. set tsids=!tsids! %%A
  5513. echo Checking Activation ID [%%A] [%%B]
  5514. )
  5515. )
  5516. )
  5517. ​
  5518. if not defined appxexist (
  5519. call :dk_color %Red% "Checking Activation ID [Not found]"
  5520. call :dk_color %Blue% "APPX Sideloading feature is available only on Pro and higher level editions."
  5521. )
  5522. ​
  5523. goto :ts_act
  5524. ​
  5525. ::========================================================================================================================================
  5526. ​
  5527. :ts_resetall
  5528. ​
  5529. echo:
  5530. if defined _vis (
  5531. echo Processing Reset of Rearm / Timers...
  5532. ) else (
  5533. echo Processing Reset of Rearm / Timers / Tamper / Lock...
  5534. )
  5535. echo:
  5536. ​
  5537. set resetstuff=1
  5538. %psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':tsforge\:.*';. ([scriptblock]::Create($f[1]))"
  5539. ​
  5540. if %errorlevel%==3 (
  5541. call :dk_color %Red% "Reset Failed."
  5542. set fixes=%fixes% %mas%troubleshoot
  5543. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  5544. ) else (
  5545. call :dk_color %Green% "Reset process has been successfully done."
  5546. )
  5547. ​
  5548. goto :dk_done
  5549. ​
  5550. ::========================================================================================================================================
  5551. ​
  5552. :ts_actman
  5553. ​
  5554. echo:
  5555. echo Processing Manual Activation...
  5556. echo:
  5557. ​
  5558. if /i %tsmethod%==KMS4k (
  5559. echo:
  5560. call :dk_color %Red% "Skipping Manual Activation [KMS4k method is not supported with it]"
  5561. if /i %_actmethod%==Auto (
  5562. call :dk_color %Blue% "Connect to the Internet and try again. Script will use the StaticCID activation method."
  5563. ) else (
  5564. call :dk_color %Blue% "Use non-KMS4K activation options from the previous menu."
  5565. )
  5566. goto :dk_done
  5567. )
  5568. ​
  5569. call :dk_color %Gray% "This option is for advanced users, those who already know what they are doing."
  5570. call :dk_color %Blue% "Some activation IDs may cause system crash [MUI mismatch], or irreversible changes [CloudEdition etc]."
  5571. ​
  5572. if %_unattended%==1 (
  5573. echo:
  5574. for %%# in (%tsids%) do (echo Activation ID - %%#)
  5575. goto :ts_act
  5576. )
  5577. ​
  5578. call :dk_color %Blue% "Although the script will try to remove those IDs from the list, it is not fully guaranteed."
  5579. echo:
  5580. choice /C:0F /N /M "> [0] Go back [F] Continue : "
  5581. if %errorlevel%==1 exit /b
  5582. ​
  5583. echo:
  5584. echo Fetching Supported Activation IDs list. Please wait...
  5585. ​
  5586. %psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':listactids\:.*';. ([scriptblock]::Create($f[1]))"
  5587. if %errorlevel%==3 (
  5588. call :dk_color %Gray% "No supported activation ID found, aborting..."
  5589. goto :dk_done
  5590. )
  5591. ​
  5592. for /f "delims=" %%a in ('%psc% "$ids = Get-WmiObject -Query 'SELECT ID FROM SoftwareLicensingProduct' | Select-Object -ExpandProperty ID; $ids" %nul6%') do call set "allactids= %%a !allactids! "
  5593. ​
  5594. if defined _vis (
  5595. echo:
  5596. call :dk_color %Blue% "On Windows Vista and Server 2008, you must manually install the key before activating it."
  5597. )
  5598. echo:
  5599. call :dk_color %Gray% "Enter / Paste the Activation ID shown in first column in the opened text file, or just press Enter to return:"
  5600. echo Add space after each Activation ID if you are adding multiple:
  5601. echo:
  5602. set /p tsids=
  5603. ​
  5604. del /f /q "%SystemRoot%\Temp\actids_159_*" %nul%
  5605. if not defined tsids goto :dk_done
  5606. ​
  5607. for %%# in (%tsids%) do (
  5608. echo "%allactids%" | find /i " %%# " %nul1% || (
  5609. call :dk_color %Red% "[%%#] Incorrect Activation ID entered, aborting..."
  5610. goto :dk_done
  5611. )
  5612. )
  5613. ​
  5614. goto :ts_act
  5615. ​
  5616. :listactids:
  5617. $t = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0)
  5618. $t.DefinePInvokeMethod('SLOpen', 'slc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  5619. $t.DefinePInvokeMethod('SLClose', 'slc.dll', 22, 1, [IntPtr], @([IntPtr]), 1, 3).SetImplementationFlags(128)
  5620. $t.DefinePInvokeMethod('SLGetProductSkuInformation', 'slc.dll', 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  5621. $t.DefinePInvokeMethod('SLGetLicense', 'slc.dll', 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  5622. $w = $t.CreateType()
  5623. $m = [Runtime.InteropServices.Marshal]
  5624. ​
  5625. function slGetSkuInfo($SkuId) {
  5626. $c = 0; $b = 0
  5627. $r = $w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, "msft:sl/EUL/PHONE/PUBLIC", [ref]$null, [ref]$c, [ref]$b)
  5628. return ($r -eq 0)
  5629. }
  5630. ​
  5631. function IsMuiNotLocked($SkuId) {
  5632. $r = $true; $c = 0; $b = 0
  5633. ​
  5634. $LicId = [Guid]::Empty
  5635. [void]$w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, "fileId", [ref]$null, [ref]$c, [ref]$b)
  5636. $FileId = $m::PtrToStringUni($b)
  5637. ​
  5638. $c = 0; $b = 0
  5639. [void]$w::SLGetLicense($hSLC, [ref][Guid]$FileId, [ref]$c, [ref]$b)
  5640. $blob = New-Object byte[] $c; $m::Copy($b, $blob, 0, $c)
  5641. $cont = [Text.Encoding]::UTF8.GetString($blob)
  5642. $xml = [xml]$cont.SubString($cont.IndexOf('<r'))
  5643. ​
  5644. $xml.licenseGroup.license[0].grant | foreach {
  5645. $_.allConditions.allConditions.productPolicies.policyStr | where { $_.name -eq 'Kernel-MUI-Language-Allowed' } | foreach {
  5646. if ($_.InnerText -ne 'EMPTY') { $r = $false }
  5647. }
  5648. }
  5649. return $r
  5650. }
  5651. ​
  5652. $hSLC = 0; [void]$w::SLOpen([ref]$hSLC)
  5653. $results = Get-WmiObject -Query "SELECT ID, Name, Description FROM SoftwareLicensingProduct"
  5654. $maxNameWidth = 60
  5655. ​
  5656. $filteredResults = $results | Where-Object {
  5657. if ($env:tsedition -like "*CountrySpecific*") {
  5658. $true
  5659. }
  5660. else {
  5661. $_.Name -like "*ESU*" -or $_.Name -notlike "*CountrySpecific*"
  5662. }
  5663. } | Where-Object {
  5664. if ($env:tsedition -like "*CloudEdition*") {
  5665. $true
  5666. }
  5667. else {
  5668. $_.Name -like "*ESU*" -or $_.Name -notlike "*CloudEdition*"
  5669. }
  5670. } | Where-Object {
  5671. $_.Name -like "*CountrySpecific*" -or (IsMuiNotLocked $_.ID)
  5672. } | Where-Object {
  5673. slGetSkuInfo $_.ID
  5674. } | ForEach-Object {
  5675. "$($_.ID)`t$($_.Name.PadRight($maxNameWidth))`t$($_.Description)"
  5676. }
  5677. ​
  5678. [void]$w::SLClose($hSLC)
  5679. if (-not $filteredResults) {
  5680. Exit 3
  5681. }
  5682. ​
  5683. $sortedResults = $filteredResults | Sort-Object { $_.Split("`t")[1].Trim() }
  5684. $output = $sortedResults -join "`r`n"
  5685. $newGuid = [Guid]::NewGuid().Guid
  5686. $filename = "$env:SystemRoot\Temp\actids_159_$newGuid.txt"
  5687. $output | Set-Content -Path $filename -Encoding ASCII
  5688. Start-Process notepad.exe $filename
  5689. :listactids:
  5690. ​
  5691. ::========================================================================================================================================
  5692. ​
  5693. :ts_act
  5694. ​
  5695. if defined eval (
  5696. echo:
  5697. echo Activating...
  5698. echo:
  5699. call :dk_act
  5700. ​
  5701. set gpr=0
  5702. set gprdays=0
  5703. set actdone=
  5704. for /f "delims=" %%a in ('%psc% "(Get-WmiObject -Query 'SELECT GracePeriodRemaining FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').GracePeriodRemaining" %nul6%') do set "gpr=%%a"
  5705. set /a "gprdays=(!gpr!+1440-1)/1440"
  5706. ​
  5707. if !gprdays! EQU 90 set actdone=1
  5708. if !gprdays! EQU 180 set actdone=1
  5709. ​
  5710. if defined actdone (
  5711. call :dk_color %Green% "[%winos%] has been reset and activated successfully for !gprdays! days."
  5712. ) else (
  5713. set error=1
  5714. set showfix=1
  5715. call :dk_color %Red% "[%winos%] Activation Failed %error_code%. Remaining Period: !gprdays! days [!gpr! minutes]."
  5716. if not defined noact (
  5717. call :dk_color %Gray% "To activate, check your internet connection and ensure the date and time are correct."
  5718. ) else (
  5719. call :dk_color %Blue% "This Windows version is known to not activate due to MS Windows/Server issues."
  5720. )
  5721. if not defined showfix call :dk_color %Blue% "%_fixmsg%"
  5722. set fixes=%fixes% %mas%troubleshoot
  5723. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  5724. )
  5725. )
  5726. ​
  5727. if defined tsids (
  5728. echo:
  5729. if not defined _vis if not defined oldks echo Installing Forged Product Key Data...
  5730. if /i %tsmethod%==KMS4k (
  5731. echo Writing TrustedStore data...
  5732. ) else (
  5733. if /i %tsmethod%==StaticCID (echo Depositing Static Confirmation ID...) else (echo Depositing Zero Confirmation ID...)
  5734. )
  5735. echo:
  5736. %psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':tsforge\:.*';. ([scriptblock]::Create($f[1])) %tsids%"
  5737. if !errorlevel!==3 (
  5738. if %_actman%==0 (if not defined showfix call :dk_color %Blue% "%_fixmsg%")
  5739. set fixes=%fixes% %mas%troubleshoot
  5740. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  5741. ) else (
  5742. if /i %tsmethod%==KMS4k if %winbuild% GEQ 26100 (
  5743. echo:
  5744. call :dk_color %Gray% "In Windows settings, you may see a renewal notification for activation that can be ignored."
  5745. if /i %_actmethod%==Auto call :dk_color %Gray% "To avoid this notification, run the script with an internet connection to use the StaticCID method."
  5746. )
  5747. echo "%tsids%" | find /i "7e94be23-b161-4956-a682-146ab291774c" %nul1% && (
  5748. call :dk_color %Gray% "Windows Update gets 1-3 years of ESU; 4-6 are unofficial but let you install Server 2008 R2 updates manually."
  5749. )
  5750. echo "%tsids%" | findstr /i "4afc620f-12a4-48ad-8015-2aebfbd6e47c 11be7019-a309-4763-9a09-091d1722ffe3" %nul1% && (
  5751. call :dk_color %Gray% "ESU is not officially supported on Windows 8.1, but updates can be installed manually until January 2024."
  5752. )
  5753. echo "%tsids%" | findstr /i "83d49986-add3-41d7-ba33-87c7bfb5c0fb 0b533b5e-08b6-44f9-b885-c2de291ba456" %nul1% && (
  5754. call :dk_color %Gray% "Windows Update gets 1-3 years of ESU; 4-6 are unofficial but may let you install LTSC updates manually."
  5755. if exist %SysPath%\ClipESUConsumer.exe (%SysPath%\ClipESUConsumer.exe -evaluateEligibility)
  5756. if exist %SysPath%\ClipESU.exe (%SysPath%\ClipESU.exe %nul%)
  5757. )
  5758. )
  5759. ​
  5760. if defined esuexistsup echo Help: %mas%tsforge#windows-esu
  5761. ​
  5762. if %_actwin%==1 for %%# in (407) do if %osSKU%==%%# (
  5763. call :dk_color %Red% "%winos% does not support activation on non-azure platforms."
  5764. )
  5765. ​
  5766. if %_actoff%==1 if not defined error if defined ohub (
  5767. echo:
  5768. call :dk_color %Gray% "Office apps such as Word, Excel are activated, use them directly. Ignore 'Buy' button in Office dashboard app."
  5769. )
  5770. ​
  5771. REM Trigger reevaluation of SPP's Scheduled Tasks
  5772. call :dk_reeval %nul%
  5773. )
  5774. ​
  5775. if not defined tsids if defined error if not defined showfix (
  5776. set fixes=%fixes% %mas%troubleshoot
  5777. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  5778. )
  5779. ​
  5780. goto :dk_done
  5781. ​
  5782. ::========================================================================================================================================
  5783. ​
  5784. :ts_remove
  5785. ​
  5786. cls
  5787. if not defined terminal (
  5788. mode 100, 30
  5789. )
  5790. title Remove TSforge Activation %masver%
  5791. ​
  5792. echo:
  5793. echo TSforge activation doesn't modify any Windows components and doesn't install any new files.
  5794. echo:
  5795. echo Instead, it appends data to one of data files used by Software Protection Platform.
  5796. echo:
  5797. call :dk_color %Gray% "If you want to reset the activation status,"
  5798. call :dk_color %Blue% "%_fixmsg%"
  5799. echo:
  5800. ​
  5801. goto :dk_done
  5802. ​
  5803. ::========================================================================================================================================
  5804. ​
  5805. :ts_reset
  5806. ​
  5807. set key=
  5808. set _oRoot=
  5809. set _oArch=
  5810. set _oIds=
  5811. set _oLPath=
  5812. set _actid=
  5813. set _prod=
  5814. set _lic=
  5815. set _arr=
  5816. set _prids=
  5817. set _config=
  5818. set _version=
  5819. set _License=
  5820. set _oMSI=
  5821. exit /b
  5822. ​
  5823. ::========================================================================================================================================
  5824. ​
  5825. :ts_getpath
  5826. ​
  5827. set o16c2r=
  5828. set o15c2r=
  5829. set o16msi=
  5830. set o15msi=
  5831. ​
  5832. set _68=HKLM\SOFTWARE\Microsoft\Office
  5833. set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office
  5834. ​
  5835. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\ClickToRun /v InstallPath" %nul6%') do if exist "%%b\root\Licenses16\ProPlus*.xrm-ms" (set o16c2r=1&set o16c2r_reg=%_86%\ClickToRun)
  5836. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\ClickToRun /v InstallPath" %nul6%') do if exist "%%b\root\Licenses16\ProPlus*.xrm-ms" (set o16c2r=1&set o16c2r_reg=%_68%\ClickToRun)
  5837. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\15.0\ClickToRun /v InstallPath" %nul6%') do if exist "%%b\root\Licenses\ProPlus*.xrm-ms" (set o15c2r=1&set o15c2r_reg=%_86%\15.0\ClickToRun)
  5838. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\15.0\ClickToRun /v InstallPath" %nul6%') do if exist "%%b\root\Licenses\ProPlus*.xrm-ms" (set o15c2r=1&set o15c2r_reg=%_68%\15.0\ClickToRun)
  5839. ​
  5840. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set o16msi=1&set o16msi_reg=%_86%\16.0)
  5841. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set o16msi=1&set o16msi_reg=%_68%\16.0)
  5842. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set o15msi=1&set o15msi_reg=%_86%\15.0)
  5843. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set o15msi=1&set o15msi_reg=%_68%\15.0)
  5844. ​
  5845. exit /b
  5846. ​
  5847. ::========================================================================================================================================
  5848. ​
  5849. :ts_process
  5850. ​
  5851. if not exist "%pkeypath%" (
  5852. call :dk_color %Red% "Checking pkeyconfig-office.xrm-ms [Not found. Aborting activation...]"
  5853. set error=1
  5854. exit /b
  5855. )
  5856. ​
  5857. for %%# in (%_oIds%) do (
  5858. set _actid=
  5859. set _preview=
  5860. set _License=%%#
  5861. ​
  5862. set skipprocess=
  5863. ​
  5864. set foundprod=
  5865. call :tsksdata chkprod %%#
  5866. if defined _oMSI if not defined foundprod if /i %tsmethod%==KMS4k (
  5867. set skipprocess=1
  5868. call :dk_color %Red% "Checking Product In Script [%%# MSI Retail is not supported with KMS4k]"
  5869. if /i %_actmethod%==Auto (
  5870. call :dk_color %Blue% "Connect to the Internet and try again. Script will use the StaticCID activation method."
  5871. ) else (
  5872. call :dk_color %Blue% "Use non-KMS4K activation options from the previous menu."
  5873. )
  5874. )
  5875. ​
  5876. if "%_actprojvis%"=="1" (
  5877. echo %%# | findstr /i "Project Visio" %nul% || (
  5878. set skipprocess=1
  5879. call :dk_color %Gray% "Skipping Because Project/Visio Mode [%%#]"
  5880. )
  5881. )
  5882. ​
  5883. if "%_actprojvis%"=="0" if /i %tsmethod%==KMS4k echo %_oIds% | findstr /i "O365" %nul% && (
  5884. echo %%# | findstr /i "Project Visio" %nul% && (
  5885. set skipprocess=1
  5886. echo Skipping Because Mondo Is Available [%%#]
  5887. )
  5888. )
  5889. ​
  5890. ​
  5891. if not defined skipprocess (
  5892. ​
  5893. if /i not %tsmethod%==KMS4k (
  5894. set no365=
  5895. if "%oVer%"=="15" (echo %%# | findstr /i "O365HomePremRetail" %nul% && set no365=1)
  5896. if "%oVer%"=="16" (echo %%# | findstr /i "O365" %nul% && set no365=1)
  5897. ​
  5898. if defined no365 (
  5899. set _License=MondoRetail
  5900. set _altoffid=MondoRetail
  5901. call :ks_osppready
  5902. echo Converting Unsupported O365 Office [%%# To MondoRetail]
  5903. if "%oVer%"=="15" (call :dk_color %Gray% "Mondo 2013 is equivalent to O365 [15.0 version] in terms of the latest features.")
  5904. if "%oVer%"=="16" (call :dk_color %Gray% "Mondo 2016 is equivalent to O365 in terms of the latest features.")
  5905. )
  5906. ​
  5907. if not defined _oMSI (
  5908. echo %%# | findstr /i "ARM" %nul% && (
  5909. set _License=MondoRetail
  5910. set _altoffid=MondoRetail
  5911. call :ks_osppready
  5912. echo Converting Unsupported OEM-ARM Office [%%# To MondoRetail]
  5913. )
  5914. )
  5915. )
  5916. ​
  5917. if not defined _oMSI if /i %tsmethod%==KMS4k if not defined foundprod (
  5918. call :tsksdata getinfo %%#
  5919. if defined _altoffid (
  5920. echo Converting Retail To Volume [%%# To !_altoffid!]
  5921. ) else (
  5922. set _License=MondoVolume
  5923. set _altoffid=MondoVolume
  5924. echo Converting Retail To Volume [%%# To !_altoffid!] [Using Mondo because %%# is not found in the script]
  5925. )
  5926. echo %%# | find /i "O365" %nul% && (
  5927. if "%oVer%"=="15" (call :dk_color %Gray% "Mondo 2013 is equivalent to O365 [15.0 version] in terms of the latest features.")
  5928. if "%oVer%"=="16" (call :dk_color %Gray% "Mondo 2016 is equivalent to O365 in terms of the latest features.")
  5929. )
  5930. call :ks_osppready
  5931. )
  5932. ​
  5933. if /i %tsmethod%==KMS4k (
  5934. echo !_License! | find /i "Retail" %nul% && (set keytype=zero) || (set keytype=ks)
  5935. ) else (
  5936. set keytype=zero
  5937. )
  5938. ​
  5939. for /f "delims=" %%a in ('%psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':offtsid\:.*';. ([scriptblock]::Create($f[1]))" %nul6%') do (
  5940. echo "%%a" | findstr /r ".*-.*-.*-.*-.*" %nul1% && (set tsids=!tsids! %%a& set _actid=%%a)
  5941. )
  5942. set "_allactid=!tsids!"
  5943. ​
  5944. if defined _actid (
  5945. echo Checking Activation ID [!_actid!] [!_License!]
  5946. ) else (
  5947. call :dk_color %Red% "Checking Activation ID [Office %oVer%.0 !_License! not found]"
  5948. set error=1
  5949. set showfix=1
  5950. set fixes=%fixes% %mas%troubleshoot
  5951. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  5952. )
  5953. ​
  5954. echo %%# | find /i "2024" %nul% && (
  5955. if exist "!_oLPath!\ProPlus2024PreviewVL_*.xrm-ms" if not exist "!_oLPath!\ProPlus2024VL_*.xrm-ms" set _preview=1
  5956. )
  5957. ​
  5958. if defined _actid (
  5959. echo "!allapps!" | find /i "!_actid!" %nul1% || call :oh_installlic
  5960. )
  5961. )
  5962. )
  5963. ​
  5964. :: Add SharedComputerLicensing registry key if Retail Office C2R is installed on Windows Server
  5965. :: https://learn.microsoft.com/en-us/office/troubleshoot/office-suite-issues/click-to-run-office-on-terminal-server
  5966. ​
  5967. if /i not %tsmethod%==KMS4k if defined winserver if defined _config if exist "%_oLPath%\Word2019VL_KMS_Client_AE*.xrm-ms" (
  5968. echo %_oIds% | find /i "Retail" %nul1% && (
  5969. set scaIsNeeded=1
  5970. reg add %_config% /v SharedComputerLicensing /t REG_SZ /d "1" /f %nul1%
  5971. echo Adding SharedComputerLicensing Reg [Successful] [Needed on Server With Retail Office]"
  5972. )
  5973. )
  5974. ​
  5975. exit /b
  5976. ​
  5977. ::========================================================================================================================================
  5978. ​
  5979. :ts_processmsi
  5980. ​
  5981. :: Process Office MSI Version
  5982. ​
  5983. call :ts_reset
  5984. call :dk_actids 0ff1ce15-a989-479d-af46-f275c6370663
  5985. ​
  5986. set _oMSI=1
  5987. set oVer=%1
  5988. for /f "skip=2 tokens=2*" %%a in ('"reg query %2\Common\InstallRoot /v Path" %nul6%') do (set "_oRoot=%%b")
  5989. for /f "skip=2 tokens=2*" %%a in ('"reg query %2\Common\ProductVersion /v LastProduct" %nul6%') do (set "_version=%%b")
  5990. if "%_oRoot:~-1%"=="\" set "_oRoot=%_oRoot:~0,-1%"
  5991. ​
  5992. echo "%2" | find /i "Wow6432Node" %nul1% && set _oArch=x86
  5993. if not "%osarch%"=="x86" if not defined _oArch set _oArch=x64
  5994. if "%osarch%"=="x86" set _oArch=x86
  5995. ​
  5996. set "_common=%CommonProgramFiles%"
  5997. if defined PROCESSOR_ARCHITEW6432 set "_common=%CommonProgramW6432%"
  5998. set "_common2=%CommonProgramFiles(x86)%"
  5999. ​
  6000. if exist "%_common%\Microsoft Shared\OFFICE%oVer%\Office Setup Controller\pkeyconfig-office.xrm-ms" (
  6001. set "pkeypath=%_common%\Microsoft Shared\OFFICE%oVer%\Office Setup Controller\pkeyconfig-office.xrm-ms"
  6002. ) else if exist "%_common2%\Microsoft Shared\OFFICE%oVer%\Office Setup Controller\pkeyconfig-office.xrm-ms" (
  6003. set "pkeypath=%_common2%\Microsoft Shared\OFFICE%oVer%\Office Setup Controller\pkeyconfig-office.xrm-ms"
  6004. )
  6005. ​
  6006. call :msiofficedata %2
  6007. ​
  6008. echo:
  6009. echo Processing Office... [MSI ^| %_version% ^| %_oArch%]
  6010. ​
  6011. if not defined _oIds (
  6012. set error=1
  6013. call :dk_color %Red% "Checking Installed Products [Product IDs not found. Aborting activation...]"
  6014. exit /b
  6015. )
  6016. ​
  6017. call :ts_process
  6018. exit /b
  6019. ​
  6020. ::========================================================================================================================================
  6021. ​
  6022. :: Get Windows permanent activation status (not counting csvlk)
  6023. ​
  6024. :ts_checkwinperm
  6025. ​
  6026. %psc% "Get-WmiObject -Query 'SELECT Name, Description FROM SoftwareLicensingProduct WHERE LicenseStatus=''1'' AND GracePeriodRemaining=''0'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn IS NULL' | Where-Object { $_.Description -notmatch 'KMS' } | Select-Object -Property Name" %nul2% | findstr /i "Windows" %nul1% && set _perm=1||set _perm=
  6027. exit /b
  6028. ​
  6029. ::========================================================================================================================================
  6030. ​
  6031. :tsforge:
  6032. $src = @'
  6033. #if !POWERSHELL2
  6034. namespace ActivationWs
  6035. {
  6036. ​
  6037. /*
  6038. ​
  6039. This code is adapted from ActivationWs.
  6040. Original Repository: https://github.com/dadorner-msft/activationws
  6041. ​
  6042. MIT License
  6043. ​
  6044. Copyright (c) Daniel Dorner
  6045. ​
  6046. Permission is hereby granted, free of charge, to any person obtaining a copy
  6047. of this software and associated documentation files (the "Software"), to deal
  6048. in the Software without restriction, including without limitation the rights
  6049. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  6050. copies of the Software, and to permit persons to whom the Software is
  6051. furnished to do so, subject to the following conditions:
  6052. ​
  6053. The above copyright notice and this permission notice shall be included in all
  6054. copies or substantial portions of the Software.
  6055. ​
  6056. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  6057. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  6058. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  6059. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  6060. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  6061. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  6062. SOFTWARE.
  6063. ​
  6064. */
  6065. ​
  6066. using System;
  6067. using System.IO;
  6068. using System.Linq;
  6069. using System.Net;
  6070. using System.Security.Cryptography;
  6071. using System.Text;
  6072. using System.Xml.Linq;
  6073. ​
  6074. public static class ActivationHelper {
  6075. // Key for HMAC/SHA256 signature.
  6076. private static readonly byte[] MacKey = new byte[64] {
  6077. 254, 49, 152, 117, 251, 72, 132, 134,
  6078. 156, 243, 241, 206, 153, 168, 144, 100,
  6079. 171, 87, 31, 202, 71, 4, 80, 88,
  6080. 48, 36, 226, 20, 98, 135, 121, 160,
  6081. 0, 0, 0, 0, 0, 0, 0, 0,
  6082. 0, 0, 0, 0, 0, 0, 0, 0,
  6083. 0, 0, 0, 0, 0, 0, 0, 0,
  6084. 0, 0, 0, 0, 0, 0, 0, 0
  6085. };
  6086. ​
  6087. private const string Action = "http://www.microsoft.com/BatchActivationService/BatchActivate";
  6088. ​
  6089. private static readonly Uri Uri = new Uri("https://activation.sls.microsoft.com/BatchActivation/BatchActivation.asmx");
  6090. ​
  6091. private static readonly XNamespace SoapSchemaNs = "http://schemas.xmlsoap.org/soap/envelope/";
  6092. private static readonly XNamespace XmlSchemaInstanceNs = "http://www.w3.org/2001/XMLSchema-instance";
  6093. private static readonly XNamespace XmlSchemaNs = "http://www.w3.org/2001/XMLSchema";
  6094. private static readonly XNamespace BatchActivationServiceNs = "http://www.microsoft.com/BatchActivationService";
  6095. private static readonly XNamespace BatchActivationRequestNs = "http://www.microsoft.com/DRM/SL/BatchActivationRequest/1.0";
  6096. private static readonly XNamespace BatchActivationResponseNs = "http://www.microsoft.com/DRM/SL/BatchActivationResponse/1.0";
  6097. ​
  6098. public static string CallWebService(int requestType, string installationId, string extendedProductId) {
  6099. XDocument soapRequest = CreateSoapRequest(requestType, installationId, extendedProductId);
  6100. HttpWebRequest webRequest = CreateWebRequest(soapRequest);
  6101. XDocument soapResponse = new XDocument();
  6102. ​
  6103. try {
  6104. IAsyncResult asyncResult = webRequest.BeginGetResponse(null, null);
  6105. asyncResult.AsyncWaitHandle.WaitOne();
  6106. ​
  6107. // Read data from the response stream.
  6108. using (WebResponse webResponse = webRequest.EndGetResponse(asyncResult))
  6109. using (StreamReader streamReader = new StreamReader(webResponse.GetResponseStream())) {
  6110. soapResponse = XDocument.Parse(streamReader.ReadToEnd());
  6111. }
  6112. ​
  6113. return ParseSoapResponse(soapResponse);
  6114. ​
  6115. } catch {
  6116. throw;
  6117. }
  6118. }
  6119. ​
  6120. private static XDocument CreateSoapRequest(int requestType, string installationId, string extendedProductId) {
  6121. // Create an activation request.
  6122. XElement activationRequest = new XElement(BatchActivationRequestNs + "ActivationRequest",
  6123. new XElement(BatchActivationRequestNs + "VersionNumber", "2.0"),
  6124. new XElement(BatchActivationRequestNs + "RequestType", requestType),
  6125. new XElement(BatchActivationRequestNs + "Requests",
  6126. new XElement(BatchActivationRequestNs + "Request",
  6127. new XElement(BatchActivationRequestNs + "PID", extendedProductId),
  6128. requestType == 1 ? new XElement(BatchActivationRequestNs + "IID", installationId) : null)
  6129. )
  6130. );
  6131. ​
  6132. // Get the unicode byte array of activationRequest and convert it to Base64.
  6133. byte[] bytes = Encoding.Unicode.GetBytes(activationRequest.ToString());
  6134. string requestXml = Convert.ToBase64String(bytes);
  6135. ​
  6136. XDocument soapRequest = new XDocument();
  6137. ​
  6138. using (HMACSHA256 hMACSHA = new HMACSHA256(MacKey)) {
  6139. // Convert the HMAC hashed data to Base64.
  6140. string digest = Convert.ToBase64String(hMACSHA.ComputeHash(bytes));
  6141. ​
  6142. soapRequest = new XDocument(
  6143. new XDeclaration("1.0", "UTF-8", "no"),
  6144. new XElement(SoapSchemaNs + "Envelope",
  6145. new XAttribute(XNamespace.Xmlns + "soap", SoapSchemaNs),
  6146. new XAttribute(XNamespace.Xmlns + "xsi", XmlSchemaInstanceNs),
  6147. new XAttribute(XNamespace.Xmlns + "xsd", XmlSchemaNs),
  6148. new XElement(SoapSchemaNs + "Body",
  6149. new XElement(BatchActivationServiceNs + "BatchActivate",
  6150. new XElement(BatchActivationServiceNs + "request",
  6151. new XElement(BatchActivationServiceNs + "Digest", digest),
  6152. new XElement(BatchActivationServiceNs + "RequestXml", requestXml)
  6153. )
  6154. )
  6155. )
  6156. ));
  6157. ​
  6158. }
  6159. ​
  6160. return soapRequest;
  6161. }
  6162. ​
  6163. private static HttpWebRequest CreateWebRequest(XDocument soapRequest) {
  6164. HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(Uri);
  6165. webRequest.Accept = "text/xml";
  6166. webRequest.ContentType = "text/xml; charset=\"utf-8\"";
  6167. webRequest.Headers.Add("SOAPAction", Action);
  6168. webRequest.Host = "activation.sls.microsoft.com";
  6169. webRequest.Method = "POST";
  6170. ​
  6171. try {
  6172. // Insert SOAP envelope
  6173. using (Stream stream = webRequest.GetRequestStream()) {
  6174. soapRequest.Save(stream);
  6175. }
  6176. ​
  6177. return webRequest;
  6178. ​
  6179. } catch {
  6180. throw;
  6181. }
  6182. }
  6183. ​
  6184. private static string ParseSoapResponse(XDocument soapResponse) {
  6185. if (soapResponse == null) {
  6186. throw new ArgumentNullException("soapResponse", "The remote server returned an unexpected response.");
  6187. }
  6188. ​
  6189. if (!soapResponse.Descendants(BatchActivationServiceNs + "ResponseXml").Any()) {
  6190. throw new Exception("The remote server returned an unexpected response");
  6191. }
  6192. ​
  6193. try {
  6194. XDocument responseXml = XDocument.Parse(soapResponse.Descendants(BatchActivationServiceNs + "ResponseXml").First().Value);
  6195. ​
  6196. if (responseXml.Descendants(BatchActivationResponseNs + "ErrorCode").Any()) {
  6197. string errorCode = responseXml.Descendants(BatchActivationResponseNs + "ErrorCode").First().Value;
  6198. ​
  6199. switch (errorCode) {
  6200. case "0x7F":
  6201. throw new Exception("The Multiple Activation Key has exceeded its limit");
  6202. ​
  6203. case "0x67":
  6204. throw new Exception("The product key has been blocked");
  6205. ​
  6206. case "0x68":
  6207. throw new Exception("Invalid product key");
  6208. ​
  6209. case "0x86":
  6210. throw new Exception("Invalid key type");
  6211. ​
  6212. case "0x90":
  6213. throw new Exception("Please check the Installation ID and try again");
  6214. ​
  6215. default:
  6216. throw new Exception(string.Format("The remote server reported an error ({0})", errorCode));
  6217. }
  6218. ​
  6219. } else if (responseXml.Descendants(BatchActivationResponseNs + "ResponseType").Any()) {
  6220. string responseType = responseXml.Descendants(BatchActivationResponseNs + "ResponseType").First().Value;
  6221. ​
  6222. switch (responseType) {
  6223. case "1":
  6224. string confirmationId = responseXml.Descendants(BatchActivationResponseNs + "CID").First().Value;
  6225. return confirmationId;
  6226. ​
  6227. case "2":
  6228. string activationsRemaining = responseXml.Descendants(BatchActivationResponseNs + "ActivationRemaining").First().Value;
  6229. return activationsRemaining;
  6230. ​
  6231. default:
  6232. throw new Exception("The remote server returned an unrecognized response");
  6233. }
  6234. ​
  6235. } else {
  6236. throw new Exception("The remote server returned an unrecognized response");
  6237. }
  6238. ​
  6239. } catch {
  6240. throw;
  6241. }
  6242. }
  6243. }
  6244. }
  6245. #endif
  6246. ​
  6247. // LibTSforge/Common.cs
  6248. namespace LibTSforge
  6249. {
  6250. using System;
  6251. using System.IO;
  6252. using System.Linq;
  6253. using System.Runtime.InteropServices;
  6254. using System.Text;
  6255. ​
  6256. public enum PSVersion
  6257. {
  6258. Vista,
  6259. Win7,
  6260. Win8,
  6261. WinBlue,
  6262. WinModern
  6263. }
  6264. ​
  6265. public static class Constants
  6266. {
  6267. public static readonly byte[] UniversalHWIDBlock =
  6268. {
  6269. 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00,
  6270. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  6271. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  6272. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  6273. 0x00, 0x00, 0x01, 0x0c, 0x01, 0x00
  6274. };
  6275. ​
  6276. public static readonly byte[] KMSv4Response =
  6277. {
  6278. 0x00, 0x00, 0x04, 0x00, 0x62, 0x00, 0x00, 0x00, 0x30, 0x00, 0x35, 0x00, 0x34, 0x00, 0x32, 0x00,
  6279. 0x36, 0x00, 0x2D, 0x00, 0x30, 0x00, 0x30, 0x00, 0x32, 0x00, 0x30, 0x00, 0x36, 0x00, 0x2D, 0x00,
  6280. 0x31, 0x00, 0x36, 0x00, 0x31, 0x00, 0x2D, 0x00, 0x36, 0x00, 0x35, 0x00, 0x35, 0x00, 0x35, 0x00,
  6281. 0x30, 0x00, 0x36, 0x00, 0x2D, 0x00, 0x30, 0x00, 0x33, 0x00, 0x2D, 0x00, 0x31, 0x00, 0x30, 0x00,
  6282. 0x33, 0x00, 0x33, 0x00, 0x2D, 0x00, 0x39, 0x00, 0x32, 0x00, 0x30, 0x00, 0x30, 0x00, 0x2E, 0x00,
  6283. 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x30, 0x00, 0x2D, 0x00, 0x30, 0x00, 0x36, 0x00, 0x35, 0x00,
  6284. 0x32, 0x00, 0x30, 0x00, 0x31, 0x00, 0x33, 0x00, 0x00, 0x00, 0xDE, 0x19, 0x02, 0xCF, 0x1F, 0x35,
  6285. 0x97, 0x4E, 0x8A, 0x8F, 0xB8, 0x07, 0xB1, 0x92, 0xB5, 0xB5, 0x97, 0x42, 0xEC, 0x3A, 0x76, 0x84,
  6286. 0xD5, 0x01, 0x32, 0x00, 0x00, 0x00, 0x78, 0x00, 0x00, 0x00, 0x60, 0x27, 0x00, 0x00, 0xC4, 0x1E,
  6287. 0xAA, 0x8B, 0xDD, 0x0C, 0xAB, 0x55, 0x6A, 0xCE, 0xAF, 0xAC, 0x7F, 0x5F, 0xBD, 0xE9
  6288. };
  6289. ​
  6290. public static readonly byte[] KMSv5Response =
  6291. {
  6292. 0x00, 0x00, 0x05, 0x00, 0xBE, 0x96, 0xF9, 0x04, 0x54, 0x17, 0x3F, 0xAF, 0xE3, 0x08, 0x50, 0xEB,
  6293. 0x22, 0xBA, 0x53, 0xBF, 0xF2, 0x6A, 0x7B, 0xC9, 0x05, 0x1D, 0xB5, 0x19, 0xDF, 0x98, 0xE2, 0x71,
  6294. 0x4D, 0x00, 0x61, 0xE9, 0x9D, 0x03, 0xFB, 0x31, 0xF9, 0x1F, 0x2E, 0x60, 0x59, 0xC7, 0x73, 0xC8,
  6295. 0xE8, 0xB6, 0xE1, 0x2B, 0x39, 0xC6, 0x35, 0x0E, 0x68, 0x7A, 0xAA, 0x4F, 0x28, 0x23, 0x12, 0x18,
  6296. 0xE3, 0xAA, 0x84, 0x81, 0x6E, 0x82, 0xF0, 0x3F, 0xD9, 0x69, 0xA9, 0xDF, 0xBA, 0x5F, 0xCA, 0x32,
  6297. 0x54, 0xB2, 0x52, 0x3B, 0x3E, 0xD1, 0x5C, 0x65, 0xBC, 0x3E, 0x59, 0x0D, 0x15, 0x9F, 0x37, 0xEC,
  6298. 0x30, 0x9C, 0xCC, 0x1B, 0x39, 0x0D, 0x21, 0x32, 0x29, 0xA2, 0xDD, 0xC7, 0xC1, 0x69, 0xF2, 0x72,
  6299. 0x3F, 0x00, 0x98, 0x1E, 0xF8, 0x9A, 0x79, 0x44, 0x5D, 0x25, 0x80, 0x7B, 0xF5, 0xE1, 0x7C, 0x68,
  6300. 0x25, 0xAA, 0x0D, 0x67, 0x98, 0xE5, 0x59, 0x9B, 0x04, 0xC1, 0x23, 0x33, 0x48, 0xFB, 0x28, 0xD0,
  6301. 0x76, 0xDF, 0x01, 0x56, 0xE7, 0xEC, 0xBF, 0x1A, 0xA2, 0x22, 0x28, 0xCA, 0xB1, 0xB4, 0x4C, 0x30,
  6302. 0x14, 0x6F, 0xD2, 0x2E, 0x01, 0x2A, 0x04, 0xE3, 0xBD, 0xA7, 0x41, 0x2F, 0xC9, 0xEF, 0x53, 0xC0,
  6303. 0x70, 0x48, 0xF1, 0xB2, 0xB6, 0xEA, 0xE7, 0x0F, 0x7A, 0x15, 0xD1, 0xA6, 0xFE, 0x23, 0xC8, 0xF3,
  6304. 0xE1, 0x02, 0x9E, 0xA0, 0x4E, 0xBD, 0xF5, 0xEA, 0x53, 0x74, 0x8E, 0x74, 0xA1, 0xA1, 0xBD, 0xBE,
  6305. 0x66, 0xC4, 0x73, 0x8F, 0x24, 0xA7, 0x2A, 0x2F, 0xE3, 0xD9, 0xF4, 0x28, 0xD9, 0xF8, 0xA3, 0x93,
  6306. 0x03, 0x9E, 0x29, 0xAB
  6307. };
  6308. ​
  6309. public static readonly byte[] KMSv6Response =
  6310. {
  6311. 0x00, 0x00, 0x06, 0x00, 0x54, 0xD3, 0x40, 0x08, 0xF3, 0xCD, 0x03, 0xEF, 0xC8, 0x15, 0x87, 0x9E,
  6312. 0xCA, 0x2E, 0x85, 0xFB, 0xE6, 0xF6, 0x73, 0x66, 0xFB, 0xDA, 0xBB, 0x7B, 0xB1, 0xBC, 0xD6, 0xF9,
  6313. 0x5C, 0x41, 0xA0, 0xFE, 0xE1, 0x74, 0xC4, 0xBB, 0x91, 0xE5, 0xDE, 0x6D, 0x3A, 0x11, 0xD5, 0xFC,
  6314. 0x68, 0xC0, 0x7B, 0x82, 0xB2, 0x24, 0xD1, 0x85, 0xBA, 0x45, 0xBF, 0xF1, 0x26, 0xFA, 0xA5, 0xC6,
  6315. 0x61, 0x70, 0x69, 0x69, 0x6E, 0x0F, 0x0B, 0x60, 0xB7, 0x3D, 0xE8, 0xF1, 0x47, 0x0B, 0x65, 0xFD,
  6316. 0xA7, 0x30, 0x1E, 0xF6, 0xA4, 0xD0, 0x79, 0xC4, 0x58, 0x8D, 0x81, 0xFD, 0xA7, 0xE7, 0x53, 0xF1,
  6317. 0x67, 0x78, 0xF0, 0x0F, 0x60, 0x8F, 0xC8, 0x16, 0x35, 0x22, 0x94, 0x48, 0xCB, 0x0F, 0x8E, 0xB2,
  6318. 0x1D, 0xF7, 0x3E, 0x28, 0x42, 0x55, 0x6B, 0x07, 0xE3, 0xE8, 0x51, 0xD5, 0xFA, 0x22, 0x0C, 0x86,
  6319. 0x65, 0x0D, 0x3F, 0xDD, 0x8D, 0x9B, 0x1B, 0xC9, 0xD3, 0xB8, 0x3A, 0xEC, 0xF1, 0x11, 0x19, 0x25,
  6320. 0xF7, 0x84, 0x4A, 0x4C, 0x0A, 0xB5, 0x31, 0x94, 0x37, 0x76, 0xCE, 0xE7, 0xAB, 0xA9, 0x69, 0xDF,
  6321. 0xA4, 0xC9, 0x22, 0x6C, 0x23, 0xFF, 0x6B, 0xFC, 0xDA, 0x78, 0xD8, 0xC4, 0x8F, 0x74, 0xBB, 0x26,
  6322. 0x05, 0x00, 0x98, 0x9B, 0xE5, 0xE2, 0xAD, 0x0D, 0x57, 0x95, 0x80, 0x66, 0x8E, 0x43, 0x74, 0x87,
  6323. 0x93, 0x1F, 0xF4, 0xB2, 0x2C, 0x20, 0x5F, 0xD8, 0x9C, 0x4C, 0x56, 0xB3, 0x57, 0x44, 0x62, 0x68,
  6324. 0x8D, 0xAA, 0x40, 0x11, 0x9D, 0x84, 0x62, 0x0E, 0x43, 0x8A, 0x1D, 0xF0, 0x1C, 0x49, 0xD8, 0x56,
  6325. 0xEF, 0x4C, 0xD3, 0x64, 0xBA, 0x0D, 0xEF, 0x87, 0xB5, 0x2C, 0x88, 0xF3, 0x18, 0xFF, 0x3A, 0x8C,
  6326. 0xF5, 0xA6, 0x78, 0x5C, 0x62, 0xE3, 0x9E, 0x4C, 0xB6, 0x31, 0x2D, 0x06, 0x80, 0x92, 0xBC, 0x2E,
  6327. 0x92, 0xA6, 0x56, 0x96
  6328. };
  6329. ​
  6330. // 2^31 - 8 minutes
  6331. public static readonly ulong TimerMax = (ulong)TimeSpan.FromMinutes(2147483640).Ticks;
  6332. ​
  6333. public static readonly string ZeroCID = new string('0', 48);
  6334. }
  6335. ​
  6336. public static class BinaryReaderExt
  6337. {
  6338. public static void Align(this BinaryReader reader, int to)
  6339. {
  6340. int pos = (int)reader.BaseStream.Position;
  6341. reader.BaseStream.Seek(-pos & (to - 1), SeekOrigin.Current);
  6342. }
  6343. ​
  6344. public static string ReadNullTerminatedString(this BinaryReader reader, int maxLen)
  6345. {
  6346. return Encoding.Unicode.GetString(reader.ReadBytes(maxLen)).Split(new char[] { '\0' }, 2)[0];
  6347. }
  6348. }
  6349. ​
  6350. public static class BinaryWriterExt
  6351. {
  6352. public static void Align(this BinaryWriter writer, int to)
  6353. {
  6354. int pos = (int)writer.BaseStream.Position;
  6355. writer.WritePadding(-pos & (to - 1));
  6356. }
  6357. ​
  6358. public static void WritePadding(this BinaryWriter writer, int len)
  6359. {
  6360. writer.Write(Enumerable.Repeat((byte)0, len).ToArray());
  6361. }
  6362. ​
  6363. public static void WriteFixedString(this BinaryWriter writer, string str, int bLen)
  6364. {
  6365. writer.Write(Encoding.ASCII.GetBytes(str));
  6366. writer.WritePadding(bLen - str.Length);
  6367. }
  6368. ​
  6369. public static void WriteFixedString16(this BinaryWriter writer, string str, int bLen)
  6370. {
  6371. byte[] bstr = Utils.EncodeString(str);
  6372. writer.Write(bstr);
  6373. writer.WritePadding(bLen - bstr.Length);
  6374. }
  6375. ​
  6376. public static byte[] GetBytes(this BinaryWriter writer)
  6377. {
  6378. return ((MemoryStream)writer.BaseStream).ToArray();
  6379. }
  6380. }
  6381. ​
  6382. public static class ByteArrayExt
  6383. {
  6384. public static byte[] CastToArray<T>(this T data) where T : struct
  6385. {
  6386. int size = Marshal.SizeOf(typeof(T));
  6387. byte[] result = new byte[size];
  6388. GCHandle handle = GCHandle.Alloc(result, GCHandleType.Pinned);
  6389. try
  6390. {
  6391. Marshal.StructureToPtr(data, handle.AddrOfPinnedObject(), false);
  6392. }
  6393. finally
  6394. {
  6395. handle.Free();
  6396. }
  6397. return result;
  6398. }
  6399. }
  6400. ​
  6401. public static class FileStreamExt
  6402. {
  6403. public static byte[] ReadAllBytes(this FileStream fs)
  6404. {
  6405. BinaryReader br = new BinaryReader(fs);
  6406. return br.ReadBytes((int)fs.Length);
  6407. }
  6408. ​
  6409. public static void WriteAllBytes(this FileStream fs, byte[] data)
  6410. {
  6411. fs.Seek(0, SeekOrigin.Begin);
  6412. fs.SetLength(data.Length);
  6413. fs.Write(data, 0, data.Length);
  6414. }
  6415. }
  6416. ​
  6417. public static class Utils
  6418. {
  6419. [DllImport("kernel32.dll")]
  6420. public static extern uint GetSystemDefaultLCID();
  6421. ​
  6422. [DllImport("kernel32.dll")]
  6423. public static extern bool Wow64EnableWow64FsRedirection(bool Wow64FsEnableRedirection);
  6424. ​
  6425. public static string DecodeString(byte[] data)
  6426. {
  6427. return Encoding.Unicode.GetString(data).Trim('\0');
  6428. }
  6429. ​
  6430. public static byte[] EncodeString(string str)
  6431. {
  6432. return Encoding.Unicode.GetBytes(str + '\0');
  6433. }
  6434. ​
  6435. public static uint CRC32(byte[] data)
  6436. {
  6437. const uint polynomial = 0x04C11DB7;
  6438. uint crc = 0xffffffff;
  6439. ​
  6440. foreach (byte b in data)
  6441. {
  6442. crc ^= (uint)b << 24;
  6443. for (int bit = 0; bit < 8; bit++)
  6444. {
  6445. if ((crc & 0x80000000) != 0)
  6446. {
  6447. crc = (crc << 1) ^ polynomial;
  6448. }
  6449. else
  6450. {
  6451. crc <<= 1;
  6452. }
  6453. }
  6454. }
  6455. return ~crc;
  6456. }
  6457. ​
  6458. public static string GetArchitecture()
  6459. {
  6460. string arch = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE", EnvironmentVariableTarget.Machine).ToUpperInvariant();
  6461. return arch == "AMD64" ? "X64" : arch;
  6462. }
  6463. ​
  6464. public static PSVersion DetectVersion()
  6465. {
  6466. int build = Environment.OSVersion.Version.Build;
  6467. ​
  6468. if (build >= 9600) return PSVersion.WinModern;
  6469. if (build >= 6000 && build <= 6003) return PSVersion.Vista;
  6470. if (build >= 7600 && build <= 7602) return PSVersion.Win7;
  6471. if (build == 9200) return PSVersion.Win8;
  6472. ​
  6473. throw new NotSupportedException("Unable to auto-detect version info");
  6474. }
  6475. }
  6476. ​
  6477. public static class Logger
  6478. {
  6479. public static bool HideOutput = false;
  6480. ​
  6481. public static void WriteLine(string line)
  6482. {
  6483. if (!HideOutput) Console.WriteLine(line);
  6484. }
  6485. }
  6486. }
  6487. ​
  6488. ​
  6489. // LibTSforge/SPP/PKeyConfig.cs
  6490. namespace LibTSforge.SPP
  6491. {
  6492. using System;
  6493. using System.Collections.Generic;
  6494. using System.IO;
  6495. using System.Linq;
  6496. using System.Text;
  6497. using System.Xml;
  6498. ​
  6499. public enum PKeyAlgorithm
  6500. {
  6501. PKEY2005,
  6502. PKEY2009
  6503. }
  6504. ​
  6505. public class KeyRange
  6506. {
  6507. public int Start;
  6508. public int End;
  6509. public string EulaType;
  6510. public string PartNumber;
  6511. public bool Valid;
  6512. ​
  6513. public bool Contains(int n)
  6514. {
  6515. return Start <= n && n <= End;
  6516. }
  6517. }
  6518. ​
  6519. public class ProductConfig
  6520. {
  6521. public int GroupId;
  6522. public string Edition;
  6523. public string Description;
  6524. public string Channel;
  6525. public bool Randomized;
  6526. public PKeyAlgorithm Algorithm;
  6527. public List<KeyRange> Ranges;
  6528. public Guid ActivationId;
  6529. ​
  6530. private List<KeyRange> GetPkeyRanges()
  6531. {
  6532. if (Ranges.Count == 0)
  6533. {
  6534. throw new ArgumentException("No key ranges.");
  6535. }
  6536. ​
  6537. if (Algorithm == PKeyAlgorithm.PKEY2005)
  6538. {
  6539. return Ranges;
  6540. }
  6541. ​
  6542. List<KeyRange> FilteredRanges = Ranges.Where(r => !r.EulaType.Contains("WAU")).ToList();
  6543. ​
  6544. if (FilteredRanges.Count == 0)
  6545. {
  6546. throw new NotSupportedException("Specified Activation ID is usable only for Windows Anytime Upgrade. Please use a non-WAU Activation ID instead.");
  6547. }
  6548. ​
  6549. return FilteredRanges;
  6550. }
  6551. ​
  6552. public ProductKey GetRandomKey()
  6553. {
  6554. List<KeyRange> KeyRanges = GetPkeyRanges();
  6555. Random rnd = new Random();
  6556. ​
  6557. KeyRange range = KeyRanges[rnd.Next(KeyRanges.Count)];
  6558. int serial = rnd.Next(range.Start, range.End);
  6559. ​
  6560. return new ProductKey(serial, 0, false, Algorithm, this, range);
  6561. }
  6562. }
  6563. ​
  6564. public class PKeyConfig
  6565. {
  6566. public readonly Dictionary<Guid, ProductConfig> Products = new Dictionary<Guid, ProductConfig>();
  6567. private readonly List<Guid> loadedPkeyConfigs = new List<Guid>();
  6568. ​
  6569. public void LoadConfig(Guid actId)
  6570. {
  6571. string pkcData;
  6572. Guid pkcFileId = SLApi.GetPkeyConfigFileId(actId);
  6573. ​
  6574. if (loadedPkeyConfigs.Contains(pkcFileId)) return;
  6575. ​
  6576. string licConts = SLApi.GetLicenseContents(pkcFileId);
  6577. ​
  6578. using (TextReader tr = new StringReader(licConts))
  6579. {
  6580. XmlDocument lic = new XmlDocument();
  6581. lic.Load(tr);
  6582. ​
  6583. XmlNamespaceManager nsmgr = new XmlNamespaceManager(lic.NameTable);
  6584. nsmgr.AddNamespace("rg", "urn:mpeg:mpeg21:2003:01-REL-R-NS");
  6585. nsmgr.AddNamespace("r", "urn:mpeg:mpeg21:2003:01-REL-R-NS");
  6586. nsmgr.AddNamespace("tm", "http://www.microsoft.com/DRM/XrML2/TM/v2");
  6587. ​
  6588. XmlNode root = lic.DocumentElement;
  6589. XmlNode pkcDataNode = root.SelectSingleNode("/rg:licenseGroup/r:license/r:otherInfo/tm:infoTables/tm:infoList/tm:infoBin[@name=\"pkeyConfigData\"]", nsmgr);
  6590. pkcData = Encoding.UTF8.GetString(Convert.FromBase64String(pkcDataNode.InnerText));
  6591. }
  6592. ​
  6593. using (TextReader tr = new StringReader(pkcData))
  6594. {
  6595. XmlDocument lic = new XmlDocument();
  6596. lic.Load(tr);
  6597. ​
  6598. XmlNamespaceManager nsmgr = new XmlNamespaceManager(lic.NameTable);
  6599. nsmgr.AddNamespace("p", "http://www.microsoft.com/DRM/PKEY/Configuration/2.0");
  6600. XmlNodeList configNodes = lic.SelectNodes("//p:ProductKeyConfiguration/p:Configurations/p:Configuration", nsmgr);
  6601. XmlNodeList rangeNodes = lic.SelectNodes("//p:ProductKeyConfiguration/p:KeyRanges/p:KeyRange", nsmgr);
  6602. XmlNodeList pubKeyNodes = lic.SelectNodes("//p:ProductKeyConfiguration/p:PublicKeys/p:PublicKey", nsmgr);
  6603. ​
  6604. Dictionary<int, PKeyAlgorithm> algorithms = new Dictionary<int, PKeyAlgorithm>();
  6605. Dictionary<string, List<KeyRange>> ranges = new Dictionary<string, List<KeyRange>>();
  6606. ​
  6607. Dictionary<string, PKeyAlgorithm> algoConv = new Dictionary<string, PKeyAlgorithm>
  6608. {
  6609. { "msft:rm/algorithm/pkey/2005", PKeyAlgorithm.PKEY2005 },
  6610. { "msft:rm/algorithm/pkey/2009", PKeyAlgorithm.PKEY2009 }
  6611. };
  6612. ​
  6613. foreach (XmlNode pubKeyNode in pubKeyNodes)
  6614. {
  6615. int group = int.Parse(pubKeyNode.SelectSingleNode("./p:GroupId", nsmgr).InnerText);
  6616. algorithms[group] = algoConv[pubKeyNode.SelectSingleNode("./p:AlgorithmId", nsmgr).InnerText];
  6617. }
  6618. ​
  6619. foreach (XmlNode rangeNode in rangeNodes)
  6620. {
  6621. string refActIdStr = rangeNode.SelectSingleNode("./p:RefActConfigId", nsmgr).InnerText;
  6622. ​
  6623. if (!ranges.ContainsKey(refActIdStr))
  6624. {
  6625. ranges[refActIdStr] = new List<KeyRange>();
  6626. }
  6627. ​
  6628. KeyRange keyRange = new KeyRange
  6629. {
  6630. Start = int.Parse(rangeNode.SelectSingleNode("./p:Start", nsmgr).InnerText),
  6631. End = int.Parse(rangeNode.SelectSingleNode("./p:End", nsmgr).InnerText),
  6632. EulaType = rangeNode.SelectSingleNode("./p:EulaType", nsmgr).InnerText,
  6633. PartNumber = rangeNode.SelectSingleNode("./p:PartNumber", nsmgr).InnerText,
  6634. Valid = rangeNode.SelectSingleNode("./p:IsValid", nsmgr).InnerText.ToLower() == "true"
  6635. };
  6636. ​
  6637. ranges[refActIdStr].Add(keyRange);
  6638. }
  6639. ​
  6640. foreach (XmlNode configNode in configNodes)
  6641. {
  6642. string refActIdStr = configNode.SelectSingleNode("./p:ActConfigId", nsmgr).InnerText;
  6643. Guid refActId = new Guid(refActIdStr);
  6644. int group = int.Parse(configNode.SelectSingleNode("./p:RefGroupId", nsmgr).InnerText);
  6645. List<KeyRange> keyRanges;
  6646. ranges.TryGetValue(refActIdStr, out keyRanges);
  6647. ​
  6648. if (keyRanges == null)
  6649. {
  6650. continue;
  6651. }
  6652. ​
  6653. if (keyRanges.Count > 0 && !Products.ContainsKey(refActId))
  6654. {
  6655. PKeyAlgorithm algorithm;
  6656. algorithms.TryGetValue(group, out algorithm);
  6657. ​
  6658. ProductConfig productConfig = new ProductConfig
  6659. {
  6660. GroupId = group,
  6661. Edition = configNode.SelectSingleNode("./p:EditionId", nsmgr).InnerText,
  6662. Description = configNode.SelectSingleNode("./p:ProductDescription", nsmgr).InnerText,
  6663. Channel = configNode.SelectSingleNode("./p:ProductKeyType", nsmgr).InnerText,
  6664. Randomized = configNode.SelectSingleNode("./p:ProductKeyType", nsmgr).InnerText.ToLower() == "true",
  6665. Algorithm = algorithm,
  6666. Ranges = keyRanges,
  6667. ActivationId = refActId
  6668. };
  6669. ​
  6670. Products[refActId] = productConfig;
  6671. }
  6672. }
  6673. }
  6674. ​
  6675. loadedPkeyConfigs.Add(pkcFileId);
  6676. }
  6677. ​
  6678. public ProductConfig MatchParams(int group, int serial)
  6679. {
  6680. foreach (ProductConfig config in Products.Values)
  6681. {
  6682. if (config.GroupId == group)
  6683. {
  6684. foreach (KeyRange range in config.Ranges)
  6685. {
  6686. if (range.Contains(serial))
  6687. {
  6688. return config;
  6689. }
  6690. }
  6691. }
  6692. }
  6693. ​
  6694. throw new FileNotFoundException("Failed to find product matching supplied product key parameters.");
  6695. }
  6696. ​
  6697. public void LoadAllConfigs(Guid appId)
  6698. {
  6699. foreach (Guid actId in SLApi.GetActivationIds(appId))
  6700. {
  6701. try
  6702. {
  6703. LoadConfig(actId);
  6704. }
  6705. catch (ArgumentException)
  6706. {
  6707. ​
  6708. }
  6709. }
  6710. }
  6711. }
  6712. }
  6713. ​
  6714. ​
  6715. // LibTSforge/SPP/ProductKey.cs
  6716. namespace LibTSforge.SPP
  6717. {
  6718. using System;
  6719. using System.IO;
  6720. using System.Linq;
  6721. using Crypto;
  6722. using PhysicalStore;
  6723. ​
  6724. public class ProductKey
  6725. {
  6726. private static readonly string ALPHABET = "BCDFGHJKMPQRTVWXY2346789";
  6727. ​
  6728. private readonly ulong klow;
  6729. private readonly ulong khigh;
  6730. ​
  6731. public int Group;
  6732. public int Serial;
  6733. public ulong Security;
  6734. public bool Upgrade;
  6735. public PKeyAlgorithm Algorithm;
  6736. public readonly string EulaType;
  6737. public readonly string PartNumber;
  6738. public readonly string Edition;
  6739. public readonly string Channel;
  6740. public readonly Guid ActivationId;
  6741. ​
  6742. private string mpc;
  6743. private string pid2;
  6744. ​
  6745. public byte[] KeyBytes
  6746. {
  6747. get { return BitConverter.GetBytes(klow).Concat(BitConverter.GetBytes(khigh)).ToArray(); }
  6748. }
  6749. ​
  6750. public ProductKey()
  6751. {
  6752. ​
  6753. }
  6754. ​
  6755. public ProductKey(int serial, ulong security, bool upgrade, PKeyAlgorithm algorithm, ProductConfig config, KeyRange range)
  6756. {
  6757. Group = config.GroupId;
  6758. Serial = serial;
  6759. Security = security;
  6760. Upgrade = upgrade;
  6761. Algorithm = algorithm;
  6762. EulaType = range.EulaType;
  6763. PartNumber = range.PartNumber.Split(':', ';')[0];
  6764. Edition = config.Edition;
  6765. Channel = config.Channel;
  6766. ActivationId = config.ActivationId;
  6767. ​
  6768. klow = ((security & 0x3fff) << 50 | ((ulong)serial & 0x3fffffff) << 20 | ((ulong)Group & 0xfffff));
  6769. khigh = ((upgrade ? (ulong)1 : 0) << 49 | ((security >> 14) & 0x7fffffffff));
  6770. ​
  6771. uint checksum = Utils.CRC32(KeyBytes) & 0x3ff;
  6772. ​
  6773. khigh |= ((ulong)checksum << 39);
  6774. }
  6775. ​
  6776. public string GetAlgoUri()
  6777. {
  6778. return "msft:rm/algorithm/pkey/" + (Algorithm == PKeyAlgorithm.PKEY2005 ? "2005" : (Algorithm == PKeyAlgorithm.PKEY2009 ? "2009" : "Unknown"));
  6779. }
  6780. ​
  6781. public Guid GetPkeyId()
  6782. {
  6783. VariableBag pkb = new VariableBag(PSVersion.WinModern);
  6784. pkb.Blocks.AddRange(new[]
  6785. {
  6786. new CRCBlockModern
  6787. {
  6788. DataType = CRCBlockType.STRING,
  6789. KeyAsStr = "SppPkeyBindingProductKey",
  6790. ValueAsStr = ToString()
  6791. },
  6792. new CRCBlockModern
  6793. {
  6794. DataType = CRCBlockType.BINARY,
  6795. KeyAsStr = "SppPkeyBindingMiscData",
  6796. Value = new byte[] { }
  6797. },
  6798. new CRCBlockModern
  6799. {
  6800. DataType = CRCBlockType.STRING,
  6801. KeyAsStr = "SppPkeyBindingAlgorithm",
  6802. ValueAsStr = GetAlgoUri()
  6803. }
  6804. });
  6805. ​
  6806. return new Guid(CryptoUtils.SHA256Hash(pkb.Serialize()).Take(16).ToArray());
  6807. }
  6808. ​
  6809. public string GetMPC()
  6810. {
  6811. if (mpc != null)
  6812. {
  6813. return mpc;
  6814. }
  6815. ​
  6816. int build = Environment.OSVersion.Version.Build;
  6817. ​
  6818. mpc = build >= 10240 ? "03612" :
  6819. build >= 9600 ? "06401" :
  6820. build >= 9200 ? "05426" :
  6821. "55041";
  6822. ​
  6823. // setup.cfg doesn't exist in Windows 8+
  6824. string setupcfg = string.Format(@"{0}\oobe\{1}", Environment.SystemDirectory, "setup.cfg");
  6825. ​
  6826. if (!File.Exists(setupcfg) || Edition.Contains(";"))
  6827. {
  6828. return mpc;
  6829. }
  6830. ​
  6831. string mpcKey = string.Format("{0}.{1}=", Utils.GetArchitecture(), Edition);
  6832. string localMPC = File.ReadAllLines(setupcfg).FirstOrDefault(line => line.Contains(mpcKey));
  6833. if (localMPC != null)
  6834. {
  6835. mpc = localMPC.Split('=')[1].Trim();
  6836. }
  6837. ​
  6838. return mpc;
  6839. }
  6840. ​
  6841. public string GetPid2()
  6842. {
  6843. if (pid2 != null)
  6844. {
  6845. return pid2;
  6846. }
  6847. ​
  6848. pid2 = "";
  6849. ​
  6850. if (Algorithm == PKeyAlgorithm.PKEY2005)
  6851. {
  6852. string mpc = GetMPC();
  6853. string serialHigh;
  6854. int serialLow;
  6855. int lastPart;
  6856. ​
  6857. if (EulaType == "OEM")
  6858. {
  6859. serialHigh = "OEM";
  6860. serialLow = ((Group / 2) % 100) * 10000 + (Serial / 100000);
  6861. lastPart = Serial % 100000;
  6862. }
  6863. else
  6864. {
  6865. serialHigh = (Serial / 1000000).ToString("D3");
  6866. serialLow = Serial % 1000000;
  6867. lastPart = ((Group / 2) % 100) * 1000 + new Random().Next(1000);
  6868. }
  6869. ​
  6870. int checksum = 0;
  6871. ​
  6872. foreach (char c in serialLow.ToString())
  6873. {
  6874. checksum += int.Parse(c.ToString());
  6875. }
  6876. checksum = 7 - (checksum % 7);
  6877. ​
  6878. pid2 = string.Format("{0}-{1}-{2:D6}{3}-{4:D5}", mpc, serialHigh, serialLow, checksum, lastPart);
  6879. }
  6880. ​
  6881. return pid2;
  6882. }
  6883. ​
  6884. public byte[] GetPid3()
  6885. {
  6886. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  6887. writer.Write(0xA4);
  6888. writer.Write(0x3);
  6889. writer.WriteFixedString(GetPid2(), 24);
  6890. writer.Write(Group);
  6891. writer.WriteFixedString(PartNumber, 16);
  6892. writer.WritePadding(0x6C);
  6893. byte[] data = writer.GetBytes();
  6894. byte[] crc = BitConverter.GetBytes(~Utils.CRC32(data.Reverse().ToArray())).Reverse().ToArray();
  6895. writer.Write(crc);
  6896. ​
  6897. return writer.GetBytes();
  6898. }
  6899. ​
  6900. public byte[] GetPid4()
  6901. {
  6902. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  6903. writer.Write(0x4F8);
  6904. writer.Write(0x4);
  6905. writer.WriteFixedString16(GetExtendedPid(), 0x80);
  6906. writer.WriteFixedString16(ActivationId.ToString(), 0x80);
  6907. writer.WritePadding(0x10);
  6908. writer.WriteFixedString16(Edition, 0x208);
  6909. writer.Write(Upgrade ? (ulong)1 : 0);
  6910. writer.WritePadding(0x50);
  6911. writer.WriteFixedString16(PartNumber, 0x80);
  6912. writer.WriteFixedString16(Channel, 0x80);
  6913. writer.WriteFixedString16(EulaType, 0x80);
  6914. ​
  6915. return writer.GetBytes();
  6916. }
  6917. ​
  6918. public string GetExtendedPid()
  6919. {
  6920. string mpc = GetMPC();
  6921. int serialHigh = Serial / 1000000;
  6922. int serialLow = Serial % 1000000;
  6923. int licenseType;
  6924. uint lcid = Utils.GetSystemDefaultLCID();
  6925. int build = Environment.OSVersion.Version.Build;
  6926. int dayOfYear = DateTime.Now.DayOfYear;
  6927. int year = DateTime.Now.Year;
  6928. ​
  6929. switch (EulaType)
  6930. {
  6931. case "OEM":
  6932. licenseType = 2;
  6933. break;
  6934. ​
  6935. case "Volume":
  6936. licenseType = 3;
  6937. break;
  6938. ​
  6939. default:
  6940. licenseType = 0;
  6941. break;
  6942. }
  6943. ​
  6944. return string.Format(
  6945. "{0}-{1:D5}-{2:D3}-{3:D6}-{4:D2}-{5:D4}-{6:D4}.0000-{7:D3}{8:D4}",
  6946. mpc,
  6947. Group,
  6948. serialHigh,
  6949. serialLow,
  6950. licenseType,
  6951. lcid,
  6952. build,
  6953. dayOfYear,
  6954. year
  6955. );
  6956. }
  6957. ​
  6958. public byte[] GetPhoneData(PSVersion version)
  6959. {
  6960. if (version == PSVersion.Win7)
  6961. {
  6962. ulong shortauth = ((ulong)Group << 41) | (Security << 31) | ((ulong)Serial << 1) | (Upgrade ? (ulong)1 : 0);
  6963. return BitConverter.GetBytes(shortauth);
  6964. }
  6965. ​
  6966. int serialHigh = Serial / 1000000;
  6967. int serialLow = Serial % 1000000;
  6968. ​
  6969. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  6970. string algoId = Algorithm == PKeyAlgorithm.PKEY2005 ? "B8731595-A2F6-430B-A799-FBFFB81A8D73" : "660672EF-7809-4CFD-8D54-41B7FB738988";
  6971. ​
  6972. writer.Write(new Guid(algoId).ToByteArray());
  6973. writer.Write(Group);
  6974. writer.Write(serialHigh);
  6975. writer.Write(serialLow);
  6976. writer.Write(Upgrade ? 1 : 0);
  6977. writer.Write(Security);
  6978. ​
  6979. return writer.GetBytes();
  6980. }
  6981. ​
  6982. public override string ToString()
  6983. {
  6984. string keyStr = "";
  6985. Random rnd = new Random(Group * 1000000000 + Serial);
  6986. ​
  6987. if (Algorithm == PKeyAlgorithm.PKEY2005)
  6988. {
  6989. keyStr = "H4X3DH4X3DH4X3DH4X3D";
  6990. ​
  6991. for (int i = 0; i < 5; i++)
  6992. {
  6993. keyStr += ALPHABET[rnd.Next(24)];
  6994. }
  6995. }
  6996. else if (Algorithm == PKeyAlgorithm.PKEY2009)
  6997. {
  6998. int last = 0;
  6999. byte[] bKey = KeyBytes;
  7000. ​
  7001. for (int i = 24; i >= 0; i--)
  7002. {
  7003. int current = 0;
  7004. ​
  7005. for (int j = 14; j >= 0; j--)
  7006. {
  7007. current *= 0x100;
  7008. current += bKey[j];
  7009. bKey[j] = (byte)(current / 24);
  7010. current %= 24;
  7011. last = current;
  7012. }
  7013. ​
  7014. keyStr = ALPHABET[current] + keyStr;
  7015. }
  7016. ​
  7017. keyStr = keyStr.Substring(1, last) + "N" + keyStr.Substring(last + 1, keyStr.Length - last - 1);
  7018. }
  7019. ​
  7020. for (int i = 5; i < keyStr.Length; i += 6)
  7021. {
  7022. keyStr = keyStr.Insert(i, "-");
  7023. }
  7024. ​
  7025. return keyStr;
  7026. }
  7027. }
  7028. }
  7029. ​
  7030. ​
  7031. // LibTSforge/SPP/SLAPI.cs
  7032. namespace LibTSforge.SPP
  7033. {
  7034. using System;
  7035. using System.Collections.Generic;
  7036. using System.Linq;
  7037. using System.Runtime.InteropServices;
  7038. using System.Text;
  7039. ​
  7040. public static class SLApi
  7041. {
  7042. private enum SLIDTYPE
  7043. {
  7044. SL_ID_APPLICATION,
  7045. SL_ID_PRODUCT_SKU,
  7046. SL_ID_LICENSE_FILE,
  7047. SL_ID_LICENSE,
  7048. SL_ID_PKEY,
  7049. SL_ID_ALL_LICENSES,
  7050. SL_ID_ALL_LICENSE_FILES,
  7051. SL_ID_STORE_TOKEN,
  7052. SL_ID_LAST
  7053. }
  7054. ​
  7055. private enum SLDATATYPE
  7056. {
  7057. SL_DATA_NONE,
  7058. SL_DATA_SZ,
  7059. SL_DATA_DWORD,
  7060. SL_DATA_BINARY,
  7061. SL_DATA_MULTI_SZ,
  7062. SL_DATA_SUM
  7063. }
  7064. ​
  7065. [StructLayout(LayoutKind.Sequential)]
  7066. private struct SL_LICENSING_STATUS
  7067. {
  7068. public Guid SkuId;
  7069. public uint eStatus;
  7070. public uint dwGraceTime;
  7071. public uint dwTotalGraceDays;
  7072. public uint hrReason;
  7073. public ulong qwValidityExpiration;
  7074. }
  7075. ​
  7076. public static readonly Guid WINDOWS_APP_ID = new Guid("55c92734-d682-4d71-983e-d6ec3f16059f");
  7077. ​
  7078. [DllImport("slc.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
  7079. private static extern void SLOpen(out IntPtr hSLC);
  7080. ​
  7081. [DllImport("slc.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
  7082. private static extern void SLClose(IntPtr hSLC);
  7083. ​
  7084. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  7085. private static extern uint SLGetWindowsInformationDWORD(string ValueName, ref int Value);
  7086. ​
  7087. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  7088. private static extern uint SLInstallProofOfPurchase(IntPtr hSLC, string pwszPKeyAlgorithm, string pwszPKeyString, uint cbPKeySpecificData, byte[] pbPKeySpecificData, ref Guid PKeyId);
  7089. ​
  7090. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  7091. private static extern uint SLUninstallProofOfPurchase(IntPtr hSLC, ref Guid PKeyId);
  7092. ​
  7093. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  7094. private static extern uint SLGetPKeyInformation(IntPtr hSLC, ref Guid pPKeyId, string pwszValueName, out SLDATATYPE peDataType, out uint pcbValue, out IntPtr ppbValue);
  7095. ​
  7096. [DllImport("slcext.dll", CharSet = CharSet.Unicode)]
  7097. private static extern uint SLActivateProduct(IntPtr hSLC, ref Guid pProductSkuId, byte[] cbAppSpecificData, byte[] pvAppSpecificData, byte[] pActivationInfo, string pwszProxyServer, ushort wProxyPort);
  7098. ​
  7099. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  7100. private static extern uint SLGenerateOfflineInstallationId(IntPtr hSLC, ref Guid pProductSkuId, ref string ppwszInstallationId);
  7101. ​
  7102. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  7103. private static extern uint SLDepositOfflineConfirmationId(IntPtr hSLC, ref Guid pProductSkuId, string pwszInstallationId, string pwszConfirmationId);
  7104. ​
  7105. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  7106. private static extern uint SLGetSLIDList(IntPtr hSLC, SLIDTYPE eQueryIdType, ref Guid pQueryId, SLIDTYPE eReturnIdType, out uint pnReturnIds, out IntPtr ppReturnIds);
  7107. ​
  7108. [DllImport("slc.dll", CharSet = CharSet.Unicode, PreserveSig = false)]
  7109. private static extern void SLGetLicensingStatusInformation(IntPtr hSLC, ref Guid pAppID, IntPtr pProductSkuId, string pwszRightName, out uint pnStatusCount, out IntPtr ppLicensingStatus);
  7110. ​
  7111. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  7112. private static extern uint SLGetInstalledProductKeyIds(IntPtr hSLC, ref Guid pProductSkuId, out uint pnProductKeyIds, out IntPtr ppProductKeyIds);
  7113. ​
  7114. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  7115. private static extern uint SLConsumeWindowsRight(uint unknown);
  7116. ​
  7117. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  7118. private static extern uint SLGetProductSkuInformation(IntPtr hSLC, ref Guid pProductSkuId, string pwszValueName, out SLDATATYPE peDataType, out uint pcbValue, out IntPtr ppbValue);
  7119. ​
  7120. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  7121. private static extern uint SLGetLicense(IntPtr hSLC, ref Guid pLicenseFileId, out uint pcbLicenseFile, out IntPtr ppbLicenseFile);
  7122. ​
  7123. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  7124. private static extern uint SLSetCurrentProductKey(IntPtr hSLC, ref Guid pProductSkuId, ref Guid pProductKeyId);
  7125. ​
  7126. [DllImport("slc.dll", CharSet = CharSet.Unicode)]
  7127. private static extern uint SLFireEvent(IntPtr hSLC, string pwszEventId, ref Guid pApplicationId);
  7128. ​
  7129. private class SLContext : IDisposable
  7130. {
  7131. public readonly IntPtr Handle;
  7132. ​
  7133. public SLContext()
  7134. {
  7135. SLOpen(out Handle);
  7136. }
  7137. ​
  7138. public void Dispose()
  7139. {
  7140. SLClose(Handle);
  7141. GC.SuppressFinalize(this);
  7142. }
  7143. ​
  7144. ~SLContext()
  7145. {
  7146. Dispose();
  7147. }
  7148. }
  7149. ​
  7150. public static Guid GetDefaultActivationID(Guid appId, bool includeActivated)
  7151. {
  7152. using (SLContext sl = new SLContext())
  7153. {
  7154. uint count;
  7155. IntPtr pLicStat;
  7156. ​
  7157. SLGetLicensingStatusInformation(sl.Handle, ref appId, IntPtr.Zero, null, out count, out pLicStat);
  7158. ​
  7159. unsafe
  7160. {
  7161. SL_LICENSING_STATUS* licensingStatuses = (SL_LICENSING_STATUS*)pLicStat;
  7162. for (int i = 0; i < count; i++)
  7163. {
  7164. SL_LICENSING_STATUS slStatus = licensingStatuses[i];
  7165. ​
  7166. Guid actId = slStatus.SkuId;
  7167. if (GetInstalledPkeyID(actId) == Guid.Empty) continue;
  7168. if (IsAddon(actId)) continue;
  7169. if (!includeActivated && (slStatus.eStatus == 1)) continue;
  7170. ​
  7171. return actId;
  7172. }
  7173. }
  7174. ​
  7175. return Guid.Empty;
  7176. }
  7177. }
  7178. ​
  7179. public static string GetInstallationID(Guid actId)
  7180. {
  7181. using (SLContext sl = new SLContext())
  7182. {
  7183. string installationId = null;
  7184. return SLGenerateOfflineInstallationId(sl.Handle, ref actId, ref installationId) == 0 ? installationId : null;
  7185. }
  7186. }
  7187. ​
  7188. public static Guid GetInstalledPkeyID(Guid actId)
  7189. {
  7190. using (SLContext sl = new SLContext())
  7191. {
  7192. uint count;
  7193. IntPtr pProductKeyIds;
  7194. ​
  7195. uint status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_PRODUCT_SKU, ref actId, SLIDTYPE.SL_ID_PKEY, out count, out pProductKeyIds);
  7196. ​
  7197. if (status != 0 || count == 0)
  7198. {
  7199. return Guid.Empty;
  7200. }
  7201. ​
  7202. unsafe { return *(Guid*)pProductKeyIds; }
  7203. }
  7204. }
  7205. ​
  7206. public static uint DepositConfirmationID(Guid actId, string installationId, string confirmationId)
  7207. {
  7208. using (SLContext sl = new SLContext())
  7209. {
  7210. return SLDepositOfflineConfirmationId(sl.Handle, ref actId, installationId, confirmationId);
  7211. }
  7212. }
  7213. ​
  7214. public static void RefreshLicenseStatus()
  7215. {
  7216. SLConsumeWindowsRight(0);
  7217. }
  7218. ​
  7219. public static void RefreshTrustedTime(Guid actId)
  7220. {
  7221. using (SLContext sl = new SLContext())
  7222. {
  7223. SLDATATYPE type;
  7224. uint count;
  7225. IntPtr ppbValue;
  7226. ​
  7227. SLGetProductSkuInformation(sl.Handle, ref actId, "TrustedTime", out type, out count, out ppbValue);
  7228. }
  7229. }
  7230. ​
  7231. public static void FireStateChangedEvent(Guid appId)
  7232. {
  7233. using (SLContext sl = new SLContext())
  7234. {
  7235. SLFireEvent(sl.Handle, "msft:rm/event/licensingstatechanged", ref appId);
  7236. }
  7237. }
  7238. ​
  7239. public static Guid GetAppId(Guid actId)
  7240. {
  7241. using (SLContext sl = new SLContext())
  7242. {
  7243. uint count;
  7244. IntPtr pAppIds;
  7245. ​
  7246. uint status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_PRODUCT_SKU, ref actId, SLIDTYPE.SL_ID_APPLICATION, out count, out pAppIds);
  7247. ​
  7248. if (status != 0 || count == 0)
  7249. {
  7250. return Guid.Empty;
  7251. }
  7252. ​
  7253. unsafe { return *(Guid*)pAppIds; }
  7254. }
  7255. }
  7256. ​
  7257. public static bool IsAddon(Guid actId)
  7258. {
  7259. using (SLContext sl = new SLContext())
  7260. {
  7261. uint count;
  7262. SLDATATYPE type;
  7263. IntPtr ppbValue;
  7264. ​
  7265. uint status = SLGetProductSkuInformation(sl.Handle, ref actId, "DependsOn", out type, out count, out ppbValue);
  7266. return (int)status >= 0 && status != 0xC004F012;
  7267. }
  7268. }
  7269. ​
  7270. public static Guid GetLicenseFileId(Guid licId)
  7271. {
  7272. using (SLContext sl = new SLContext())
  7273. {
  7274. uint count;
  7275. IntPtr ppReturnLics;
  7276. ​
  7277. uint status = SLGetSLIDList(sl.Handle, SLIDTYPE.SL_ID_LICENSE, ref licId, SLIDTYPE.SL_ID_LICENSE_FILE, out count, out ppReturnLics);
  7278. ​
  7279. if (status != 0 || count == 0)
  7280. {
  7281. return Guid.Empty;
  7282. }
  7283. ​
  7284. unsafe { return *(Guid*)ppReturnLics; }
  7285. }
  7286. }
  7287. ​
  7288. public static Guid GetPkeyConfigFileId(Guid actId)
  7289. {
  7290. using (SLContext sl = new SLContext())
  7291. {
  7292. SLDATATYPE type;
  7293. uint len;
  7294. IntPtr ppReturnLics;
  7295. ​
  7296. uint status = SLGetProductSkuInformation(sl.Handle, ref actId, "pkeyConfigLicenseId", out type, out len, out ppReturnLics);
  7297. ​
  7298. if (status != 0 || len == 0)
  7299. {
  7300. return Guid.Empty;
  7301. }
  7302. ​
  7303. Guid pkcId = new Guid(Marshal.PtrToStringAuto(ppReturnLics));
  7304. return GetLicenseFileId(pkcId);
  7305. }
  7306. }
  7307. ​
  7308. public static string GetLicenseContents(Guid fileId)
  7309. {
  7310. if (fileId == Guid.Empty) throw new ArgumentException("License contents could not be retrieved.");
  7311. ​
  7312. using (SLContext sl = new SLContext())
  7313. {
  7314. uint dataLen;
  7315. IntPtr dataPtr;
  7316. ​
  7317. if (SLGetLicense(sl.Handle, ref fileId, out dataLen, out dataPtr) != 0)
  7318. {
  7319. return null;
  7320. }
  7321. ​
  7322. byte[] data = new byte[dataLen];
  7323. Marshal.Copy(dataPtr, data, 0, (int)dataLen);
  7324. ​
  7325. data = data.Skip(Array.IndexOf(data, (byte)'<')).ToArray();
  7326. return Encoding.UTF8.GetString(data);
  7327. }
  7328. }
  7329. ​
  7330. public static bool IsPhoneActivatable(Guid actId)
  7331. {
  7332. using (SLContext sl = new SLContext())
  7333. {
  7334. uint count;
  7335. SLDATATYPE type;
  7336. IntPtr ppbValue;
  7337. ​
  7338. uint status = SLGetProductSkuInformation(sl.Handle, ref actId, "msft:sl/EUL/PHONE/PUBLIC", out type, out count, out ppbValue);
  7339. return status != 0xC004F012;
  7340. }
  7341. }
  7342. ​
  7343. public static string GetPKeyChannel(Guid pkeyId)
  7344. {
  7345. using (SLContext sl = new SLContext())
  7346. {
  7347. SLDATATYPE type;
  7348. uint len;
  7349. IntPtr ppbValue;
  7350. ​
  7351. uint status = SLGetPKeyInformation(sl.Handle, ref pkeyId, "Channel", out type, out len, out ppbValue);
  7352. ​
  7353. if (status != 0 || len == 0)
  7354. {
  7355. return null;
  7356. }
  7357. ​
  7358. return Marshal.PtrToStringAuto(ppbValue);
  7359. }
  7360. }
  7361. ​
  7362. public static string GetMetaStr(Guid actId, string value)
  7363. {
  7364. using (SLContext sl = new SLContext())
  7365. {
  7366. uint len;
  7367. SLDATATYPE type;
  7368. IntPtr ppbValue;
  7369. ​
  7370. uint status = SLGetProductSkuInformation(sl.Handle, ref actId, value, out type, out len, out ppbValue);
  7371. ​
  7372. if (status != 0 || len == 0 || type != SLDATATYPE.SL_DATA_SZ)
  7373. {
  7374. return null;
  7375. }
  7376. ​
  7377. return Marshal.PtrToStringAuto(ppbValue);
  7378. }
  7379. }
  7380. ​
  7381. public static List<Guid> GetActivationIds(Guid appId)
  7382. {
  7383. using (SLContext sl = new SLContext())
  7384. {
  7385. uint count;
  7386. IntPtr pLicStat;
  7387. ​
  7388. SLGetLicensingStatusInformation(sl.Handle, ref appId, IntPtr.Zero, null, out count, out pLicStat);
  7389. ​
  7390. List<Guid> result = new List<Guid>();
  7391. ​
  7392. unsafe
  7393. {
  7394. SL_LICENSING_STATUS* licensingStatuses = (SL_LICENSING_STATUS*)pLicStat;
  7395. for (int i = 0; i < count; i++)
  7396. {
  7397. result.Add(licensingStatuses[i].SkuId);
  7398. }
  7399. }
  7400. ​
  7401. return result;
  7402. }
  7403. }
  7404. ​
  7405. public static uint SetCurrentProductKey(Guid actId, Guid pkeyId)
  7406. {
  7407. using (SLContext sl = new SLContext())
  7408. {
  7409. return SLSetCurrentProductKey(sl.Handle, ref actId, ref pkeyId);
  7410. }
  7411. }
  7412. ​
  7413. public static uint InstallProductKey(ProductKey pkey)
  7414. {
  7415. using (SLContext sl = new SLContext())
  7416. {
  7417. Guid pkeyId = Guid.Empty;
  7418. return SLInstallProofOfPurchase(sl.Handle, pkey.GetAlgoUri(), pkey.ToString(), 0, null, ref pkeyId);
  7419. }
  7420. }
  7421. ​
  7422. public static void UninstallProductKey(Guid pkeyId)
  7423. {
  7424. using (SLContext sl = new SLContext())
  7425. {
  7426. SLUninstallProofOfPurchase(sl.Handle, ref pkeyId);
  7427. }
  7428. }
  7429. ​
  7430. public static void UninstallAllProductKeys(Guid appId)
  7431. {
  7432. foreach (Guid actId in GetActivationIds(appId))
  7433. {
  7434. Guid pkeyId = GetInstalledPkeyID(actId);
  7435. if (pkeyId == Guid.Empty) continue;
  7436. if (IsAddon(actId)) continue;
  7437. UninstallProductKey(pkeyId);
  7438. }
  7439. }
  7440. }
  7441. }
  7442. ​
  7443. ​
  7444. // LibTSforge/SPP/SPPUtils.cs
  7445. namespace LibTSforge.SPP
  7446. {
  7447. using Microsoft.Win32;
  7448. using System;
  7449. using System.IO;
  7450. using System.Linq;
  7451. using System.ServiceProcess;
  7452. using Crypto;
  7453. using PhysicalStore;
  7454. using TokenStore;
  7455. ​
  7456. public static class SPPUtils
  7457. {
  7458. public static void KillSPP(PSVersion version)
  7459. {
  7460. ServiceController sc;
  7461. ​
  7462. string svcName = version == PSVersion.Vista ? "slsvc" : "sppsvc";
  7463. ​
  7464. try
  7465. {
  7466. sc = new ServiceController(svcName);
  7467. ​
  7468. if (sc.Status == ServiceControllerStatus.Stopped)
  7469. return;
  7470. }
  7471. catch (InvalidOperationException ex)
  7472. {
  7473. throw new InvalidOperationException(string.Format("Unable to access {0}: ", svcName) + ex.Message);
  7474. }
  7475. ​
  7476. Logger.WriteLine(string.Format("Stopping {0}...", svcName));
  7477. ​
  7478. bool stopped = false;
  7479. ​
  7480. for (int i = 0; stopped == false && i < 1080; i++)
  7481. {
  7482. try
  7483. {
  7484. if (sc.Status != ServiceControllerStatus.StopPending)
  7485. sc.Stop();
  7486. ​
  7487. sc.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromMilliseconds(500));
  7488. }
  7489. catch (System.ServiceProcess.TimeoutException)
  7490. {
  7491. continue;
  7492. }
  7493. catch (InvalidOperationException ex)
  7494. {
  7495. Logger.WriteLine("Warning: Stopping sppsvc failed, retrying. Details: " + ex.Message);
  7496. System.Threading.Thread.Sleep(500);
  7497. continue;
  7498. }
  7499. ​
  7500. stopped = true;
  7501. }
  7502. ​
  7503. if (!stopped)
  7504. throw new System.TimeoutException(string.Format("Failed to stop {0}", svcName));
  7505. ​
  7506. Logger.WriteLine(string.Format("{0} stopped successfully.", svcName));
  7507. ​
  7508. if (version == PSVersion.Vista && SPSys.IsSpSysRunning())
  7509. {
  7510. Logger.WriteLine("Unloading spsys...");
  7511. ​
  7512. int status = SPSys.ControlSpSys(false);
  7513. ​
  7514. if (status < 0)
  7515. {
  7516. throw new IOException("Failed to unload spsys");
  7517. }
  7518. ​
  7519. Logger.WriteLine("spsys unloaded successfully.");
  7520. }
  7521. }
  7522. ​
  7523. public static void RestartSPP(PSVersion version)
  7524. {
  7525. if (version == PSVersion.Vista)
  7526. {
  7527. ServiceController sc;
  7528. ​
  7529. try
  7530. {
  7531. sc = new ServiceController("slsvc");
  7532. ​
  7533. if (sc.Status == ServiceControllerStatus.Running)
  7534. return;
  7535. }
  7536. catch (InvalidOperationException ex)
  7537. {
  7538. throw new InvalidOperationException("Unable to access slsvc: " + ex.Message);
  7539. }
  7540. ​
  7541. Logger.WriteLine("Starting slsvc...");
  7542. ​
  7543. bool started = false;
  7544. ​
  7545. for (int i = 0; started == false && i < 360; i++)
  7546. {
  7547. try
  7548. {
  7549. if (sc.Status != ServiceControllerStatus.StartPending)
  7550. sc.Start();
  7551. ​
  7552. sc.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMilliseconds(500));
  7553. }
  7554. catch (System.ServiceProcess.TimeoutException)
  7555. {
  7556. continue;
  7557. }
  7558. catch (InvalidOperationException ex)
  7559. {
  7560. Logger.WriteLine("Warning: Starting slsvc failed, retrying. Details: " + ex.Message);
  7561. System.Threading.Thread.Sleep(500);
  7562. continue;
  7563. }
  7564. ​
  7565. started = true;
  7566. }
  7567. ​
  7568. if (!started)
  7569. throw new System.TimeoutException("Failed to start slsvc");
  7570. ​
  7571. Logger.WriteLine("slsvc started successfully.");
  7572. }
  7573. ​
  7574. SLApi.RefreshLicenseStatus();
  7575. }
  7576. ​
  7577. public static bool DetectCurrentKey()
  7578. {
  7579. SLApi.RefreshLicenseStatus();
  7580. ​
  7581. using (RegistryKey wpaKey = Registry.LocalMachine.OpenSubKey(@"SYSTEM\WPA"))
  7582. {
  7583. foreach (string subKey in wpaKey.GetSubKeyNames())
  7584. {
  7585. if (subKey.StartsWith("8DEC0AF1"))
  7586. {
  7587. return subKey.Contains("P");
  7588. }
  7589. }
  7590. }
  7591. ​
  7592. throw new FileNotFoundException("Failed to autodetect key type, specify physical store key with /prod or /test arguments.");
  7593. }
  7594. ​
  7595. public static string GetPSPath(PSVersion version)
  7596. {
  7597. switch (version)
  7598. {
  7599. case PSVersion.Vista:
  7600. case PSVersion.Win7:
  7601. return Directory.GetFiles(
  7602. Environment.GetFolderPath(Environment.SpecialFolder.System),
  7603. "7B296FB0-376B-497e-B012-9C450E1B7327-*.C7483456-A289-439d-8115-601632D005A0")
  7604. .FirstOrDefault() ?? "";
  7605. default:
  7606. string psDir = Environment.ExpandEnvironmentVariables(
  7607. (string)Registry.GetValue(
  7608. @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform",
  7609. "TokenStore",
  7610. ""
  7611. )
  7612. );
  7613. string psPath = Path.Combine(psDir, "data.dat");
  7614. ​
  7615. if (string.IsNullOrEmpty(psDir) || !File.Exists(psPath))
  7616. {
  7617. string[] psDirs =
  7618. {
  7619. @"spp\store",
  7620. @"spp\store\2.0",
  7621. @"spp\store_test",
  7622. @"spp\store_test\2.0"
  7623. };
  7624. ​
  7625. foreach (string dir in psDirs)
  7626. {
  7627. psPath = Path.Combine(
  7628. Path.Combine(
  7629. Environment.GetFolderPath(Environment.SpecialFolder.System),
  7630. dir
  7631. ),
  7632. "data.dat"
  7633. );
  7634. ​
  7635. if (File.Exists(psPath)) return psPath;
  7636. }
  7637. }
  7638. else
  7639. {
  7640. return psPath;
  7641. }
  7642. ​
  7643. throw new FileNotFoundException("Failed to locate physical store.");
  7644. }
  7645. }
  7646. ​
  7647. public static string GetTokensPath(PSVersion version)
  7648. {
  7649. switch (version)
  7650. {
  7651. case PSVersion.Vista:
  7652. return Path.Combine(
  7653. Environment.ExpandEnvironmentVariables("%WINDIR%"),
  7654. @"ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareLicensing\tokens.dat"
  7655. );
  7656. case PSVersion.Win7:
  7657. return Path.Combine(
  7658. Environment.ExpandEnvironmentVariables("%WINDIR%"),
  7659. @"ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\tokens.dat"
  7660. );
  7661. default:
  7662. string tokDir = Environment.ExpandEnvironmentVariables(
  7663. (string)Registry.GetValue(
  7664. @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform",
  7665. "TokenStore",
  7666. ""
  7667. )
  7668. );
  7669. string tokPath = Path.Combine(tokDir, "tokens.dat");
  7670. ​
  7671. if (string.IsNullOrEmpty(tokDir) || !File.Exists(tokPath))
  7672. {
  7673. string[] tokDirs =
  7674. {
  7675. @"spp\store",
  7676. @"spp\store\2.0",
  7677. @"spp\store_test",
  7678. @"spp\store_test\2.0"
  7679. };
  7680. ​
  7681. foreach (string dir in tokDirs)
  7682. {
  7683. tokPath = Path.Combine(
  7684. Path.Combine(
  7685. Environment.GetFolderPath(Environment.SpecialFolder.System),
  7686. dir
  7687. ),
  7688. "tokens.dat"
  7689. );
  7690. ​
  7691. if (File.Exists(tokPath)) return tokPath;
  7692. }
  7693. }
  7694. else
  7695. {
  7696. return tokPath;
  7697. }
  7698. ​
  7699. throw new FileNotFoundException("Failed to locate token store.");
  7700. }
  7701. }
  7702. ​
  7703. public static IPhysicalStore GetStore(PSVersion version, bool production)
  7704. {
  7705. string psPath = GetPSPath(version);
  7706. ​
  7707. switch (version)
  7708. {
  7709. case PSVersion.Vista:
  7710. return new PhysicalStoreVista(psPath, production);
  7711. case PSVersion.Win7:
  7712. return new PhysicalStoreWin7(psPath, production);
  7713. default:
  7714. return new PhysicalStoreModern(psPath, production, version);
  7715. }
  7716. }
  7717. ​
  7718. public static ITokenStore GetTokenStore(PSVersion version)
  7719. {
  7720. string tokPath = GetTokensPath(version);
  7721. ​
  7722. return new TokenStoreModern(tokPath);
  7723. }
  7724. ​
  7725. public static void DumpStore(PSVersion version, bool production, string filePath, string encrFilePath)
  7726. {
  7727. bool manageSpp = false;
  7728. ​
  7729. if (encrFilePath == null)
  7730. {
  7731. encrFilePath = GetPSPath(version);
  7732. manageSpp = true;
  7733. KillSPP(version);
  7734. }
  7735. ​
  7736. if (string.IsNullOrEmpty(encrFilePath) || !File.Exists(encrFilePath))
  7737. {
  7738. throw new FileNotFoundException("Store does not exist at expected path '" + encrFilePath + "'.");
  7739. }
  7740. ​
  7741. try
  7742. {
  7743. using (FileStream fs = File.Open(encrFilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
  7744. {
  7745. byte[] encrData = fs.ReadAllBytes();
  7746. File.WriteAllBytes(filePath, PhysStoreCrypto.DecryptPhysicalStore(encrData, production, version));
  7747. }
  7748. Logger.WriteLine("Store dumped successfully to '" + filePath + "'.");
  7749. }
  7750. finally
  7751. {
  7752. if (manageSpp)
  7753. {
  7754. RestartSPP(version);
  7755. }
  7756. }
  7757. }
  7758. ​
  7759. public static void LoadStore(PSVersion version, bool production, string filePath)
  7760. {
  7761. if (string.IsNullOrEmpty(filePath) || !File.Exists(filePath))
  7762. {
  7763. throw new FileNotFoundException("Store file '" + filePath + "' does not exist.");
  7764. }
  7765. ​
  7766. KillSPP(version);
  7767. ​
  7768. using (IPhysicalStore store = GetStore(version, production))
  7769. {
  7770. store.WriteRaw(File.ReadAllBytes(filePath));
  7771. }
  7772. ​
  7773. RestartSPP(version);
  7774. ​
  7775. Logger.WriteLine("Loaded store file successfully.");
  7776. }
  7777. }
  7778. }
  7779. ​
  7780. ​
  7781. // LibTSforge/SPP/SPSys.cs
  7782. namespace LibTSforge.SPP
  7783. {
  7784. using Microsoft.Win32.SafeHandles;
  7785. using System;
  7786. using System.Runtime.InteropServices;
  7787. ​
  7788. public class SPSys
  7789. {
  7790. [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  7791. private static extern IntPtr CreateFile(string lpFileName, uint dwDesiredAccess, uint dwShareMode, IntPtr lpSecurityAttributes, uint dwCreationDisposition, uint dwFlagsAndAttributes, IntPtr hTemplateFile);
  7792. private static SafeFileHandle CreateFileSafe(string device)
  7793. {
  7794. return new SafeFileHandle(CreateFile(device, 0xC0000000, 0, IntPtr.Zero, 3, 0, IntPtr.Zero), true);
  7795. }
  7796. ​
  7797. [return: MarshalAs(UnmanagedType.Bool)]
  7798. [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
  7799. private static extern bool DeviceIoControl([In] SafeFileHandle hDevice, [In] uint dwIoControlCode, [In] IntPtr lpInBuffer, [In] int nInBufferSize, [Out] IntPtr lpOutBuffer, [In] int nOutBufferSize, out int lpBytesReturned, [In] IntPtr lpOverlapped);
  7800. ​
  7801. public static bool IsSpSysRunning()
  7802. {
  7803. SafeFileHandle file = CreateFileSafe(@"\\.\SpDevice");
  7804. IntPtr buffer = Marshal.AllocHGlobal(1);
  7805. int bytesReturned;
  7806. DeviceIoControl(file, 0x80006008, IntPtr.Zero, 0, buffer, 1, out bytesReturned, IntPtr.Zero);
  7807. bool running = Marshal.ReadByte(buffer) != 0;
  7808. Marshal.FreeHGlobal(buffer);
  7809. file.Close();
  7810. return running;
  7811. }
  7812. ​
  7813. public static int ControlSpSys(bool start)
  7814. {
  7815. SafeFileHandle file = CreateFileSafe(@"\\.\SpDevice");
  7816. IntPtr buffer = Marshal.AllocHGlobal(4);
  7817. int bytesReturned;
  7818. DeviceIoControl(file, start ? 0x8000a000 : 0x8000a004, IntPtr.Zero, 0, buffer, 4, out bytesReturned, IntPtr.Zero);
  7819. int result = Marshal.ReadInt32(buffer);
  7820. Marshal.FreeHGlobal(buffer);
  7821. file.Close();
  7822. return result;
  7823. }
  7824. }
  7825. }
  7826. ​
  7827. ​
  7828. // LibTSforge/Crypto/CryptoUtils.cs
  7829. namespace LibTSforge.Crypto
  7830. {
  7831. using System;
  7832. using System.Linq;
  7833. using System.Security.Cryptography;
  7834. ​
  7835. public static class CryptoUtils
  7836. {
  7837. public static byte[] GenerateRandomKey(int len)
  7838. {
  7839. byte[] rand = new byte[len];
  7840. Random r = new Random();
  7841. r.NextBytes(rand);
  7842. ​
  7843. return rand;
  7844. }
  7845. ​
  7846. public static byte[] AESEncrypt(byte[] data, byte[] key)
  7847. {
  7848. using (Aes aes = Aes.Create())
  7849. {
  7850. aes.Key = key;
  7851. aes.Mode = CipherMode.CBC;
  7852. aes.Padding = PaddingMode.PKCS7;
  7853. ​
  7854. ICryptoTransform encryptor = aes.CreateEncryptor(aes.Key, Enumerable.Repeat((byte)0, 16).ToArray());
  7855. byte[] encryptedData = encryptor.TransformFinalBlock(data, 0, data.Length);
  7856. return encryptedData;
  7857. }
  7858. }
  7859. ​
  7860. public static byte[] AESDecrypt(byte[] data, byte[] key)
  7861. {
  7862. using (Aes aes = Aes.Create())
  7863. {
  7864. aes.Key = key;
  7865. aes.Mode = CipherMode.CBC;
  7866. aes.Padding = PaddingMode.PKCS7;
  7867. ​
  7868. ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, Enumerable.Repeat((byte)0, 16).ToArray());
  7869. byte[] decryptedData = decryptor.TransformFinalBlock(data, 0, data.Length);
  7870. return decryptedData;
  7871. }
  7872. }
  7873. ​
  7874. public static byte[] RSADecrypt(byte[] rsaKey, byte[] data)
  7875. {
  7876. ​
  7877. using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
  7878. {
  7879. rsa.ImportCspBlob(rsaKey);
  7880. return rsa.Decrypt(data, false);
  7881. }
  7882. }
  7883. ​
  7884. public static byte[] RSAEncrypt(byte[] rsaKey, byte[] data)
  7885. {
  7886. using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
  7887. {
  7888. rsa.ImportCspBlob(rsaKey);
  7889. return rsa.Encrypt(data, false);
  7890. }
  7891. }
  7892. ​
  7893. public static byte[] RSASign(byte[] rsaKey, byte[] data)
  7894. {
  7895. using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
  7896. {
  7897. rsa.ImportCspBlob(rsaKey);
  7898. RSAPKCS1SignatureFormatter formatter = new RSAPKCS1SignatureFormatter(rsa);
  7899. formatter.SetHashAlgorithm("SHA1");
  7900. ​
  7901. byte[] hash;
  7902. using (SHA1 sha1 = SHA1.Create())
  7903. {
  7904. hash = sha1.ComputeHash(data);
  7905. }
  7906. ​
  7907. return formatter.CreateSignature(hash);
  7908. }
  7909. }
  7910. ​
  7911. public static bool RSAVerifySignature(byte[] rsaKey, byte[] data, byte[] signature)
  7912. {
  7913. using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
  7914. {
  7915. rsa.ImportCspBlob(rsaKey);
  7916. RSAPKCS1SignatureDeformatter deformatter = new RSAPKCS1SignatureDeformatter(rsa);
  7917. deformatter.SetHashAlgorithm("SHA1");
  7918. ​
  7919. byte[] hash;
  7920. using (SHA1 sha1 = SHA1.Create())
  7921. {
  7922. hash = sha1.ComputeHash(data);
  7923. }
  7924. ​
  7925. return deformatter.VerifySignature(hash, signature);
  7926. }
  7927. }
  7928. ​
  7929. public static byte[] HMACSign(byte[] key, byte[] data)
  7930. {
  7931. HMACSHA1 hmac = new HMACSHA1(key);
  7932. return hmac.ComputeHash(data);
  7933. }
  7934. ​
  7935. public static bool HMACVerify(byte[] key, byte[] data, byte[] signature)
  7936. {
  7937. return Enumerable.SequenceEqual(signature, HMACSign(key, data));
  7938. }
  7939. ​
  7940. public static byte[] SaltSHASum(byte[] salt, byte[] data)
  7941. {
  7942. SHA1 sha1 = SHA1.Create();
  7943. byte[] sha_data = salt.Concat(data).ToArray();
  7944. return sha1.ComputeHash(sha_data);
  7945. }
  7946. ​
  7947. public static bool SaltSHAVerify(byte[] salt, byte[] data, byte[] checksum)
  7948. {
  7949. return Enumerable.SequenceEqual(checksum, SaltSHASum(salt, data));
  7950. }
  7951. ​
  7952. public static byte[] SHA256Hash(byte[] data)
  7953. {
  7954. using (SHA256 sha256 = SHA256.Create())
  7955. {
  7956. return sha256.ComputeHash(data);
  7957. }
  7958. }
  7959. }
  7960. }
  7961. ​
  7962. ​
  7963. // LibTSforge/Crypto/Keys.cs
  7964. namespace LibTSforge.Crypto
  7965. {
  7966. public static class Keys
  7967. {
  7968. public static readonly byte[] PRODUCTION = {
  7969. 0x07, 0x02, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00, 0x04, 0x00, 0x00,
  7970. 0x01, 0x00, 0x01, 0x00, 0x29, 0x87, 0xBA, 0x3F, 0x52, 0x90, 0x57, 0xD8, 0x12, 0x26, 0x6B, 0x38,
  7971. 0xB2, 0x3B, 0xF9, 0x67, 0x08, 0x4F, 0xDD, 0x8B, 0xF5, 0xE3, 0x11, 0xB8, 0x61, 0x3A, 0x33, 0x42,
  7972. 0x51, 0x65, 0x05, 0x86, 0x1E, 0x00, 0x41, 0xDE, 0xC5, 0xDD, 0x44, 0x60, 0x56, 0x3D, 0x14, 0x39,
  7973. 0xB7, 0x43, 0x65, 0xE9, 0xF7, 0x2B, 0xA5, 0xF0, 0xA3, 0x65, 0x68, 0xE9, 0xE4, 0x8B, 0x5C, 0x03,
  7974. 0x2D, 0x36, 0xFE, 0x28, 0x4C, 0xD1, 0x3C, 0x3D, 0xC1, 0x90, 0x75, 0xF9, 0x6E, 0x02, 0xE0, 0x58,
  7975. 0x97, 0x6A, 0xCA, 0x80, 0x02, 0x42, 0x3F, 0x6C, 0x15, 0x85, 0x4D, 0x83, 0x23, 0x6A, 0x95, 0x9E,
  7976. 0x38, 0x52, 0x59, 0x38, 0x6A, 0x99, 0xF0, 0xB5, 0xCD, 0x53, 0x7E, 0x08, 0x7C, 0xB5, 0x51, 0xD3,
  7977. 0x8F, 0xA3, 0x0D, 0xA0, 0xFA, 0x8D, 0x87, 0x3C, 0xFC, 0x59, 0x21, 0xD8, 0x2E, 0xD9, 0x97, 0x8B,
  7978. 0x40, 0x60, 0xB1, 0xD7, 0x2B, 0x0A, 0x6E, 0x60, 0xB5, 0x50, 0xCC, 0x3C, 0xB1, 0x57, 0xE4, 0xB7,
  7979. 0xDC, 0x5A, 0x4D, 0xE1, 0x5C, 0xE0, 0x94, 0x4C, 0x5E, 0x28, 0xFF, 0xFA, 0x80, 0x6A, 0x13, 0x53,
  7980. 0x52, 0xDB, 0xF3, 0x04, 0x92, 0x43, 0x38, 0xB9, 0x1B, 0xD9, 0x85, 0x54, 0x7B, 0x14, 0xC7, 0x89,
  7981. 0x16, 0x8A, 0x4B, 0x82, 0xA1, 0x08, 0x02, 0x99, 0x23, 0x48, 0xDD, 0x75, 0x9C, 0xC8, 0xC1, 0xCE,
  7982. 0xB0, 0xD7, 0x1B, 0xD8, 0xFB, 0x2D, 0xA7, 0x2E, 0x47, 0xA7, 0x18, 0x4B, 0xF6, 0x29, 0x69, 0x44,
  7983. 0x30, 0x33, 0xBA, 0xA7, 0x1F, 0xCE, 0x96, 0x9E, 0x40, 0xE1, 0x43, 0xF0, 0xE0, 0x0D, 0x0A, 0x32,
  7984. 0xB4, 0xEE, 0xA1, 0xC3, 0x5E, 0x9B, 0xC7, 0x7F, 0xF5, 0x9D, 0xD8, 0xF2, 0x0F, 0xD9, 0x8F, 0xAD,
  7985. 0x75, 0x0A, 0x00, 0xD5, 0x25, 0x43, 0xF7, 0xAE, 0x51, 0x7F, 0xB7, 0xDE, 0xB7, 0xAD, 0xFB, 0xCE,
  7986. 0x83, 0xE1, 0x81, 0xFF, 0xDD, 0xA2, 0x77, 0xFE, 0xEB, 0x27, 0x1F, 0x10, 0xFA, 0x82, 0x37, 0xF4,
  7987. 0x7E, 0xCC, 0xE2, 0xA1, 0x58, 0xC8, 0xAF, 0x1D, 0x1A, 0x81, 0x31, 0x6E, 0xF4, 0x8B, 0x63, 0x34,
  7988. 0xF3, 0x05, 0x0F, 0xE1, 0xCC, 0x15, 0xDC, 0xA4, 0x28, 0x7A, 0x9E, 0xEB, 0x62, 0xD8, 0xD8, 0x8C,
  7989. 0x85, 0xD7, 0x07, 0x87, 0x90, 0x2F, 0xF7, 0x1C, 0x56, 0x85, 0x2F, 0xEF, 0x32, 0x37, 0x07, 0xAB,
  7990. 0xB0, 0xE6, 0xB5, 0x02, 0x19, 0x35, 0xAF, 0xDB, 0xD4, 0xA2, 0x9C, 0x36, 0x80, 0xC6, 0xDC, 0x82,
  7991. 0x08, 0xE0, 0xC0, 0x5F, 0x3C, 0x59, 0xAA, 0x4E, 0x26, 0x03, 0x29, 0xB3, 0x62, 0x58, 0x41, 0x59,
  7992. 0x3A, 0x37, 0x43, 0x35, 0xE3, 0x9F, 0x34, 0xE2, 0xA1, 0x04, 0x97, 0x12, 0x9D, 0x8C, 0xAD, 0xF7,
  7993. 0xFB, 0x8C, 0xA1, 0xA2, 0xE9, 0xE4, 0xEF, 0xD9, 0xC5, 0xE5, 0xDF, 0x0E, 0xBF, 0x4A, 0xE0, 0x7A,
  7994. 0x1E, 0x10, 0x50, 0x58, 0x63, 0x51, 0xE1, 0xD4, 0xFE, 0x57, 0xB0, 0x9E, 0xD7, 0xDA, 0x8C, 0xED,
  7995. 0x7D, 0x82, 0xAC, 0x2F, 0x25, 0x58, 0x0A, 0x58, 0xE6, 0xA4, 0xF4, 0x57, 0x4B, 0xA4, 0x1B, 0x65,
  7996. 0xB9, 0x4A, 0x87, 0x46, 0xEB, 0x8C, 0x0F, 0x9A, 0x48, 0x90, 0xF9, 0x9F, 0x76, 0x69, 0x03, 0x72,
  7997. 0x77, 0xEC, 0xC1, 0x42, 0x4C, 0x87, 0xDB, 0x0B, 0x3C, 0xD4, 0x74, 0xEF, 0xE5, 0x34, 0xE0, 0x32,
  7998. 0x45, 0xB0, 0xF8, 0xAB, 0xD5, 0x26, 0x21, 0xD7, 0xD2, 0x98, 0x54, 0x8F, 0x64, 0x88, 0x20, 0x2B,
  7999. 0x14, 0xE3, 0x82, 0xD5, 0x2A, 0x4B, 0x8F, 0x4E, 0x35, 0x20, 0x82, 0x7E, 0x1B, 0xFE, 0xFA, 0x2C,
  8000. 0x79, 0x6C, 0x6E, 0x66, 0x94, 0xBB, 0x0A, 0xEB, 0xBA, 0xD9, 0x70, 0x61, 0xE9, 0x47, 0xB5, 0x82,
  8001. 0xFC, 0x18, 0x3C, 0x66, 0x3A, 0x09, 0x2E, 0x1F, 0x61, 0x74, 0xCA, 0xCB, 0xF6, 0x7A, 0x52, 0x37,
  8002. 0x1D, 0xAC, 0x8D, 0x63, 0x69, 0x84, 0x8E, 0xC7, 0x70, 0x59, 0xDD, 0x2D, 0x91, 0x1E, 0xF7, 0xB1,
  8003. 0x56, 0xED, 0x7A, 0x06, 0x9D, 0x5B, 0x33, 0x15, 0xDD, 0x31, 0xD0, 0xE6, 0x16, 0x07, 0x9B, 0xA5,
  8004. 0x94, 0x06, 0x7D, 0xC1, 0xE9, 0xD6, 0xC8, 0xAF, 0xB4, 0x1E, 0x2D, 0x88, 0x06, 0xA7, 0x63, 0xB8,
  8005. 0xCF, 0xC8, 0xA2, 0x6E, 0x84, 0xB3, 0x8D, 0xE5, 0x47, 0xE6, 0x13, 0x63, 0x8E, 0xD1, 0x7F, 0xD4,
  8006. 0x81, 0x44, 0x38, 0xBF
  8007. };
  8008. ​
  8009. public static readonly byte[] TEST = {
  8010. 0x07, 0x02, 0x00, 0x00, 0x00, 0xA4, 0x00, 0x00, 0x52, 0x53, 0x41, 0x32, 0x00, 0x04, 0x00, 0x00,
  8011. 0x01, 0x00, 0x01, 0x00, 0x0F, 0xBE, 0x77, 0xB8, 0xDD, 0x54, 0x36, 0xDD, 0x67, 0xD4, 0x17, 0x66,
  8012. 0xC4, 0x13, 0xD1, 0x3F, 0x1E, 0x16, 0x0C, 0x16, 0x35, 0xAB, 0x6D, 0x3D, 0x34, 0x51, 0xED, 0x3F,
  8013. 0x57, 0x14, 0xB6, 0xB7, 0x08, 0xE9, 0xD9, 0x7A, 0x80, 0xB3, 0x5F, 0x9B, 0x3A, 0xFD, 0x9E, 0x37,
  8014. 0x3A, 0x53, 0x72, 0x67, 0x92, 0x60, 0xC3, 0xEF, 0xB5, 0x8E, 0x1E, 0xCF, 0x9D, 0x9C, 0xD3, 0x90,
  8015. 0xE5, 0xDD, 0xF4, 0xDB, 0xF3, 0xD6, 0x65, 0xB3, 0xC1, 0xBD, 0x69, 0xE1, 0x76, 0x95, 0xD9, 0x37,
  8016. 0xB8, 0x5E, 0xCA, 0x3D, 0x98, 0xFC, 0x50, 0x5C, 0x98, 0xAE, 0xE3, 0x7C, 0x4C, 0x27, 0xC3, 0xD0,
  8017. 0xCE, 0x78, 0x06, 0x51, 0x68, 0x23, 0xE6, 0x70, 0xF8, 0x7C, 0xAE, 0x36, 0xBE, 0x41, 0x57, 0xE2,
  8018. 0xC3, 0x2D, 0xAF, 0x21, 0xB1, 0xB3, 0x15, 0x81, 0x19, 0x26, 0x6B, 0x10, 0xB3, 0xE9, 0xD1, 0x45,
  8019. 0x21, 0x77, 0x9C, 0xF6, 0xE1, 0xDD, 0xB6, 0x78, 0x9D, 0x1D, 0x32, 0x61, 0xBC, 0x2B, 0xDB, 0x86,
  8020. 0xFB, 0x07, 0x24, 0x10, 0x19, 0x4F, 0x09, 0x6D, 0x03, 0x90, 0xD4, 0x5E, 0x30, 0x85, 0xC5, 0x58,
  8021. 0x7E, 0x5D, 0xAE, 0x9F, 0x64, 0x93, 0x04, 0x82, 0x09, 0x0E, 0x1C, 0x66, 0xA8, 0x95, 0x91, 0x51,
  8022. 0xB2, 0xED, 0x9A, 0x75, 0x04, 0x87, 0x50, 0xAC, 0xCC, 0x20, 0x06, 0x45, 0xB9, 0x7B, 0x42, 0x53,
  8023. 0x9A, 0xD1, 0x29, 0xFC, 0xEF, 0xB9, 0x47, 0x16, 0x75, 0x69, 0x05, 0x87, 0x2B, 0xCB, 0x54, 0x9C,
  8024. 0x21, 0x2D, 0x50, 0x8E, 0x12, 0xDE, 0xD3, 0x6B, 0xEC, 0x92, 0xA1, 0xB1, 0xE9, 0x4B, 0xBF, 0x6B,
  8025. 0x9A, 0x38, 0xC7, 0x13, 0xFA, 0x78, 0xA1, 0x3C, 0x1E, 0xBB, 0x38, 0x31, 0xBB, 0x0C, 0x9F, 0x70,
  8026. 0x1A, 0x31, 0x00, 0xD7, 0x5A, 0xA5, 0x84, 0x24, 0x89, 0x80, 0xF5, 0x88, 0xC2, 0x31, 0x18, 0xDC,
  8027. 0x53, 0x05, 0x5D, 0xFA, 0x81, 0xDC, 0xE1, 0xCE, 0xA4, 0xAA, 0xBA, 0x07, 0xDA, 0x28, 0x4F, 0x64,
  8028. 0x0E, 0x84, 0x9B, 0x06, 0xDE, 0xC8, 0x78, 0x66, 0x2F, 0x17, 0x25, 0xA8, 0x9C, 0x99, 0xFC, 0xBC,
  8029. 0x7D, 0x01, 0x42, 0xD7, 0x35, 0xBF, 0x19, 0xF6, 0x3F, 0x20, 0xD9, 0x98, 0x9B, 0x5D, 0xDD, 0x39,
  8030. 0xBE, 0x81, 0x00, 0x0B, 0xDE, 0x6F, 0x14, 0xCA, 0x7E, 0xF8, 0xC0, 0x26, 0xA8, 0x1D, 0xD1, 0x16,
  8031. 0x88, 0x64, 0x87, 0x36, 0x45, 0x37, 0x50, 0xDA, 0x6C, 0xEB, 0x85, 0xB5, 0x43, 0x29, 0x88, 0x6F,
  8032. 0x2F, 0xFE, 0x8D, 0x12, 0x8B, 0x72, 0xB7, 0x5A, 0xCB, 0x66, 0xC2, 0x2E, 0x1D, 0x7D, 0x42, 0xA6,
  8033. 0xF4, 0xFE, 0x26, 0x5D, 0x54, 0x9E, 0x77, 0x1D, 0x97, 0xC2, 0xF3, 0xFD, 0x60, 0xB3, 0x22, 0x88,
  8034. 0xCA, 0x27, 0x99, 0xDF, 0xC8, 0xB1, 0xD7, 0xC6, 0x54, 0xA6, 0x50, 0xB9, 0x54, 0xF5, 0xDE, 0xFE,
  8035. 0xE1, 0x81, 0xA2, 0xBE, 0x81, 0x9F, 0x48, 0xFF, 0x2F, 0xB8, 0xA4, 0xB3, 0x17, 0xD8, 0xC1, 0xB9,
  8036. 0x5D, 0x21, 0x3D, 0xA2, 0xED, 0x1C, 0x96, 0x66, 0xEE, 0x1F, 0x47, 0xCF, 0x62, 0xFA, 0xD6, 0xC1,
  8037. 0x87, 0x5B, 0xC4, 0xE5, 0xD9, 0x08, 0x38, 0x22, 0xFA, 0x21, 0xBD, 0xF2, 0x88, 0xDA, 0xE2, 0x24,
  8038. 0x25, 0x1F, 0xF1, 0x0B, 0x2D, 0xAE, 0x04, 0xBE, 0xA6, 0x7F, 0x75, 0x8C, 0xD9, 0x97, 0xE1, 0xCA,
  8039. 0x35, 0xB9, 0xFC, 0x6F, 0x01, 0x68, 0x11, 0xD3, 0x68, 0x32, 0xD0, 0xC1, 0x69, 0xA3, 0xCF, 0x9B,
  8040. 0x10, 0xE4, 0x69, 0xA7, 0xCF, 0xE1, 0xFE, 0x2A, 0x07, 0x9E, 0xC1, 0x37, 0x84, 0x68, 0xE5, 0xC5,
  8041. 0xAB, 0x25, 0xEC, 0x7D, 0x7D, 0x74, 0x6A, 0xD1, 0xD5, 0x4D, 0xD7, 0xE1, 0x7D, 0xDE, 0x30, 0x4B,
  8042. 0xE6, 0x5D, 0xCD, 0x91, 0x59, 0xF6, 0x80, 0xFD, 0xC6, 0x3C, 0xDD, 0x94, 0x7F, 0x15, 0x9D, 0xEF,
  8043. 0x2F, 0x00, 0x62, 0xD7, 0xDA, 0xB9, 0xB3, 0xD9, 0x8D, 0xE8, 0xD7, 0x3C, 0x96, 0x45, 0x5D, 0x1E,
  8044. 0x50, 0xFB, 0xAA, 0x43, 0xD3, 0x47, 0x77, 0x81, 0xE9, 0x67, 0xE4, 0xFE, 0xDF, 0x42, 0x79, 0xCB,
  8045. 0xA7, 0xAD, 0x5D, 0x48, 0xF5, 0xB7, 0x74, 0x96, 0x12, 0x23, 0x06, 0x70, 0x42, 0x68, 0x7A, 0x44,
  8046. 0xFC, 0xA0, 0x31, 0x7F, 0x68, 0xCA, 0xA2, 0x14, 0x5D, 0xA3, 0xCF, 0x42, 0x23, 0xAB, 0x47, 0xF6,
  8047. 0xB2, 0xFC, 0x6D, 0xF1
  8048. };
  8049. }
  8050. }
  8051. ​
  8052. ​
  8053. // LibTSforge/Crypto/PhysStoreCrypto.cs
  8054. namespace LibTSforge.Crypto
  8055. {
  8056. using System;
  8057. using System.Collections.Generic;
  8058. using System.IO;
  8059. using System.Linq;
  8060. using System.Text;
  8061. ​
  8062. public static class PhysStoreCrypto
  8063. {
  8064. public static byte[] DecryptPhysicalStore(byte[] data, bool production, PSVersion version)
  8065. {
  8066. byte[] rsaKey = production ? Keys.PRODUCTION : Keys.TEST;
  8067. BinaryReader br = new BinaryReader(new MemoryStream(data));
  8068. br.BaseStream.Seek(0x10, SeekOrigin.Begin);
  8069. byte[] aesKeySig = br.ReadBytes(0x80);
  8070. byte[] encAesKey = br.ReadBytes(0x80);
  8071. ​
  8072. if (!CryptoUtils.RSAVerifySignature(rsaKey, encAesKey, aesKeySig))
  8073. {
  8074. throw new Exception("Failed to decrypt physical store.");
  8075. }
  8076. ​
  8077. byte[] aesKey = CryptoUtils.RSADecrypt(rsaKey, encAesKey);
  8078. byte[] decData = CryptoUtils.AESDecrypt(br.ReadBytes((int)br.BaseStream.Length - 0x110), aesKey);
  8079. byte[] hmacKey = decData.Take(0x10).ToArray(); // SHA-1 salt on Vista
  8080. byte[] hmacSig = decData.Skip(0x10).Take(0x14).ToArray(); // SHA-1 hash on Vista
  8081. byte[] psData = decData.Skip(0x28).ToArray();
  8082. ​
  8083. if (version != PSVersion.Vista)
  8084. {
  8085. if (!CryptoUtils.HMACVerify(hmacKey, psData, hmacSig))
  8086. {
  8087. throw new InvalidDataException("Failed to verify HMAC. Physical store is corrupt.");
  8088. }
  8089. }
  8090. else
  8091. {
  8092. if (!CryptoUtils.SaltSHAVerify(hmacKey, psData, hmacSig))
  8093. {
  8094. throw new InvalidDataException("Failed to verify checksum. Physical store is corrupt.");
  8095. }
  8096. }
  8097. ​
  8098. return psData;
  8099. }
  8100. ​
  8101. public static byte[] EncryptPhysicalStore(byte[] data, bool production, PSVersion version)
  8102. {
  8103. Dictionary<PSVersion, int> versionTable = new Dictionary<PSVersion, int>
  8104. {
  8105. {PSVersion.Vista, 2},
  8106. {PSVersion.Win7, 5},
  8107. {PSVersion.Win8, 1},
  8108. {PSVersion.WinBlue, 2},
  8109. {PSVersion.WinModern, 3}
  8110. };
  8111. ​
  8112. byte[] rsaKey = production ? Keys.PRODUCTION : Keys.TEST;
  8113. ​
  8114. byte[] aesKey = Encoding.UTF8.GetBytes("massgrave.dev :3");
  8115. byte[] hmacKey = CryptoUtils.GenerateRandomKey(0x10);
  8116. ​
  8117. byte[] encAesKey = CryptoUtils.RSAEncrypt(rsaKey, aesKey);
  8118. byte[] aesKeySig = CryptoUtils.RSASign(rsaKey, encAesKey);
  8119. byte[] hmacSig = version != PSVersion.Vista ? CryptoUtils.HMACSign(hmacKey, data) : CryptoUtils.SaltSHASum(hmacKey, data);
  8120. ​
  8121. byte[] decData = { };
  8122. decData = decData.Concat(hmacKey).Concat(hmacSig).Concat(BitConverter.GetBytes(0)).Concat(data).ToArray();
  8123. byte[] encData = CryptoUtils.AESEncrypt(decData, aesKey);
  8124. ​
  8125. BinaryWriter bw = new BinaryWriter(new MemoryStream());
  8126. bw.Write(versionTable[version]);
  8127. bw.Write(Encoding.UTF8.GetBytes("UNTRUSTSTORE"));
  8128. bw.Write(aesKeySig);
  8129. bw.Write(encAesKey);
  8130. bw.Write(encData);
  8131. ​
  8132. return bw.GetBytes();
  8133. }
  8134. }
  8135. }
  8136. ​
  8137. ​
  8138. // LibTSforge/Modifiers/GenPKeyInstall.cs
  8139. namespace LibTSforge.Modifiers
  8140. {
  8141. using System;
  8142. using System.IO;
  8143. using Microsoft.Win32;
  8144. using PhysicalStore;
  8145. using SPP;
  8146. using TokenStore;
  8147. ​
  8148. public static class GenPKeyInstall
  8149. {
  8150. private static void WritePkey2005RegistryValues(PSVersion version, ProductKey pkey)
  8151. {
  8152. Logger.WriteLine("Writing registry data for Windows product key...");
  8153. Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "ProductId", pkey.GetPid2());
  8154. Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductId", pkey.GetPid3());
  8155. Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion", "DigitalProductId4", pkey.GetPid4());
  8156. ​
  8157. if (Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Registration", "ProductId", null) != null)
  8158. {
  8159. Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Registration", "ProductId", pkey.GetPid2());
  8160. Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Registration", "DigitalProductId", pkey.GetPid3());
  8161. Registry.SetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Registration", "DigitalProductId4", pkey.GetPid4());
  8162. }
  8163. ​
  8164. if (pkey.Channel == "Volume:CSVLK" && version != PSVersion.Win7)
  8165. {
  8166. Registry.SetValue(@"HKEY_USERS\S-1-5-20\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform", "KmsHostConfig", 1);
  8167. }
  8168. }
  8169. ​
  8170. public static void InstallGenPKey(PSVersion version, bool production, Guid actId)
  8171. {
  8172. if (version == PSVersion.Vista) throw new NotSupportedException("This feature is not supported on Windows Vista/Server 2008.");
  8173. if (actId == Guid.Empty) throw new ArgumentException("Activation ID must be specified for generated product key install.");
  8174. ​
  8175. PKeyConfig pkc = new PKeyConfig();
  8176. try
  8177. {
  8178. pkc.LoadConfig(actId);
  8179. }
  8180. catch (ArgumentException)
  8181. {
  8182. pkc.LoadAllConfigs(SLApi.GetAppId(actId));
  8183. }
  8184. ​
  8185. ProductConfig config;
  8186. pkc.Products.TryGetValue(actId, out config);
  8187. ​
  8188. if (config == null) throw new ArgumentException("Activation ID " + actId + " not found in PKeyConfig.");
  8189. ​
  8190. ProductKey pkey = config.GetRandomKey();
  8191. ​
  8192. Guid instPkeyId = SLApi.GetInstalledPkeyID(actId);
  8193. if (instPkeyId != Guid.Empty) SLApi.UninstallProductKey(instPkeyId);
  8194. ​
  8195. if (pkey.Algorithm == PKeyAlgorithm.PKEY2009)
  8196. {
  8197. uint status = SLApi.InstallProductKey(pkey);
  8198. Logger.WriteLine(string.Format("Installing generated product key {0} status {1:X}", pkey, status));
  8199. ​
  8200. if ((int)status < 0)
  8201. {
  8202. throw new ApplicationException("Failed to install generated product key.");
  8203. }
  8204. ​
  8205. Logger.WriteLine("Successfully deposited generated product key.");
  8206. return;
  8207. }
  8208. ​
  8209. Logger.WriteLine("Key range is PKEY2005, creating fake key data...");
  8210. ​
  8211. if (pkey.Channel == "Volume:GVLK" && version == PSVersion.Win7) throw new NotSupportedException("Fake GVLK generation is not supported on Windows 7.");
  8212. ​
  8213. VariableBag pkb = new VariableBag(version);
  8214. pkb.Blocks.AddRange(new[]
  8215. {
  8216. new CRCBlockModern
  8217. {
  8218. DataType = CRCBlockType.STRING,
  8219. KeyAsStr = "SppPkeyBindingProductKey",
  8220. ValueAsStr = pkey.ToString()
  8221. },
  8222. new CRCBlockModern
  8223. {
  8224. DataType = CRCBlockType.STRING,
  8225. KeyAsStr = "SppPkeyBindingMPC",
  8226. ValueAsStr = pkey.GetMPC()
  8227. },
  8228. new CRCBlockModern {
  8229. DataType = CRCBlockType.BINARY,
  8230. KeyAsStr = "SppPkeyBindingPid2",
  8231. ValueAsStr = pkey.GetPid2()
  8232. },
  8233. new CRCBlockModern
  8234. {
  8235. DataType = CRCBlockType.BINARY,
  8236. KeyAsStr = "SppPkeyBindingPid3",
  8237. Value = pkey.GetPid3()
  8238. },
  8239. new CRCBlockModern
  8240. {
  8241. DataType = CRCBlockType.BINARY,
  8242. KeyAsStr = "SppPkeyBindingPid4",
  8243. Value = pkey.GetPid4()
  8244. },
  8245. new CRCBlockModern
  8246. {
  8247. DataType = CRCBlockType.STRING,
  8248. KeyAsStr = "SppPkeyChannelId",
  8249. ValueAsStr = pkey.Channel
  8250. },
  8251. new CRCBlockModern
  8252. {
  8253. DataType = CRCBlockType.STRING,
  8254. KeyAsStr = "SppPkeyBindingEditionId",
  8255. ValueAsStr = pkey.Edition
  8256. },
  8257. new CRCBlockModern
  8258. {
  8259. DataType = CRCBlockType.BINARY,
  8260. KeyAsStr = (version == PSVersion.Win7) ? "SppPkeyShortAuthenticator" : "SppPkeyPhoneActivationData",
  8261. Value = pkey.GetPhoneData(version)
  8262. },
  8263. new CRCBlockModern
  8264. {
  8265. DataType = CRCBlockType.BINARY,
  8266. KeyAsStr = "SppPkeyBindingMiscData",
  8267. Value = new byte[] { }
  8268. }
  8269. });
  8270. ​
  8271. Guid appId = SLApi.GetAppId(actId);
  8272. string pkeyId = pkey.GetPkeyId().ToString();
  8273. bool isAddon = SLApi.IsAddon(actId);
  8274. string currEdition = SLApi.GetMetaStr(actId, "Family");
  8275. ​
  8276. if (appId == SLApi.WINDOWS_APP_ID && !isAddon)
  8277. {
  8278. SLApi.UninstallAllProductKeys(appId);
  8279. }
  8280. ​
  8281. SPPUtils.KillSPP(version);
  8282. ​
  8283. using (IPhysicalStore ps = SPPUtils.GetStore(version, production))
  8284. {
  8285. using (ITokenStore tks = SPPUtils.GetTokenStore(version))
  8286. {
  8287. Logger.WriteLine("Writing to physical store and token store...");
  8288. ​
  8289. string suffix = (version == PSVersion.Win8 || version == PSVersion.WinBlue || version == PSVersion.WinModern) ? "_--" : "";
  8290. string metSuffix = suffix + "_met";
  8291. ​
  8292. if (appId == SLApi.WINDOWS_APP_ID && !isAddon)
  8293. {
  8294. string edTokName = "msft:spp/token/windows/productkeyid/" + currEdition;
  8295. ​
  8296. TokenMeta edToken = tks.GetMetaEntry(edTokName);
  8297. edToken.Data["windowsComponentEditionPkeyId"] = pkeyId;
  8298. edToken.Data["windowsComponentEditionSkuId"] = actId.ToString();
  8299. tks.SetEntry(edTokName, "xml", edToken.Serialize());
  8300. ​
  8301. WritePkey2005RegistryValues(version, pkey);
  8302. }
  8303. ​
  8304. string uriMapName = "msft:spp/token/PKeyIdUriMapper" + metSuffix;
  8305. TokenMeta uriMap = tks.GetMetaEntry(uriMapName);
  8306. uriMap.Data[pkeyId] = pkey.GetAlgoUri();
  8307. tks.SetEntry(uriMapName, "xml", uriMap.Serialize());
  8308. ​
  8309. string skuMetaName = actId + metSuffix;
  8310. TokenMeta skuMeta = tks.GetMetaEntry(skuMetaName);
  8311. ​
  8312. foreach (string k in skuMeta.Data.Keys)
  8313. {
  8314. if (k.StartsWith("pkeyId_"))
  8315. {
  8316. skuMeta.Data.Remove(k);
  8317. break;
  8318. }
  8319. }
  8320. ​
  8321. skuMeta.Data["pkeyId"] = pkeyId;
  8322. skuMeta.Data["pkeyIdList"] = pkeyId;
  8323. tks.SetEntry(skuMetaName, "xml", skuMeta.Serialize());
  8324. ​
  8325. string psKey = string.Format("SPPSVC\\{0}\\{1}", appId, actId);
  8326. ps.DeleteBlock(psKey, pkeyId);
  8327. ps.AddBlock(new PSBlock
  8328. {
  8329. Type = BlockType.NAMED,
  8330. Flags = (version == PSVersion.WinModern) ? (uint)0x402 : 0x2,
  8331. KeyAsStr = psKey,
  8332. ValueAsStr = pkeyId,
  8333. Data = pkb.Serialize()
  8334. });
  8335. ​
  8336. string cachePath = SPPUtils.GetTokensPath(version).Replace("tokens.dat", @"cache\cache.dat");
  8337. if (File.Exists(cachePath)) File.Delete(cachePath);
  8338. }
  8339. }
  8340. ​
  8341. SLApi.RefreshTrustedTime(actId);
  8342. Logger.WriteLine("Successfully deposited fake product key.");
  8343. }
  8344. }
  8345. }
  8346. ​
  8347. ​
  8348. // LibTSforge/Modifiers/GracePeriodReset.cs
  8349. namespace LibTSforge.Modifiers
  8350. {
  8351. using System.Collections.Generic;
  8352. using System.Linq;
  8353. using PhysicalStore;
  8354. using SPP;
  8355. ​
  8356. public static class GracePeriodReset
  8357. {
  8358. public static void Reset(PSVersion version, bool production)
  8359. {
  8360. SPPUtils.KillSPP(version);
  8361. Logger.WriteLine("Writing TrustedStore data...");
  8362. ​
  8363. using (IPhysicalStore store = SPPUtils.GetStore(version, production))
  8364. {
  8365. string value = "msft:sl/timer";
  8366. List<PSBlock> blocks = store.FindBlocks(value).ToList();
  8367. ​
  8368. foreach (PSBlock block in blocks)
  8369. {
  8370. store.DeleteBlock(block.KeyAsStr, block.ValueAsStr);
  8371. }
  8372. }
  8373. ​
  8374. SPPUtils.RestartSPP(version);
  8375. Logger.WriteLine("Successfully reset all grace and evaluation period timers.");
  8376. }
  8377. }
  8378. }
  8379. ​
  8380. ​
  8381. // LibTSforge/Modifiers/KeyChangeLockDelete.cs
  8382. namespace LibTSforge.Modifiers
  8383. {
  8384. using System.Collections.Generic;
  8385. using System.Linq;
  8386. using PhysicalStore;
  8387. using SPP;
  8388. using System;
  8389. ​
  8390. public static class KeyChangeLockDelete
  8391. {
  8392. public static void Delete(PSVersion version, bool production)
  8393. {
  8394. if (version == PSVersion.Vista) throw new NotSupportedException("This feature is not supported on Windows Vista/Server 2008.");
  8395. ​
  8396. SPPUtils.KillSPP(version);
  8397. Logger.WriteLine("Writing TrustedStore data...");
  8398. using (IPhysicalStore store = SPPUtils.GetStore(version, production))
  8399. {
  8400. List<string> values = new List<string>
  8401. {
  8402. "msft:spp/timebased/AB",
  8403. "msft:spp/timebased/CD"
  8404. };
  8405. List<PSBlock> blocks = new List<PSBlock>();
  8406. foreach (string value in values)
  8407. {
  8408. blocks.AddRange(store.FindBlocks(value).ToList());
  8409. }
  8410. foreach (PSBlock block in blocks)
  8411. {
  8412. store.DeleteBlock(block.KeyAsStr, block.ValueAsStr);
  8413. }
  8414. }
  8415. Logger.WriteLine("Successfully removed the key change lock.");
  8416. }
  8417. }
  8418. }
  8419. ​
  8420. ​
  8421. // LibTSforge/Modifiers/KMSHostCharge.cs
  8422. namespace LibTSforge.Modifiers
  8423. {
  8424. using System;
  8425. using System.IO;
  8426. using PhysicalStore;
  8427. using SPP;
  8428. ​
  8429. public static class KMSHostCharge
  8430. {
  8431. public static void Charge(PSVersion version, bool production, Guid actId)
  8432. {
  8433. if (actId == Guid.Empty)
  8434. {
  8435. actId = SLApi.GetDefaultActivationID(SLApi.WINDOWS_APP_ID, true);
  8436. ​
  8437. if (actId == Guid.Empty)
  8438. {
  8439. throw new NotSupportedException("No applicable activation IDs found.");
  8440. }
  8441. }
  8442. ​
  8443. if (SLApi.GetPKeyChannel(SLApi.GetInstalledPkeyID(actId)) != "Volume:CSVLK")
  8444. {
  8445. throw new NotSupportedException("Non-Volume:CSVLK product key installed.");
  8446. }
  8447. ​
  8448. Guid appId = SLApi.GetAppId(actId);
  8449. int totalClients = 50;
  8450. int currClients = 25;
  8451. byte[] hwidBlock = Constants.UniversalHWIDBlock;
  8452. string key = string.Format("SPPSVC\\{0}", appId);
  8453. long ldapTimestamp = DateTime.Now.ToFileTime();
  8454. ​
  8455. byte[] cmidGuids = { };
  8456. byte[] reqCounts = { };
  8457. byte[] kmsChargeData = { };
  8458. ​
  8459. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  8460. ​
  8461. if (version == PSVersion.Vista)
  8462. {
  8463. writer.Write(new byte[44]);
  8464. writer.Seek(0, SeekOrigin.Begin);
  8465. ​
  8466. writer.Write(totalClients);
  8467. writer.Write(43200);
  8468. writer.Write(32);
  8469. ​
  8470. writer.Seek(20, SeekOrigin.Begin);
  8471. writer.Write((byte)currClients);
  8472. ​
  8473. writer.Seek(32, SeekOrigin.Begin);
  8474. writer.Write((byte)currClients);
  8475. ​
  8476. writer.Seek(0, SeekOrigin.End);
  8477. ​
  8478. for (int i = 0; i < currClients; i++)
  8479. {
  8480. writer.Write(Guid.NewGuid().ToByteArray());
  8481. writer.Write(ldapTimestamp - (10 * (i + 1)));
  8482. }
  8483. ​
  8484. kmsChargeData = writer.GetBytes();
  8485. }
  8486. else
  8487. {
  8488. for (int i = 0; i < currClients; i++)
  8489. {
  8490. writer.Write(ldapTimestamp - (10 * (i + 1)));
  8491. writer.Write(Guid.NewGuid().ToByteArray());
  8492. }
  8493. ​
  8494. cmidGuids = writer.GetBytes();
  8495. ​
  8496. writer = new BinaryWriter(new MemoryStream());
  8497. ​
  8498. writer.Write(new byte[40]);
  8499. ​
  8500. writer.Seek(4, SeekOrigin.Begin);
  8501. writer.Write((byte)currClients);
  8502. ​
  8503. writer.Seek(24, SeekOrigin.Begin);
  8504. writer.Write((byte)currClients);
  8505. ​
  8506. reqCounts = writer.GetBytes();
  8507. }
  8508. ​
  8509. SPPUtils.KillSPP(version);
  8510. ​
  8511. Logger.WriteLine("Writing TrustedStore data...");
  8512. ​
  8513. using (IPhysicalStore store = SPPUtils.GetStore(version, production))
  8514. {
  8515. if (version != PSVersion.Vista)
  8516. {
  8517. VariableBag kmsCountData = new VariableBag(version);
  8518. kmsCountData.Blocks.AddRange(new[]
  8519. {
  8520. new CRCBlockModern
  8521. {
  8522. DataType = CRCBlockType.BINARY,
  8523. KeyAsStr = "SppBindingLicenseData",
  8524. Value = hwidBlock
  8525. },
  8526. new CRCBlockModern
  8527. {
  8528. DataType = CRCBlockType.UINT,
  8529. Key = new byte[] { },
  8530. ValueAsInt = (uint)totalClients
  8531. },
  8532. new CRCBlockModern
  8533. {
  8534. DataType = CRCBlockType.UINT,
  8535. Key = new byte[] { },
  8536. ValueAsInt = 1051200000
  8537. },
  8538. new CRCBlockModern
  8539. {
  8540. DataType = CRCBlockType.UINT,
  8541. Key = new byte[] { },
  8542. ValueAsInt = (uint)currClients
  8543. },
  8544. new CRCBlockModern
  8545. {
  8546. DataType = CRCBlockType.BINARY,
  8547. Key = new byte[] { },
  8548. Value = cmidGuids
  8549. },
  8550. new CRCBlockModern
  8551. {
  8552. DataType = CRCBlockType.BINARY,
  8553. Key = new byte[] { },
  8554. Value = reqCounts
  8555. }
  8556. });
  8557. ​
  8558. kmsChargeData = kmsCountData.Serialize();
  8559. }
  8560. ​
  8561. string countVal = version == PSVersion.Vista ? "C8F6FFF1-79CE-404C-B150-F97991273DF1" : string.Format("msft:spp/kms/host/2.0/store/counters/{0}", appId);
  8562. ​
  8563. store.DeleteBlock(key, countVal);
  8564. store.AddBlock(new PSBlock
  8565. {
  8566. Type = BlockType.NAMED,
  8567. Flags = (version == PSVersion.WinModern) ? (uint)0x400 : 0,
  8568. KeyAsStr = key,
  8569. ValueAsStr = countVal,
  8570. Data = kmsChargeData
  8571. });
  8572. ​
  8573. Logger.WriteLine(string.Format("Set charge count to {0} successfully.", currClients));
  8574. }
  8575. ​
  8576. SPPUtils.RestartSPP(version);
  8577. }
  8578. }
  8579. }
  8580. ​
  8581. ​
  8582. // LibTSforge/Modifiers/RearmReset.cs
  8583. namespace LibTSforge.Modifiers
  8584. {
  8585. using System.Collections.Generic;
  8586. using System.Linq;
  8587. using PhysicalStore;
  8588. using SPP;
  8589. ​
  8590. public static class RearmReset
  8591. {
  8592. public static void Reset(PSVersion version, bool production)
  8593. {
  8594. SPPUtils.KillSPP(version);
  8595. ​
  8596. Logger.WriteLine("Writing TrustedStore data...");
  8597. ​
  8598. using (IPhysicalStore store = SPPUtils.GetStore(version, production))
  8599. {
  8600. List<PSBlock> blocks;
  8601. ​
  8602. if (version == PSVersion.Vista)
  8603. {
  8604. blocks = store.FindBlocks("740D70D8-6448-4b2f-9063-4A7A463600C5").ToList();
  8605. }
  8606. else if (version == PSVersion.Win7)
  8607. {
  8608. blocks = store.FindBlocks(0xA0000).ToList();
  8609. }
  8610. else
  8611. {
  8612. blocks = store.FindBlocks("__##USERSEP-RESERVED##__$$REARM-COUNT$$").ToList();
  8613. }
  8614. ​
  8615. foreach (PSBlock block in blocks)
  8616. {
  8617. if (version == PSVersion.Vista)
  8618. {
  8619. store.DeleteBlock(block.KeyAsStr, block.ValueAsStr);
  8620. }
  8621. else if (version == PSVersion.Win7)
  8622. {
  8623. store.SetBlock(block.KeyAsStr, block.ValueAsInt, new byte[8]);
  8624. }
  8625. else
  8626. {
  8627. store.SetBlock(block.KeyAsStr, block.ValueAsStr, new byte[8]);
  8628. }
  8629. }
  8630. ​
  8631. Logger.WriteLine("Successfully reset all rearm counters.");
  8632. }
  8633. }
  8634. }
  8635. }
  8636. ​
  8637. ​
  8638. // LibTSforge/Modifiers/SetIIDParams.cs
  8639. namespace LibTSforge.Modifiers
  8640. {
  8641. using PhysicalStore;
  8642. using SPP;
  8643. using System.IO;
  8644. using System;
  8645. ​
  8646. public static class SetIIDParams
  8647. {
  8648. public static void SetParams(PSVersion version, bool production, Guid actId, PKeyAlgorithm algorithm, int group, int serial, ulong security)
  8649. {
  8650. if (version == PSVersion.Vista) throw new NotSupportedException("This feature is not supported on Windows Vista/Server 2008.");
  8651. ​
  8652. Guid appId;
  8653. ​
  8654. if (actId == Guid.Empty)
  8655. {
  8656. appId = SLApi.WINDOWS_APP_ID;
  8657. actId = SLApi.GetDefaultActivationID(appId, true);
  8658. ​
  8659. if (actId == Guid.Empty)
  8660. {
  8661. throw new Exception("No applicable activation IDs found.");
  8662. }
  8663. }
  8664. else
  8665. {
  8666. appId = SLApi.GetAppId(actId);
  8667. }
  8668. ​
  8669. Guid pkeyId = SLApi.GetInstalledPkeyID(actId);
  8670. ​
  8671. SPPUtils.KillSPP(version);
  8672. ​
  8673. Logger.WriteLine("Writing TrustedStore data...");
  8674. ​
  8675. using (IPhysicalStore store = SPPUtils.GetStore(version, production))
  8676. {
  8677. string key = string.Format("SPPSVC\\{0}\\{1}", appId, actId);
  8678. PSBlock keyBlock = store.GetBlock(key, pkeyId.ToString());
  8679. ​
  8680. if (keyBlock == null)
  8681. {
  8682. throw new InvalidDataException("Failed to get product key data for activation ID " + actId + ".");
  8683. }
  8684. ​
  8685. VariableBag pkb = new VariableBag(keyBlock.Data, version);
  8686. ​
  8687. ProductKey pkey = new ProductKey
  8688. {
  8689. Group = group,
  8690. Serial = serial,
  8691. Security = security,
  8692. Algorithm = algorithm,
  8693. Upgrade = false
  8694. };
  8695. ​
  8696. string blockName = version == PSVersion.Win7 ? "SppPkeyShortAuthenticator" : "SppPkeyPhoneActivationData";
  8697. pkb.SetBlock(blockName, pkey.GetPhoneData(version));
  8698. store.SetBlock(key, pkeyId.ToString(), pkb.Serialize());
  8699. }
  8700. ​
  8701. Logger.WriteLine("Successfully set IID parameters.");
  8702. }
  8703. }
  8704. }
  8705. ​
  8706. ​
  8707. // LibTSforge/Modifiers/TamperedFlagsDelete.cs
  8708. namespace LibTSforge.Modifiers
  8709. {
  8710. using System.Linq;
  8711. using PhysicalStore;
  8712. using SPP;
  8713. ​
  8714. public static class TamperedFlagsDelete
  8715. {
  8716. public static void DeleteTamperFlags(PSVersion version, bool production)
  8717. {
  8718. SPPUtils.KillSPP(version);
  8719. ​
  8720. Logger.WriteLine("Writing TrustedStore data...");
  8721. ​
  8722. using (IPhysicalStore store = SPPUtils.GetStore(version, production))
  8723. {
  8724. if (version == PSVersion.Vista)
  8725. {
  8726. DeleteFlag(store, "6BE8425B-E3CF-4e86-A6AF-5863E3DCB606");
  8727. }
  8728. else if (version == PSVersion.Win7)
  8729. {
  8730. SetFlag(store, 0xA0001);
  8731. }
  8732. else
  8733. {
  8734. DeleteFlag(store, "__##USERSEP-RESERVED##__$$RECREATED-FLAG$$");
  8735. DeleteFlag(store, "__##USERSEP-RESERVED##__$$RECOVERED-FLAG$$");
  8736. }
  8737. ​
  8738. Logger.WriteLine("Successfully cleared the tamper state.");
  8739. }
  8740. ​
  8741. SPPUtils.RestartSPP(version);
  8742. }
  8743. ​
  8744. private static void DeleteFlag(IPhysicalStore store, string flag)
  8745. {
  8746. store.FindBlocks(flag).ToList().ForEach(block => store.DeleteBlock(block.KeyAsStr, block.ValueAsStr));
  8747. }
  8748. ​
  8749. private static void SetFlag(IPhysicalStore store, uint flag)
  8750. {
  8751. store.FindBlocks(flag).ToList().ForEach(block => store.SetBlock(block.KeyAsStr, block.ValueAsInt, new byte[8]));
  8752. }
  8753. }
  8754. }
  8755. ​
  8756. ​
  8757. // LibTSforge/Modifiers/UniqueIdDelete.cs
  8758. namespace LibTSforge.Modifiers
  8759. {
  8760. using System;
  8761. using PhysicalStore;
  8762. using SPP;
  8763. ​
  8764. public static class UniqueIdDelete
  8765. {
  8766. public static void DeleteUniqueId(PSVersion version, bool production, Guid actId)
  8767. {
  8768. if (version == PSVersion.Vista) throw new NotSupportedException("This feature is not supported on Windows Vista/Server 2008.");
  8769. ​
  8770. Guid appId;
  8771. ​
  8772. if (actId == Guid.Empty)
  8773. {
  8774. appId = SLApi.WINDOWS_APP_ID;
  8775. actId = SLApi.GetDefaultActivationID(appId, true);
  8776. ​
  8777. if (actId == Guid.Empty)
  8778. {
  8779. throw new Exception("No applicable activation IDs found.");
  8780. }
  8781. }
  8782. else
  8783. {
  8784. appId = SLApi.GetAppId(actId);
  8785. }
  8786. ​
  8787. Guid pkeyId = SLApi.GetInstalledPkeyID(actId);
  8788. ​
  8789. SPPUtils.KillSPP(version);
  8790. ​
  8791. Logger.WriteLine("Writing TrustedStore data...");
  8792. ​
  8793. using (IPhysicalStore store = SPPUtils.GetStore(version, production))
  8794. {
  8795. string key = string.Format("SPPSVC\\{0}\\{1}", appId, actId);
  8796. PSBlock keyBlock = store.GetBlock(key, pkeyId.ToString());
  8797. ​
  8798. if (keyBlock == null)
  8799. {
  8800. throw new Exception("No product key found.");
  8801. }
  8802. ​
  8803. VariableBag pkb = new VariableBag(keyBlock.Data, version);
  8804. ​
  8805. pkb.DeleteBlock("SppPkeyUniqueIdToken");
  8806. ​
  8807. store.SetBlock(key, pkeyId.ToString(), pkb.Serialize());
  8808. }
  8809. ​
  8810. Logger.WriteLine("Successfully removed Unique ID for product key ID " + pkeyId);
  8811. }
  8812. }
  8813. }
  8814. ​
  8815. ​
  8816. // LibTSforge/Activators/KMS4K.cs
  8817. namespace LibTSforge.Activators
  8818. {
  8819. using System;
  8820. using System.IO;
  8821. using PhysicalStore;
  8822. using SPP;
  8823. ​
  8824. public class KMS4k
  8825. {
  8826. public static void Activate(PSVersion version, bool production, Guid actId)
  8827. {
  8828. Guid appId;
  8829. if (actId == Guid.Empty)
  8830. {
  8831. appId = SLApi.WINDOWS_APP_ID;
  8832. actId = SLApi.GetDefaultActivationID(appId, true);
  8833. ​
  8834. if (actId == Guid.Empty)
  8835. {
  8836. throw new NotSupportedException("No applicable activation IDs found.");
  8837. }
  8838. }
  8839. else
  8840. {
  8841. appId = SLApi.GetAppId(actId);
  8842. }
  8843. ​
  8844. if (SLApi.GetPKeyChannel(SLApi.GetInstalledPkeyID(actId)) != "Volume:GVLK")
  8845. {
  8846. throw new NotSupportedException("Non-Volume:GVLK product key installed.");
  8847. }
  8848. ​
  8849. SPPUtils.KillSPP(version);
  8850. ​
  8851. Logger.WriteLine("Writing TrustedStore data...");
  8852. ​
  8853. using (IPhysicalStore store = SPPUtils.GetStore(version, production))
  8854. {
  8855. string key = string.Format("SPPSVC\\{0}\\{1}", appId, actId);
  8856. ​
  8857. ulong unknown = 0;
  8858. ulong time1;
  8859. ulong time2 = (ulong)DateTime.UtcNow.ToFileTime();
  8860. ulong expiry = Constants.TimerMax;
  8861. ​
  8862. if (version == PSVersion.Vista || version == PSVersion.Win7)
  8863. {
  8864. unknown = 0x800000000;
  8865. time1 = 0;
  8866. }
  8867. else
  8868. {
  8869. long creationTime = BitConverter.ToInt64(store.GetBlock("__##USERSEP##\\$$_RESERVED_$$\\NAMESPACE__", "__##USERSEP-RESERVED##__$$GLOBAL-CREATION-TIME$$").Data, 0);
  8870. long tickCount = BitConverter.ToInt64(store.GetBlock("__##USERSEP##\\$$_RESERVED_$$\\NAMESPACE__", "__##USERSEP-RESERVED##__$$GLOBAL-TICKCOUNT-UPTIME$$").Data, 0);
  8871. long deltaTime = BitConverter.ToInt64(store.GetBlock(key, "__##USERSEP-RESERVED##__$$UP-TIME-DELTA$$").Data, 0);
  8872. ​
  8873. time1 = (ulong)(creationTime + tickCount + deltaTime);
  8874. time2 /= 10000;
  8875. expiry /= 10000;
  8876. }
  8877. ​
  8878. if (version == PSVersion.Vista)
  8879. {
  8880. VistaTimer vistaTimer = new VistaTimer
  8881. {
  8882. Time = time2,
  8883. Expiry = Constants.TimerMax
  8884. };
  8885. ​
  8886. string vistaTimerName = string.Format("msft:sl/timer/VLExpiration/VOLUME/{0}/{1}", appId, actId);
  8887. ​
  8888. store.DeleteBlock(key, vistaTimerName);
  8889. store.DeleteBlock(key, actId.ToString());
  8890. ​
  8891. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  8892. writer.Write(Constants.KMSv4Response.Length);
  8893. writer.Write(Constants.KMSv4Response);
  8894. writer.Write(Constants.UniversalHWIDBlock);
  8895. byte[] kmsData = writer.GetBytes();
  8896. ​
  8897. store.AddBlocks(new[]
  8898. {
  8899. new PSBlock
  8900. {
  8901. Type = BlockType.TIMER,
  8902. Flags = 0,
  8903. KeyAsStr = key,
  8904. ValueAsStr = vistaTimerName,
  8905. Data = vistaTimer.CastToArray()
  8906. },
  8907. new PSBlock
  8908. {
  8909. Type = BlockType.NAMED,
  8910. Flags = 0,
  8911. KeyAsStr = key,
  8912. ValueAsStr = actId.ToString(),
  8913. Data = kmsData
  8914. }
  8915. });
  8916. }
  8917. else
  8918. {
  8919. byte[] hwidBlock = Constants.UniversalHWIDBlock;
  8920. byte[] kmsResp;
  8921. ​
  8922. switch (version)
  8923. {
  8924. case PSVersion.Win7:
  8925. kmsResp = Constants.KMSv4Response;
  8926. break;
  8927. case PSVersion.Win8:
  8928. kmsResp = Constants.KMSv5Response;
  8929. break;
  8930. case PSVersion.WinBlue:
  8931. case PSVersion.WinModern:
  8932. kmsResp = Constants.KMSv6Response;
  8933. break;
  8934. default:
  8935. throw new NotSupportedException("Unsupported PSVersion.");
  8936. }
  8937. ​
  8938. VariableBag kmsBinding = new VariableBag(version);
  8939. ​
  8940. kmsBinding.Blocks.AddRange(new[]
  8941. {
  8942. new CRCBlockModern
  8943. {
  8944. DataType = CRCBlockType.BINARY,
  8945. Key = new byte[] { },
  8946. Value = kmsResp
  8947. },
  8948. new CRCBlockModern
  8949. {
  8950. DataType = CRCBlockType.STRING,
  8951. Key = new byte[] { },
  8952. ValueAsStr = "msft:rm/algorithm/hwid/4.0"
  8953. },
  8954. new CRCBlockModern
  8955. {
  8956. DataType = CRCBlockType.BINARY,
  8957. KeyAsStr = "SppBindingLicenseData",
  8958. Value = hwidBlock
  8959. }
  8960. });
  8961. ​
  8962. if (version == PSVersion.WinModern)
  8963. {
  8964. kmsBinding.Blocks.AddRange(new[]
  8965. {
  8966. new CRCBlockModern
  8967. {
  8968. DataType = CRCBlockType.STRING,
  8969. Key = new byte[] { },
  8970. ValueAsStr = "massgrave.dev"
  8971. },
  8972. new CRCBlockModern
  8973. {
  8974. DataType = CRCBlockType.STRING,
  8975. Key = new byte[] { },
  8976. ValueAsStr = "6969"
  8977. }
  8978. });
  8979. }
  8980. ​
  8981. byte[] kmsBindingData = kmsBinding.Serialize();
  8982. ​
  8983. Timer kmsTimer = new Timer
  8984. {
  8985. Unknown = unknown,
  8986. Time1 = time1,
  8987. Time2 = time2,
  8988. Expiry = expiry
  8989. };
  8990. ​
  8991. string storeVal = string.Format("msft:spp/kms/bind/2.0/store/{0}/{1}", appId, actId);
  8992. string timerVal = string.Format("msft:spp/kms/bind/2.0/timer/{0}/{1}", appId, actId);
  8993. ​
  8994. store.DeleteBlock(key, storeVal);
  8995. store.DeleteBlock(key, timerVal);
  8996. ​
  8997. store.AddBlocks(new[]
  8998. {
  8999. new PSBlock
  9000. {
  9001. Type = BlockType.NAMED,
  9002. Flags = (version == PSVersion.WinModern) ? (uint)0x400 : 0,
  9003. KeyAsStr = key,
  9004. ValueAsStr = storeVal,
  9005. Data = kmsBindingData
  9006. },
  9007. new PSBlock
  9008. {
  9009. Type = BlockType.TIMER,
  9010. Flags = (version == PSVersion.Win7) ? (uint)0 : 0x4,
  9011. KeyAsStr = key,
  9012. ValueAsStr = timerVal,
  9013. Data = kmsTimer.CastToArray()
  9014. }
  9015. });
  9016. }
  9017. }
  9018. ​
  9019. SPPUtils.RestartSPP(version);
  9020. SLApi.FireStateChangedEvent(appId);
  9021. Logger.WriteLine("Activated using KMS4k successfully.");
  9022. }
  9023. }
  9024. }
  9025. ​
  9026. ​
  9027. // LibTSforge/Activators/ZeroCID.cs
  9028. namespace LibTSforge.Activators
  9029. {
  9030. using System;
  9031. using System.IO;
  9032. using System.Linq;
  9033. using Crypto;
  9034. using PhysicalStore;
  9035. using SPP;
  9036. ​
  9037. public static class ZeroCID
  9038. {
  9039. private static void Deposit(Guid actId, string instId)
  9040. {
  9041. uint status = SLApi.DepositConfirmationID(actId, instId, Constants.ZeroCID);
  9042. Logger.WriteLine(string.Format("Depositing fake CID status {0:X}", status));
  9043. ​
  9044. if (status != 0)
  9045. {
  9046. throw new InvalidOperationException("Failed to deposit fake CID.");
  9047. }
  9048. }
  9049. ​
  9050. public static void Activate(PSVersion version, bool production, Guid actId)
  9051. {
  9052. Guid appId;
  9053. ​
  9054. if (actId == Guid.Empty)
  9055. {
  9056. appId = SLApi.WINDOWS_APP_ID;
  9057. actId = SLApi.GetDefaultActivationID(appId, false);
  9058. ​
  9059. if (actId == Guid.Empty)
  9060. {
  9061. throw new NotSupportedException("No applicable activation IDs found.");
  9062. }
  9063. }
  9064. else
  9065. {
  9066. appId = SLApi.GetAppId(actId);
  9067. }
  9068. ​
  9069. if (!SLApi.IsPhoneActivatable(actId))
  9070. {
  9071. throw new NotSupportedException("Phone license is unavailable for this product.");
  9072. }
  9073. ​
  9074. string instId = SLApi.GetInstallationID(actId);
  9075. Guid pkeyId = SLApi.GetInstalledPkeyID(actId);
  9076. ​
  9077. if (version == PSVersion.Vista || version == PSVersion.Win7)
  9078. {
  9079. Deposit(actId, instId);
  9080. }
  9081. ​
  9082. SPPUtils.KillSPP(version);
  9083. ​
  9084. Logger.WriteLine("Writing TrustedStore data...");
  9085. ​
  9086. using (IPhysicalStore store = SPPUtils.GetStore(version, production))
  9087. {
  9088. byte[] hwidBlock = Constants.UniversalHWIDBlock;
  9089. ​
  9090. Logger.WriteLine("Activation ID: " + actId);
  9091. Logger.WriteLine("Installation ID: " + instId);
  9092. Logger.WriteLine("Product Key ID: " + pkeyId);
  9093. ​
  9094. byte[] iidHash;
  9095. ​
  9096. if (version == PSVersion.Vista)
  9097. {
  9098. iidHash = CryptoUtils.SHA256Hash(Utils.EncodeString(instId)).Take(0x10).ToArray();
  9099. }
  9100. else if (version == PSVersion.Win7)
  9101. {
  9102. iidHash = CryptoUtils.SHA256Hash(Utils.EncodeString(instId));
  9103. }
  9104. else
  9105. {
  9106. iidHash = CryptoUtils.SHA256Hash(Utils.EncodeString(instId + '\0' + Constants.ZeroCID));
  9107. }
  9108. ​
  9109. string key = string.Format("SPPSVC\\{0}\\{1}", appId, actId);
  9110. PSBlock keyBlock = store.GetBlock(key, pkeyId.ToString());
  9111. ​
  9112. if (keyBlock == null)
  9113. {
  9114. throw new InvalidDataException("Failed to get product key data for activation ID " + actId + ".");
  9115. }
  9116. ​
  9117. VariableBag pkb = new VariableBag(keyBlock.Data, version);
  9118. ​
  9119. byte[] pkeyData;
  9120. ​
  9121. if (version == PSVersion.Vista)
  9122. {
  9123. pkeyData = pkb.GetBlock("PKeyBasicInfo").Value;
  9124. string uniqueId = Utils.DecodeString(pkeyData.Skip(0x120).Take(0x80).ToArray());
  9125. string extPid = Utils.DecodeString(pkeyData.Skip(0x1A0).Take(0x80).ToArray());
  9126. ​
  9127. uint group;
  9128. uint.TryParse(extPid.Split('-')[1], out group);
  9129. ​
  9130. if (group == 0)
  9131. {
  9132. throw new FormatException("Extended PID has invalid format.");
  9133. }
  9134. ​
  9135. ulong shortauth;
  9136. ​
  9137. try
  9138. {
  9139. shortauth = BitConverter.ToUInt64(Convert.FromBase64String(uniqueId.Split('&')[1]), 0);
  9140. }
  9141. catch
  9142. {
  9143. throw new FormatException("Key Unique ID has invalid format.");
  9144. }
  9145. ​
  9146. shortauth |= (ulong)group << 41;
  9147. pkeyData = BitConverter.GetBytes(shortauth);
  9148. }
  9149. else if (version == PSVersion.Win7)
  9150. {
  9151. pkeyData = pkb.GetBlock("SppPkeyShortAuthenticator").Value;
  9152. }
  9153. else
  9154. {
  9155. pkeyData = pkb.GetBlock("SppPkeyPhoneActivationData").Value;
  9156. }
  9157. ​
  9158. pkb.DeleteBlock("SppPkeyVirtual");
  9159. store.SetBlock(key, pkeyId.ToString(), pkb.Serialize());
  9160. ​
  9161. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  9162. writer.Write(iidHash.Length);
  9163. writer.Write(iidHash);
  9164. writer.Write(hwidBlock.Length);
  9165. writer.Write(hwidBlock);
  9166. byte[] tsHwidData = writer.GetBytes();
  9167. ​
  9168. writer = new BinaryWriter(new MemoryStream());
  9169. writer.Write(iidHash.Length);
  9170. writer.Write(iidHash);
  9171. writer.Write(pkeyData.Length);
  9172. writer.Write(pkeyData);
  9173. byte[] tsPkeyInfoData = writer.GetBytes();
  9174. ​
  9175. string phoneVersion = version == PSVersion.Vista ? "6.0" : "7.0";
  9176. Guid indexSlid = version == PSVersion.Vista ? actId : pkeyId;
  9177. string hwidBlockName = string.Format("msft:Windows/{0}/Phone/Cached/HwidBlock/{1}", phoneVersion, indexSlid);
  9178. string pkeyInfoName = string.Format("msft:Windows/{0}/Phone/Cached/PKeyInfo/{1}", phoneVersion, indexSlid);
  9179. ​
  9180. store.DeleteBlock(key, hwidBlockName);
  9181. store.DeleteBlock(key, pkeyInfoName);
  9182. ​
  9183. store.AddBlocks(new[] {
  9184. new PSBlock
  9185. {
  9186. Type = BlockType.NAMED,
  9187. Flags = 0,
  9188. KeyAsStr = key,
  9189. ValueAsStr = hwidBlockName,
  9190. Data = tsHwidData
  9191. },
  9192. new PSBlock
  9193. {
  9194. Type = BlockType.NAMED,
  9195. Flags = 0,
  9196. KeyAsStr = key,
  9197. ValueAsStr = pkeyInfoName,
  9198. Data = tsPkeyInfoData
  9199. }
  9200. });
  9201. }
  9202. ​
  9203. if (version != PSVersion.Vista && version != PSVersion.Win7)
  9204. {
  9205. Deposit(actId, instId);
  9206. }
  9207. ​
  9208. SPPUtils.RestartSPP(version);
  9209. SLApi.FireStateChangedEvent(appId);
  9210. Logger.WriteLine("Activated using ZeroCID successfully.");
  9211. }
  9212. }
  9213. }
  9214. ​
  9215. ​
  9216. // LibTSforge/TokenStore/Common.cs
  9217. namespace LibTSforge.TokenStore
  9218. {
  9219. using System.Collections.Generic;
  9220. using System.IO;
  9221. ​
  9222. public class TokenEntry
  9223. {
  9224. public string Name;
  9225. public string Extension;
  9226. public byte[] Data;
  9227. public bool Populated;
  9228. }
  9229. ​
  9230. public class TokenMeta
  9231. {
  9232. public string Name;
  9233. public readonly Dictionary<string, string> Data = new Dictionary<string, string>();
  9234. ​
  9235. public byte[] Serialize()
  9236. {
  9237. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  9238. writer.Write(1);
  9239. byte[] nameBytes = Utils.EncodeString(Name);
  9240. writer.Write(nameBytes.Length);
  9241. writer.Write(nameBytes);
  9242. ​
  9243. foreach (KeyValuePair<string, string> kv in Data)
  9244. {
  9245. byte[] keyBytes = Utils.EncodeString(kv.Key);
  9246. byte[] valueBytes = Utils.EncodeString(kv.Value);
  9247. writer.Write(keyBytes.Length);
  9248. writer.Write(valueBytes.Length);
  9249. writer.Write(keyBytes);
  9250. writer.Write(valueBytes);
  9251. }
  9252. ​
  9253. return writer.GetBytes();
  9254. }
  9255. ​
  9256. private void Deserialize(byte[] data)
  9257. {
  9258. BinaryReader reader = new BinaryReader(new MemoryStream(data));
  9259. reader.ReadInt32();
  9260. int nameLen = reader.ReadInt32();
  9261. Name = reader.ReadNullTerminatedString(nameLen);
  9262. ​
  9263. while (reader.BaseStream.Position < data.Length - 0x8)
  9264. {
  9265. int keyLen = reader.ReadInt32();
  9266. int valueLen = reader.ReadInt32();
  9267. string key = reader.ReadNullTerminatedString(keyLen);
  9268. string value = reader.ReadNullTerminatedString(valueLen);
  9269. Data[key] = value;
  9270. }
  9271. }
  9272. ​
  9273. public TokenMeta(byte[] data)
  9274. {
  9275. Deserialize(data);
  9276. }
  9277. ​
  9278. public TokenMeta()
  9279. {
  9280. ​
  9281. }
  9282. }
  9283. }
  9284. ​
  9285. ​
  9286. // LibTSforge/TokenStore/ITokenStore.cs
  9287. namespace LibTSforge.TokenStore
  9288. {
  9289. using System;
  9290. ​
  9291. public interface ITokenStore : IDisposable
  9292. {
  9293. void Deserialize();
  9294. void Serialize();
  9295. void AddEntry(TokenEntry entry);
  9296. void AddEntries(TokenEntry[] entries);
  9297. void DeleteEntry(string name, string ext);
  9298. void DeleteUnpopEntry(string name, string ext);
  9299. TokenEntry GetEntry(string name, string ext);
  9300. TokenMeta GetMetaEntry(string name);
  9301. void SetEntry(string name, string ext, byte[] data);
  9302. }
  9303. }
  9304. ​
  9305. ​
  9306. // LibTSforge/TokenStore/TokenStoreModern.cs
  9307. namespace LibTSforge.TokenStore
  9308. {
  9309. using System;
  9310. using System.Collections.Generic;
  9311. using System.IO;
  9312. using System.Linq;
  9313. using Crypto;
  9314. ​
  9315. public class TokenStoreModern : ITokenStore
  9316. {
  9317. private static readonly uint VERSION = 3;
  9318. private static readonly int ENTRY_SIZE = 0x9E;
  9319. private static readonly int BLOCK_SIZE = 0x4020;
  9320. private static readonly int ENTRIES_PER_BLOCK = BLOCK_SIZE / ENTRY_SIZE;
  9321. private static readonly int BLOCK_PAD_SIZE = 0x66;
  9322. ​
  9323. private static readonly byte[] CONTS_HEADER = Enumerable.Repeat((byte)0x55, 0x20).ToArray();
  9324. private static readonly byte[] CONTS_FOOTER = Enumerable.Repeat((byte)0xAA, 0x20).ToArray();
  9325. ​
  9326. private List<TokenEntry> Entries = new List<TokenEntry>();
  9327. private readonly FileStream TokensFile;
  9328. ​
  9329. public void Deserialize()
  9330. {
  9331. if (TokensFile.Length < BLOCK_SIZE) return;
  9332. ​
  9333. TokensFile.Seek(0x24, SeekOrigin.Begin);
  9334. uint nextBlock;
  9335. ​
  9336. BinaryReader reader = new BinaryReader(TokensFile);
  9337. do
  9338. {
  9339. reader.ReadUInt32();
  9340. nextBlock = reader.ReadUInt32();
  9341. ​
  9342. for (int i = 0; i < ENTRIES_PER_BLOCK; i++)
  9343. {
  9344. uint curOffset = reader.ReadUInt32();
  9345. bool populated = reader.ReadUInt32() == 1;
  9346. uint contentOffset = reader.ReadUInt32();
  9347. uint contentLength = reader.ReadUInt32();
  9348. uint allocLength = reader.ReadUInt32();
  9349. byte[] contentData = { };
  9350. ​
  9351. if (populated)
  9352. {
  9353. reader.BaseStream.Seek(contentOffset + 0x20, SeekOrigin.Begin);
  9354. uint dataLength = reader.ReadUInt32();
  9355. ​
  9356. if (dataLength != contentLength)
  9357. {
  9358. throw new FormatException("Data length in tokens content is inconsistent with entry.");
  9359. }
  9360. ​
  9361. reader.ReadBytes(0x20);
  9362. contentData = reader.ReadBytes((int)contentLength);
  9363. }
  9364. ​
  9365. reader.BaseStream.Seek(curOffset + 0x14, SeekOrigin.Begin);
  9366. ​
  9367. Entries.Add(new TokenEntry
  9368. {
  9369. Name = reader.ReadNullTerminatedString(0x82),
  9370. Extension = reader.ReadNullTerminatedString(0x8),
  9371. Data = contentData,
  9372. Populated = populated
  9373. });
  9374. }
  9375. ​
  9376. reader.BaseStream.Seek(nextBlock, SeekOrigin.Begin);
  9377. } while (nextBlock != 0);
  9378. }
  9379. ​
  9380. public void Serialize()
  9381. {
  9382. MemoryStream tokens = new MemoryStream();
  9383. ​
  9384. using (BinaryWriter writer = new BinaryWriter(tokens))
  9385. {
  9386. writer.Write(VERSION);
  9387. writer.Write(CONTS_HEADER);
  9388. ​
  9389. int curBlockOffset = (int)writer.BaseStream.Position;
  9390. int curEntryOffset = curBlockOffset + 0x8;
  9391. int curContsOffset = curBlockOffset + BLOCK_SIZE;
  9392. ​
  9393. for (int eIndex = 0; eIndex < ((Entries.Count / ENTRIES_PER_BLOCK) + 1) * ENTRIES_PER_BLOCK; eIndex++)
  9394. {
  9395. TokenEntry entry;
  9396. ​
  9397. if (eIndex < Entries.Count)
  9398. {
  9399. entry = Entries[eIndex];
  9400. }
  9401. else
  9402. {
  9403. entry = new TokenEntry
  9404. {
  9405. Name = "",
  9406. Extension = "",
  9407. Populated = false,
  9408. Data = new byte[] { }
  9409. };
  9410. }
  9411. ​
  9412. writer.BaseStream.Seek(curBlockOffset, SeekOrigin.Begin);
  9413. writer.Write(curBlockOffset);
  9414. writer.Write(0);
  9415. ​
  9416. writer.BaseStream.Seek(curEntryOffset, SeekOrigin.Begin);
  9417. writer.Write(curEntryOffset);
  9418. writer.Write(entry.Populated ? 1 : 0);
  9419. writer.Write(entry.Populated ? curContsOffset : 0);
  9420. writer.Write(entry.Populated ? entry.Data.Length : -1);
  9421. writer.Write(entry.Populated ? entry.Data.Length : -1);
  9422. writer.WriteFixedString16(entry.Name, 0x82);
  9423. writer.WriteFixedString16(entry.Extension, 0x8);
  9424. curEntryOffset = (int)writer.BaseStream.Position;
  9425. ​
  9426. if (entry.Populated)
  9427. {
  9428. writer.BaseStream.Seek(curContsOffset, SeekOrigin.Begin);
  9429. writer.Write(CONTS_HEADER);
  9430. writer.Write(entry.Data.Length);
  9431. writer.Write(CryptoUtils.SHA256Hash(entry.Data));
  9432. writer.Write(entry.Data);
  9433. writer.Write(CONTS_FOOTER);
  9434. curContsOffset = (int)writer.BaseStream.Position;
  9435. }
  9436. ​
  9437. if ((eIndex + 1) % ENTRIES_PER_BLOCK == 0 && eIndex != 0)
  9438. {
  9439. if (eIndex < Entries.Count)
  9440. {
  9441. writer.BaseStream.Seek(curBlockOffset + 0x4, SeekOrigin.Begin);
  9442. writer.Write(curContsOffset);
  9443. }
  9444. ​
  9445. writer.BaseStream.Seek(curEntryOffset, SeekOrigin.Begin);
  9446. writer.WritePadding(BLOCK_PAD_SIZE);
  9447. ​
  9448. writer.BaseStream.Seek(curBlockOffset, SeekOrigin.Begin);
  9449. byte[] blockData = new byte[BLOCK_SIZE - 0x20];
  9450. ​
  9451. tokens.Read(blockData, 0, BLOCK_SIZE - 0x20);
  9452. byte[] blockHash = CryptoUtils.SHA256Hash(blockData);
  9453. ​
  9454. writer.BaseStream.Seek(curBlockOffset + BLOCK_SIZE - 0x20, SeekOrigin.Begin);
  9455. writer.Write(blockHash);
  9456. ​
  9457. curBlockOffset = curContsOffset;
  9458. curEntryOffset = curBlockOffset + 0x8;
  9459. curContsOffset = curBlockOffset + BLOCK_SIZE;
  9460. }
  9461. }
  9462. ​
  9463. tokens.SetLength(curBlockOffset);
  9464. }
  9465. ​
  9466. byte[] tokensData = tokens.ToArray();
  9467. byte[] tokensHash = CryptoUtils.SHA256Hash(tokensData.Take(0x4).Concat(tokensData.Skip(0x24)).ToArray());
  9468. ​
  9469. tokens = new MemoryStream(tokensData);
  9470. ​
  9471. BinaryWriter tokWriter = new BinaryWriter(TokensFile);
  9472. using (BinaryReader reader = new BinaryReader(tokens))
  9473. {
  9474. TokensFile.Seek(0, SeekOrigin.Begin);
  9475. TokensFile.SetLength(tokens.Length);
  9476. tokWriter.Write(reader.ReadBytes(0x4));
  9477. reader.ReadBytes(0x20);
  9478. tokWriter.Write(tokensHash);
  9479. tokWriter.Write(reader.ReadBytes((int)reader.BaseStream.Length - 0x4));
  9480. }
  9481. }
  9482. ​
  9483. public void AddEntry(TokenEntry entry)
  9484. {
  9485. Entries.Add(entry);
  9486. }
  9487. ​
  9488. public void AddEntries(TokenEntry[] entries)
  9489. {
  9490. Entries.AddRange(entries);
  9491. }
  9492. ​
  9493. public void DeleteEntry(string name, string ext)
  9494. {
  9495. foreach (TokenEntry entry in Entries)
  9496. {
  9497. if (entry.Name == name && entry.Extension == ext)
  9498. {
  9499. Entries.Remove(entry);
  9500. return;
  9501. }
  9502. }
  9503. }
  9504. ​
  9505. public void DeleteUnpopEntry(string name, string ext)
  9506. {
  9507. List<TokenEntry> delEntries = new List<TokenEntry>();
  9508. foreach (TokenEntry entry in Entries)
  9509. {
  9510. if (entry.Name == name && entry.Extension == ext && !entry.Populated)
  9511. {
  9512. delEntries.Add(entry);
  9513. }
  9514. }
  9515. ​
  9516. Entries = Entries.Except(delEntries).ToList();
  9517. }
  9518. ​
  9519. public TokenEntry GetEntry(string name, string ext)
  9520. {
  9521. foreach (TokenEntry entry in Entries)
  9522. {
  9523. if (entry.Name == name && entry.Extension == ext)
  9524. {
  9525. if (!entry.Populated) continue;
  9526. return entry;
  9527. }
  9528. }
  9529. ​
  9530. return null;
  9531. }
  9532. ​
  9533. public TokenMeta GetMetaEntry(string name)
  9534. {
  9535. DeleteUnpopEntry(name, "xml");
  9536. TokenEntry entry = GetEntry(name, "xml");
  9537. TokenMeta meta;
  9538. ​
  9539. if (entry == null)
  9540. {
  9541. meta = new TokenMeta
  9542. {
  9543. Name = name
  9544. };
  9545. }
  9546. else
  9547. {
  9548. meta = new TokenMeta(entry.Data);
  9549. }
  9550. ​
  9551. return meta;
  9552. }
  9553. ​
  9554. public void SetEntry(string name, string ext, byte[] data)
  9555. {
  9556. for (int i = 0; i < Entries.Count; i++)
  9557. {
  9558. TokenEntry entry = Entries[i];
  9559. ​
  9560. if (entry.Name == name && entry.Extension == ext && entry.Populated)
  9561. {
  9562. entry.Data = data;
  9563. Entries[i] = entry;
  9564. return;
  9565. }
  9566. }
  9567. ​
  9568. Entries.Add(new TokenEntry
  9569. {
  9570. Populated = true,
  9571. Name = name,
  9572. Extension = ext,
  9573. Data = data
  9574. });
  9575. }
  9576. ​
  9577. public TokenStoreModern(string tokensPath)
  9578. {
  9579. TokensFile = File.Open(tokensPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
  9580. Deserialize();
  9581. }
  9582. ​
  9583. public void Dispose()
  9584. {
  9585. Serialize();
  9586. TokensFile.Close();
  9587. }
  9588. }
  9589. }
  9590. ​
  9591. ​
  9592. // LibTSforge/PhysicalStore/Common.cs
  9593. namespace LibTSforge.PhysicalStore
  9594. {
  9595. using System.Runtime.InteropServices;
  9596. ​
  9597. public enum BlockType : uint
  9598. {
  9599. NONE,
  9600. NAMED,
  9601. ATTRIBUTE,
  9602. TIMER
  9603. }
  9604. ​
  9605. [StructLayout(LayoutKind.Sequential, Pack = 1)]
  9606. public struct Timer
  9607. {
  9608. public ulong Unknown;
  9609. public ulong Time1;
  9610. public ulong Time2;
  9611. public ulong Expiry;
  9612. }
  9613. ​
  9614. [StructLayout(LayoutKind.Sequential, Pack = 1)]
  9615. public struct VistaTimer
  9616. {
  9617. public ulong Time;
  9618. public ulong Expiry;
  9619. }
  9620. }
  9621. ​
  9622. ​
  9623. // LibTSforge/PhysicalStore/IPhysicalStore.cs
  9624. namespace LibTSforge.PhysicalStore
  9625. {
  9626. using System;
  9627. using System.Collections.Generic;
  9628. ​
  9629. public class PSBlock
  9630. {
  9631. public BlockType Type;
  9632. public uint Flags;
  9633. public uint Unknown = 0;
  9634. public byte[] Key;
  9635. public string KeyAsStr
  9636. {
  9637. get
  9638. {
  9639. return Utils.DecodeString(Key);
  9640. }
  9641. set
  9642. {
  9643. Key = Utils.EncodeString(value);
  9644. }
  9645. }
  9646. public byte[] Value;
  9647. public string ValueAsStr
  9648. {
  9649. get
  9650. {
  9651. return Utils.DecodeString(Value);
  9652. }
  9653. set
  9654. {
  9655. Value = Utils.EncodeString(value);
  9656. }
  9657. }
  9658. public uint ValueAsInt
  9659. {
  9660. get
  9661. {
  9662. return BitConverter.ToUInt32(Value, 0);
  9663. }
  9664. set
  9665. {
  9666. Value = BitConverter.GetBytes(value);
  9667. }
  9668. }
  9669. public byte[] Data;
  9670. public string DataAsStr
  9671. {
  9672. get
  9673. {
  9674. return Utils.DecodeString(Data);
  9675. }
  9676. set
  9677. {
  9678. Data = Utils.EncodeString(value);
  9679. }
  9680. }
  9681. public uint DataAsInt
  9682. {
  9683. get
  9684. {
  9685. return BitConverter.ToUInt32(Data, 0);
  9686. }
  9687. set
  9688. {
  9689. Data = BitConverter.GetBytes(value);
  9690. }
  9691. }
  9692. }
  9693. ​
  9694. public interface IPhysicalStore : IDisposable
  9695. {
  9696. PSBlock GetBlock(string key, string value);
  9697. PSBlock GetBlock(string key, uint value);
  9698. void AddBlock(PSBlock block);
  9699. void AddBlocks(IEnumerable<PSBlock> blocks);
  9700. void SetBlock(string key, string value, byte[] data);
  9701. void SetBlock(string key, string value, string data);
  9702. void SetBlock(string key, string value, uint data);
  9703. void SetBlock(string key, uint value, byte[] data);
  9704. void SetBlock(string key, uint value, string data);
  9705. void SetBlock(string key, uint value, uint data);
  9706. void DeleteBlock(string key, string value);
  9707. void DeleteBlock(string key, uint value);
  9708. byte[] Serialize();
  9709. void Deserialize(byte[] data);
  9710. byte[] ReadRaw();
  9711. void WriteRaw(byte[] data);
  9712. IEnumerable<PSBlock> FindBlocks(string valueSearch);
  9713. IEnumerable<PSBlock> FindBlocks(uint valueSearch);
  9714. }
  9715. }
  9716. ​
  9717. ​
  9718. // LibTSforge/PhysicalStore/PhysicalStoreModern.cs
  9719. namespace LibTSforge.PhysicalStore
  9720. {
  9721. using System;
  9722. using System.Collections.Generic;
  9723. using System.IO;
  9724. using Crypto;
  9725. ​
  9726. public class ModernBlock
  9727. {
  9728. public BlockType Type;
  9729. public uint Flags;
  9730. public uint Unknown;
  9731. public byte[] Value;
  9732. public string ValueAsStr
  9733. {
  9734. get
  9735. {
  9736. return Utils.DecodeString(Value);
  9737. }
  9738. set
  9739. {
  9740. Value = Utils.EncodeString(value);
  9741. }
  9742. }
  9743. public uint ValueAsInt
  9744. {
  9745. get
  9746. {
  9747. return BitConverter.ToUInt32(Value, 0);
  9748. }
  9749. set
  9750. {
  9751. Value = BitConverter.GetBytes(value);
  9752. }
  9753. }
  9754. public byte[] Data;
  9755. public string DataAsStr
  9756. {
  9757. get
  9758. {
  9759. return Utils.DecodeString(Data);
  9760. }
  9761. set
  9762. {
  9763. Data = Utils.EncodeString(value);
  9764. }
  9765. }
  9766. public uint DataAsInt
  9767. {
  9768. get
  9769. {
  9770. return BitConverter.ToUInt32(Data, 0);
  9771. }
  9772. set
  9773. {
  9774. Data = BitConverter.GetBytes(value);
  9775. }
  9776. }
  9777. ​
  9778. public void Encode(BinaryWriter writer)
  9779. {
  9780. writer.Write((uint)Type);
  9781. writer.Write(Flags);
  9782. writer.Write((uint)Value.Length);
  9783. writer.Write((uint)Data.Length);
  9784. writer.Write(Unknown);
  9785. writer.Write(Value);
  9786. writer.Write(Data);
  9787. }
  9788. ​
  9789. public static ModernBlock Decode(BinaryReader reader)
  9790. {
  9791. uint type = reader.ReadUInt32();
  9792. uint flags = reader.ReadUInt32();
  9793. ​
  9794. uint valueLen = reader.ReadUInt32();
  9795. uint dataLen = reader.ReadUInt32();
  9796. uint unk3 = reader.ReadUInt32();
  9797. ​
  9798. byte[] value = reader.ReadBytes((int)valueLen);
  9799. byte[] data = reader.ReadBytes((int)dataLen);
  9800. ​
  9801. return new ModernBlock
  9802. {
  9803. Type = (BlockType)type,
  9804. Flags = flags,
  9805. Unknown = unk3,
  9806. Value = value,
  9807. Data = data,
  9808. };
  9809. }
  9810. }
  9811. ​
  9812. public sealed class PhysicalStoreModern : IPhysicalStore
  9813. {
  9814. private byte[] PreHeaderBytes = { };
  9815. private readonly Dictionary<string, List<ModernBlock>> Data = new Dictionary<string, List<ModernBlock>>();
  9816. private readonly FileStream TSFile;
  9817. private readonly PSVersion Version;
  9818. private readonly bool Production;
  9819. ​
  9820. public byte[] Serialize()
  9821. {
  9822. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  9823. writer.Write(PreHeaderBytes);
  9824. writer.Write(Data.Keys.Count);
  9825. ​
  9826. foreach (string key in Data.Keys)
  9827. {
  9828. List<ModernBlock> blocks = Data[key];
  9829. byte[] keyNameEnc = Utils.EncodeString(key);
  9830. ​
  9831. writer.Write(keyNameEnc.Length);
  9832. writer.Write(keyNameEnc);
  9833. writer.Write(blocks.Count);
  9834. writer.Align(4);
  9835. ​
  9836. foreach (ModernBlock block in blocks)
  9837. {
  9838. block.Encode(writer);
  9839. writer.Align(4);
  9840. }
  9841. }
  9842. ​
  9843. return writer.GetBytes();
  9844. }
  9845. ​
  9846. public void Deserialize(byte[] data)
  9847. {
  9848. BinaryReader reader = new BinaryReader(new MemoryStream(data));
  9849. PreHeaderBytes = reader.ReadBytes(8);
  9850. ​
  9851. while (reader.BaseStream.Position < data.Length - 0x4)
  9852. {
  9853. uint numKeys = reader.ReadUInt32();
  9854. ​
  9855. for (int i = 0; i < numKeys; i++)
  9856. {
  9857. uint lenKeyName = reader.ReadUInt32();
  9858. string keyName = Utils.DecodeString(reader.ReadBytes((int)lenKeyName)); uint numValues = reader.ReadUInt32();
  9859. ​
  9860. reader.Align(4);
  9861. ​
  9862. Data[keyName] = new List<ModernBlock>();
  9863. ​
  9864. for (int j = 0; j < numValues; j++)
  9865. {
  9866. Data[keyName].Add(ModernBlock.Decode(reader));
  9867. reader.Align(4);
  9868. }
  9869. }
  9870. }
  9871. }
  9872. ​
  9873. public void AddBlock(PSBlock block)
  9874. {
  9875. if (!Data.ContainsKey(block.KeyAsStr))
  9876. {
  9877. Data[block.KeyAsStr] = new List<ModernBlock>();
  9878. }
  9879. ​
  9880. Data[block.KeyAsStr].Add(new ModernBlock
  9881. {
  9882. Type = block.Type,
  9883. Flags = block.Flags,
  9884. Unknown = block.Unknown,
  9885. Value = block.Value,
  9886. Data = block.Data
  9887. });
  9888. }
  9889. ​
  9890. public void AddBlocks(IEnumerable<PSBlock> blocks)
  9891. {
  9892. foreach (PSBlock block in blocks)
  9893. {
  9894. AddBlock(block);
  9895. }
  9896. }
  9897. ​
  9898. public PSBlock GetBlock(string key, string value)
  9899. {
  9900. List<ModernBlock> blocks = Data[key];
  9901. ​
  9902. foreach (ModernBlock block in blocks)
  9903. {
  9904. if (block.ValueAsStr == value)
  9905. {
  9906. return new PSBlock
  9907. {
  9908. Type = block.Type,
  9909. Flags = block.Flags,
  9910. Key = Utils.EncodeString(key),
  9911. Value = block.Value,
  9912. Data = block.Data
  9913. };
  9914. }
  9915. }
  9916. ​
  9917. return null;
  9918. }
  9919. ​
  9920. public PSBlock GetBlock(string key, uint value)
  9921. {
  9922. List<ModernBlock> blocks = Data[key];
  9923. ​
  9924. foreach (ModernBlock block in blocks)
  9925. {
  9926. if (block.ValueAsInt == value)
  9927. {
  9928. return new PSBlock
  9929. {
  9930. Type = block.Type,
  9931. Flags = block.Flags,
  9932. Key = Utils.EncodeString(key),
  9933. Value = block.Value,
  9934. Data = block.Data
  9935. };
  9936. }
  9937. }
  9938. ​
  9939. return null;
  9940. }
  9941. ​
  9942. public void SetBlock(string key, string value, byte[] data)
  9943. {
  9944. List<ModernBlock> blocks = Data[key];
  9945. ​
  9946. for (int i = 0; i < blocks.Count; i++)
  9947. {
  9948. ModernBlock block = blocks[i];
  9949. ​
  9950. if (block.ValueAsStr == value)
  9951. {
  9952. block.Data = data;
  9953. blocks[i] = block;
  9954. break;
  9955. }
  9956. }
  9957. ​
  9958. Data[key] = blocks;
  9959. }
  9960. ​
  9961. public void SetBlock(string key, uint value, byte[] data)
  9962. {
  9963. List<ModernBlock> blocks = Data[key];
  9964. ​
  9965. for (int i = 0; i < blocks.Count; i++)
  9966. {
  9967. ModernBlock block = blocks[i];
  9968. ​
  9969. if (block.ValueAsInt == value)
  9970. {
  9971. block.Data = data;
  9972. blocks[i] = block;
  9973. break;
  9974. }
  9975. }
  9976. ​
  9977. Data[key] = blocks;
  9978. }
  9979. ​
  9980. public void SetBlock(string key, string value, string data)
  9981. {
  9982. SetBlock(key, value, Utils.EncodeString(data));
  9983. }
  9984. ​
  9985. public void SetBlock(string key, string value, uint data)
  9986. {
  9987. SetBlock(key, value, BitConverter.GetBytes(data));
  9988. }
  9989. ​
  9990. public void SetBlock(string key, uint value, string data)
  9991. {
  9992. SetBlock(key, value, Utils.EncodeString(data));
  9993. }
  9994. ​
  9995. public void SetBlock(string key, uint value, uint data)
  9996. {
  9997. SetBlock(key, value, BitConverter.GetBytes(data));
  9998. }
  9999. ​
  10000. public void DeleteBlock(string key, string value)
  10001. {
  10002. if (!Data.ContainsKey(key))
  10003. {
  10004. return;
  10005. }
  10006. ​
  10007. List<ModernBlock> blocks = Data[key];
  10008. ​
  10009. foreach (ModernBlock block in blocks)
  10010. {
  10011. if (block.ValueAsStr == value)
  10012. {
  10013. blocks.Remove(block);
  10014. break;
  10015. }
  10016. }
  10017. ​
  10018. Data[key] = blocks;
  10019. }
  10020. ​
  10021. public void DeleteBlock(string key, uint value)
  10022. {
  10023. if (!Data.ContainsKey(key))
  10024. {
  10025. return;
  10026. }
  10027. ​
  10028. List<ModernBlock> blocks = Data[key];
  10029. ​
  10030. foreach (ModernBlock block in blocks)
  10031. {
  10032. if (block.ValueAsInt == value)
  10033. {
  10034. blocks.Remove(block);
  10035. break;
  10036. }
  10037. }
  10038. ​
  10039. Data[key] = blocks;
  10040. }
  10041. ​
  10042. public PhysicalStoreModern(string tsPath, bool production, PSVersion version)
  10043. {
  10044. TSFile = File.Open(tsPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
  10045. Deserialize(PhysStoreCrypto.DecryptPhysicalStore(TSFile.ReadAllBytes(), production, version));
  10046. TSFile.Seek(0, SeekOrigin.Begin);
  10047. Version = version;
  10048. Production = production;
  10049. }
  10050. ​
  10051. public void Dispose()
  10052. {
  10053. if (TSFile.CanWrite)
  10054. {
  10055. byte[] data = PhysStoreCrypto.EncryptPhysicalStore(Serialize(), Production, Version);
  10056. TSFile.SetLength(data.LongLength);
  10057. TSFile.Seek(0, SeekOrigin.Begin);
  10058. TSFile.WriteAllBytes(data);
  10059. TSFile.Close();
  10060. }
  10061. }
  10062. ​
  10063. public byte[] ReadRaw()
  10064. {
  10065. byte[] data = PhysStoreCrypto.DecryptPhysicalStore(TSFile.ReadAllBytes(), Production, Version);
  10066. TSFile.Seek(0, SeekOrigin.Begin);
  10067. return data;
  10068. }
  10069. ​
  10070. public void WriteRaw(byte[] data)
  10071. {
  10072. byte[] encrData = PhysStoreCrypto.EncryptPhysicalStore(data, Production, Version);
  10073. TSFile.SetLength(encrData.LongLength);
  10074. TSFile.Seek(0, SeekOrigin.Begin);
  10075. TSFile.WriteAllBytes(encrData);
  10076. TSFile.Close();
  10077. }
  10078. ​
  10079. public IEnumerable<PSBlock> FindBlocks(string valueSearch)
  10080. {
  10081. List<PSBlock> results = new List<PSBlock>();
  10082. ​
  10083. foreach (string key in Data.Keys)
  10084. {
  10085. List<ModernBlock> values = Data[key];
  10086. ​
  10087. foreach (ModernBlock block in values)
  10088. {
  10089. if (block.ValueAsStr.Contains(valueSearch))
  10090. {
  10091. results.Add(new PSBlock
  10092. {
  10093. Type = block.Type,
  10094. Flags = block.Flags,
  10095. KeyAsStr = key,
  10096. Value = block.Value,
  10097. Data = block.Data
  10098. });
  10099. }
  10100. }
  10101. }
  10102. ​
  10103. return results;
  10104. }
  10105. ​
  10106. public IEnumerable<PSBlock> FindBlocks(uint valueSearch)
  10107. {
  10108. List<PSBlock> results = new List<PSBlock>();
  10109. ​
  10110. foreach (string key in Data.Keys)
  10111. {
  10112. List<ModernBlock> values = Data[key];
  10113. ​
  10114. foreach (ModernBlock block in values)
  10115. {
  10116. if (block.ValueAsInt == valueSearch)
  10117. {
  10118. results.Add(new PSBlock
  10119. {
  10120. Type = block.Type,
  10121. Flags = block.Flags,
  10122. KeyAsStr = key,
  10123. Value = block.Value,
  10124. Data = block.Data
  10125. });
  10126. }
  10127. }
  10128. }
  10129. ​
  10130. return results;
  10131. }
  10132. }
  10133. }
  10134. ​
  10135. ​
  10136. // LibTSforge/PhysicalStore/PhysicalStoreVista.cs
  10137. namespace LibTSforge.PhysicalStore
  10138. {
  10139. using System;
  10140. using System.Collections.Generic;
  10141. using System.IO;
  10142. using Crypto;
  10143. ​
  10144. public class VistaBlock
  10145. {
  10146. public BlockType Type;
  10147. public uint Flags;
  10148. public byte[] Value;
  10149. public string ValueAsStr
  10150. {
  10151. get
  10152. {
  10153. return Utils.DecodeString(Value);
  10154. }
  10155. set
  10156. {
  10157. Value = Utils.EncodeString(value);
  10158. }
  10159. }
  10160. public uint ValueAsInt
  10161. {
  10162. get
  10163. {
  10164. return BitConverter.ToUInt32(Value, 0);
  10165. }
  10166. set
  10167. {
  10168. Value = BitConverter.GetBytes(value);
  10169. }
  10170. }
  10171. public byte[] Data;
  10172. public string DataAsStr
  10173. {
  10174. get
  10175. {
  10176. return Utils.DecodeString(Data);
  10177. }
  10178. set
  10179. {
  10180. Data = Utils.EncodeString(value);
  10181. }
  10182. }
  10183. public uint DataAsInt
  10184. {
  10185. get
  10186. {
  10187. return BitConverter.ToUInt32(Data, 0);
  10188. }
  10189. set
  10190. {
  10191. Data = BitConverter.GetBytes(value);
  10192. }
  10193. }
  10194. ​
  10195. internal void Encode(BinaryWriter writer)
  10196. {
  10197. writer.Write((uint)Type);
  10198. writer.Write(Flags);
  10199. writer.Write(Value.Length);
  10200. writer.Write(Data.Length);
  10201. writer.Write(Value);
  10202. writer.Write(Data);
  10203. }
  10204. ​
  10205. internal static VistaBlock Decode(BinaryReader reader)
  10206. {
  10207. uint type = reader.ReadUInt32();
  10208. uint flags = reader.ReadUInt32();
  10209. ​
  10210. int valueLen = reader.ReadInt32();
  10211. int dataLen = reader.ReadInt32();
  10212. ​
  10213. byte[] value = reader.ReadBytes(valueLen);
  10214. byte[] data = reader.ReadBytes(dataLen);
  10215. return new VistaBlock
  10216. {
  10217. Type = (BlockType)type,
  10218. Flags = flags,
  10219. Value = value,
  10220. Data = data,
  10221. };
  10222. }
  10223. }
  10224. ​
  10225. public sealed class PhysicalStoreVista : IPhysicalStore
  10226. {
  10227. private byte[] PreHeaderBytes = { };
  10228. private readonly List<VistaBlock> Blocks = new List<VistaBlock>();
  10229. private readonly FileStream TSPrimary;
  10230. private readonly FileStream TSSecondary;
  10231. private readonly bool Production;
  10232. ​
  10233. public byte[] Serialize()
  10234. {
  10235. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  10236. writer.Write(PreHeaderBytes);
  10237. ​
  10238. foreach (VistaBlock block in Blocks)
  10239. {
  10240. block.Encode(writer);
  10241. writer.Align(4);
  10242. }
  10243. ​
  10244. return writer.GetBytes();
  10245. }
  10246. ​
  10247. public void Deserialize(byte[] data)
  10248. {
  10249. int len = data.Length;
  10250. ​
  10251. BinaryReader reader = new BinaryReader(new MemoryStream(data));
  10252. PreHeaderBytes = reader.ReadBytes(8);
  10253. ​
  10254. while (reader.BaseStream.Position < len - 0x14)
  10255. {
  10256. Blocks.Add(VistaBlock.Decode(reader));
  10257. reader.Align(4);
  10258. }
  10259. }
  10260. ​
  10261. public void AddBlock(PSBlock block)
  10262. {
  10263. Blocks.Add(new VistaBlock
  10264. {
  10265. Type = block.Type,
  10266. Flags = block.Flags,
  10267. Value = block.Value,
  10268. Data = block.Data
  10269. });
  10270. }
  10271. ​
  10272. public void AddBlocks(IEnumerable<PSBlock> blocks)
  10273. {
  10274. foreach (PSBlock block in blocks)
  10275. {
  10276. AddBlock(block);
  10277. }
  10278. }
  10279. ​
  10280. public PSBlock GetBlock(string key, string value)
  10281. {
  10282. foreach (VistaBlock block in Blocks)
  10283. {
  10284. if (block.ValueAsStr == value)
  10285. {
  10286. return new PSBlock
  10287. {
  10288. Type = block.Type,
  10289. Flags = block.Flags,
  10290. Key = new byte[0],
  10291. Value = block.Value,
  10292. Data = block.Data
  10293. };
  10294. }
  10295. }
  10296. ​
  10297. return null;
  10298. }
  10299. ​
  10300. public PSBlock GetBlock(string key, uint value)
  10301. {
  10302. foreach (VistaBlock block in Blocks)
  10303. {
  10304. if (block.ValueAsInt == value)
  10305. {
  10306. return new PSBlock
  10307. {
  10308. Type = block.Type,
  10309. Flags = block.Flags,
  10310. Key = new byte[0],
  10311. Value = block.Value,
  10312. Data = block.Data
  10313. };
  10314. }
  10315. }
  10316. ​
  10317. return null;
  10318. }
  10319. ​
  10320. public void SetBlock(string key, string value, byte[] data)
  10321. {
  10322. for (int i = 0; i < Blocks.Count; i++)
  10323. {
  10324. VistaBlock block = Blocks[i];
  10325. ​
  10326. if (block.ValueAsStr == value)
  10327. {
  10328. block.Data = data;
  10329. Blocks[i] = block;
  10330. break;
  10331. }
  10332. }
  10333. }
  10334. ​
  10335. public void SetBlock(string key, uint value, byte[] data)
  10336. {
  10337. for (int i = 0; i < Blocks.Count; i++)
  10338. {
  10339. VistaBlock block = Blocks[i];
  10340. ​
  10341. if (block.ValueAsInt == value)
  10342. {
  10343. block.Data = data;
  10344. Blocks[i] = block;
  10345. break;
  10346. }
  10347. }
  10348. }
  10349. ​
  10350. public void SetBlock(string key, string value, string data)
  10351. {
  10352. SetBlock(key, value, Utils.EncodeString(data));
  10353. }
  10354. ​
  10355. public void SetBlock(string key, string value, uint data)
  10356. {
  10357. SetBlock(key, value, BitConverter.GetBytes(data));
  10358. }
  10359. ​
  10360. public void SetBlock(string key, uint value, string data)
  10361. {
  10362. SetBlock(key, value, Utils.EncodeString(data));
  10363. }
  10364. ​
  10365. public void SetBlock(string key, uint value, uint data)
  10366. {
  10367. SetBlock(key, value, BitConverter.GetBytes(data));
  10368. }
  10369. ​
  10370. public void DeleteBlock(string key, string value)
  10371. {
  10372. foreach (VistaBlock block in Blocks)
  10373. {
  10374. if (block.ValueAsStr == value)
  10375. {
  10376. Blocks.Remove(block);
  10377. return;
  10378. }
  10379. }
  10380. }
  10381. ​
  10382. public void DeleteBlock(string key, uint value)
  10383. {
  10384. foreach (VistaBlock block in Blocks)
  10385. {
  10386. if (block.ValueAsInt == value)
  10387. {
  10388. Blocks.Remove(block);
  10389. return;
  10390. }
  10391. }
  10392. }
  10393. ​
  10394. public PhysicalStoreVista(string primaryPath, bool production)
  10395. {
  10396. TSPrimary = File.Open(primaryPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
  10397. TSSecondary = File.Open(primaryPath.Replace("-0.", "-1."), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
  10398. Production = production;
  10399. ​
  10400. Deserialize(PhysStoreCrypto.DecryptPhysicalStore(TSPrimary.ReadAllBytes(), production, PSVersion.Vista));
  10401. TSPrimary.Seek(0, SeekOrigin.Begin);
  10402. }
  10403. ​
  10404. public void Dispose()
  10405. {
  10406. if (TSPrimary.CanWrite && TSSecondary.CanWrite)
  10407. {
  10408. byte[] data = PhysStoreCrypto.EncryptPhysicalStore(Serialize(), Production, PSVersion.Vista);
  10409. ​
  10410. TSPrimary.SetLength(data.LongLength);
  10411. TSSecondary.SetLength(data.LongLength);
  10412. ​
  10413. TSPrimary.Seek(0, SeekOrigin.Begin);
  10414. TSSecondary.Seek(0, SeekOrigin.Begin);
  10415. ​
  10416. TSPrimary.WriteAllBytes(data);
  10417. TSSecondary.WriteAllBytes(data);
  10418. ​
  10419. TSPrimary.Close();
  10420. TSSecondary.Close();
  10421. }
  10422. }
  10423. ​
  10424. public byte[] ReadRaw()
  10425. {
  10426. byte[] data = PhysStoreCrypto.DecryptPhysicalStore(TSPrimary.ReadAllBytes(), Production, PSVersion.Vista);
  10427. TSPrimary.Seek(0, SeekOrigin.Begin);
  10428. return data;
  10429. }
  10430. ​
  10431. public void WriteRaw(byte[] data)
  10432. {
  10433. byte[] encrData = PhysStoreCrypto.EncryptPhysicalStore(data, Production, PSVersion.Vista);
  10434. ​
  10435. TSPrimary.SetLength(encrData.LongLength);
  10436. TSSecondary.SetLength(encrData.LongLength);
  10437. ​
  10438. TSPrimary.Seek(0, SeekOrigin.Begin);
  10439. TSSecondary.Seek(0, SeekOrigin.Begin);
  10440. ​
  10441. TSPrimary.WriteAllBytes(encrData);
  10442. TSSecondary.WriteAllBytes(encrData);
  10443. ​
  10444. TSPrimary.Close();
  10445. TSSecondary.Close();
  10446. }
  10447. ​
  10448. public IEnumerable<PSBlock> FindBlocks(string valueSearch)
  10449. {
  10450. List<PSBlock> results = new List<PSBlock>();
  10451. ​
  10452. foreach (VistaBlock block in Blocks)
  10453. {
  10454. if (block.ValueAsStr.Contains(valueSearch))
  10455. {
  10456. results.Add(new PSBlock
  10457. {
  10458. Type = block.Type,
  10459. Flags = block.Flags,
  10460. Key = new byte[0],
  10461. Value = block.Value,
  10462. Data = block.Data
  10463. });
  10464. }
  10465. }
  10466. ​
  10467. return results;
  10468. }
  10469. ​
  10470. public IEnumerable<PSBlock> FindBlocks(uint valueSearch)
  10471. {
  10472. List<PSBlock> results = new List<PSBlock>();
  10473. ​
  10474. foreach (VistaBlock block in Blocks)
  10475. {
  10476. if (block.ValueAsInt == valueSearch)
  10477. {
  10478. results.Add(new PSBlock
  10479. {
  10480. Type = block.Type,
  10481. Flags = block.Flags,
  10482. Key = new byte[0],
  10483. Value = block.Value,
  10484. Data = block.Data
  10485. });
  10486. }
  10487. }
  10488. ​
  10489. return results;
  10490. }
  10491. }
  10492. }
  10493. ​
  10494. ​
  10495. // LibTSforge/PhysicalStore/PhysicalStoreWin7.cs
  10496. namespace LibTSforge.PhysicalStore
  10497. {
  10498. using System;
  10499. using System.Collections.Generic;
  10500. using System.IO;
  10501. using Crypto;
  10502. ​
  10503. public class Win7Block
  10504. {
  10505. public BlockType Type;
  10506. public uint Flags;
  10507. public byte[] Key;
  10508. public string KeyAsStr
  10509. {
  10510. get
  10511. {
  10512. return Utils.DecodeString(Key);
  10513. }
  10514. set
  10515. {
  10516. Key = Utils.EncodeString(value);
  10517. }
  10518. }
  10519. public byte[] Value;
  10520. public string ValueAsStr
  10521. {
  10522. get
  10523. {
  10524. return Utils.DecodeString(Value);
  10525. }
  10526. set
  10527. {
  10528. Value = Utils.EncodeString(value);
  10529. }
  10530. }
  10531. public uint ValueAsInt
  10532. {
  10533. get
  10534. {
  10535. return BitConverter.ToUInt32(Value, 0);
  10536. }
  10537. set
  10538. {
  10539. Value = BitConverter.GetBytes(value);
  10540. }
  10541. }
  10542. public byte[] Data;
  10543. public string DataAsStr
  10544. {
  10545. get
  10546. {
  10547. return Utils.DecodeString(Data);
  10548. }
  10549. set
  10550. {
  10551. Data = Utils.EncodeString(value);
  10552. }
  10553. }
  10554. public uint DataAsInt
  10555. {
  10556. get
  10557. {
  10558. return BitConverter.ToUInt32(Data, 0);
  10559. }
  10560. set
  10561. {
  10562. Data = BitConverter.GetBytes(value);
  10563. }
  10564. }
  10565. ​
  10566. internal void Encode(BinaryWriter writer)
  10567. {
  10568. writer.Write((uint)Type);
  10569. writer.Write(Flags);
  10570. writer.Write(Key.Length);
  10571. writer.Write(Value.Length);
  10572. writer.Write(Data.Length);
  10573. writer.Write(Key);
  10574. writer.Write(Value);
  10575. writer.Write(Data);
  10576. }
  10577. ​
  10578. internal static Win7Block Decode(BinaryReader reader)
  10579. {
  10580. uint type = reader.ReadUInt32();
  10581. uint flags = reader.ReadUInt32();
  10582. ​
  10583. int keyLen = reader.ReadInt32();
  10584. int valueLen = reader.ReadInt32();
  10585. int dataLen = reader.ReadInt32();
  10586. ​
  10587. byte[] key = reader.ReadBytes(keyLen);
  10588. byte[] value = reader.ReadBytes(valueLen);
  10589. byte[] data = reader.ReadBytes(dataLen);
  10590. return new Win7Block
  10591. {
  10592. Type = (BlockType)type,
  10593. Flags = flags,
  10594. Key = key,
  10595. Value = value,
  10596. Data = data,
  10597. };
  10598. }
  10599. }
  10600. ​
  10601. public sealed class PhysicalStoreWin7 : IPhysicalStore
  10602. {
  10603. private byte[] PreHeaderBytes = { };
  10604. private readonly List<Win7Block> Blocks = new List<Win7Block>();
  10605. private readonly FileStream TSPrimary;
  10606. private readonly FileStream TSSecondary;
  10607. private readonly bool Production;
  10608. ​
  10609. public byte[] Serialize()
  10610. {
  10611. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  10612. writer.Write(PreHeaderBytes);
  10613. ​
  10614. foreach (Win7Block block in Blocks)
  10615. {
  10616. block.Encode(writer);
  10617. writer.Align(4);
  10618. }
  10619. ​
  10620. return writer.GetBytes();
  10621. }
  10622. ​
  10623. public void Deserialize(byte[] data)
  10624. {
  10625. int len = data.Length;
  10626. ​
  10627. BinaryReader reader = new BinaryReader(new MemoryStream(data));
  10628. PreHeaderBytes = reader.ReadBytes(8);
  10629. ​
  10630. while (reader.BaseStream.Position < len - 0x14)
  10631. {
  10632. Blocks.Add(Win7Block.Decode(reader));
  10633. reader.Align(4);
  10634. }
  10635. }
  10636. ​
  10637. public void AddBlock(PSBlock block)
  10638. {
  10639. Blocks.Add(new Win7Block
  10640. {
  10641. Type = block.Type,
  10642. Flags = block.Flags,
  10643. Key = block.Key,
  10644. Value = block.Value,
  10645. Data = block.Data
  10646. });
  10647. }
  10648. ​
  10649. public void AddBlocks(IEnumerable<PSBlock> blocks)
  10650. {
  10651. foreach (PSBlock block in blocks)
  10652. {
  10653. AddBlock(block);
  10654. }
  10655. }
  10656. ​
  10657. public PSBlock GetBlock(string key, string value)
  10658. {
  10659. foreach (Win7Block block in Blocks)
  10660. {
  10661. if (block.KeyAsStr == key && block.ValueAsStr == value)
  10662. {
  10663. return new PSBlock
  10664. {
  10665. Type = block.Type,
  10666. Flags = block.Flags,
  10667. Key = block.Key,
  10668. Value = block.Value,
  10669. Data = block.Data
  10670. };
  10671. }
  10672. }
  10673. ​
  10674. return null;
  10675. }
  10676. ​
  10677. public PSBlock GetBlock(string key, uint value)
  10678. {
  10679. foreach (Win7Block block in Blocks)
  10680. {
  10681. if (block.KeyAsStr == key && block.ValueAsInt == value)
  10682. {
  10683. return new PSBlock
  10684. {
  10685. Type = block.Type,
  10686. Flags = block.Flags,
  10687. Key = block.Key,
  10688. Value = block.Value,
  10689. Data = block.Data
  10690. };
  10691. }
  10692. }
  10693. ​
  10694. return null;
  10695. }
  10696. ​
  10697. public void SetBlock(string key, string value, byte[] data)
  10698. {
  10699. for (int i = 0; i < Blocks.Count; i++)
  10700. {
  10701. Win7Block block = Blocks[i];
  10702. ​
  10703. if (block.KeyAsStr == key && block.ValueAsStr == value)
  10704. {
  10705. block.Data = data;
  10706. Blocks[i] = block;
  10707. break;
  10708. }
  10709. }
  10710. }
  10711. ​
  10712. public void SetBlock(string key, uint value, byte[] data)
  10713. {
  10714. for (int i = 0; i < Blocks.Count; i++)
  10715. {
  10716. Win7Block block = Blocks[i];
  10717. ​
  10718. if (block.KeyAsStr == key && block.ValueAsInt == value)
  10719. {
  10720. block.Data = data;
  10721. Blocks[i] = block;
  10722. break;
  10723. }
  10724. }
  10725. }
  10726. ​
  10727. public void SetBlock(string key, string value, string data)
  10728. {
  10729. SetBlock(key, value, Utils.EncodeString(data));
  10730. }
  10731. ​
  10732. public void SetBlock(string key, string value, uint data)
  10733. {
  10734. SetBlock(key, value, BitConverter.GetBytes(data));
  10735. }
  10736. ​
  10737. public void SetBlock(string key, uint value, string data)
  10738. {
  10739. SetBlock(key, value, Utils.EncodeString(data));
  10740. }
  10741. ​
  10742. public void SetBlock(string key, uint value, uint data)
  10743. {
  10744. SetBlock(key, value, BitConverter.GetBytes(data));
  10745. }
  10746. ​
  10747. public void DeleteBlock(string key, string value)
  10748. {
  10749. foreach (Win7Block block in Blocks)
  10750. {
  10751. if (block.KeyAsStr == key && block.ValueAsStr == value)
  10752. {
  10753. Blocks.Remove(block);
  10754. return;
  10755. }
  10756. }
  10757. }
  10758. ​
  10759. public void DeleteBlock(string key, uint value)
  10760. {
  10761. foreach (Win7Block block in Blocks)
  10762. {
  10763. if (block.KeyAsStr == key && block.ValueAsInt == value)
  10764. {
  10765. Blocks.Remove(block);
  10766. return;
  10767. }
  10768. }
  10769. }
  10770. ​
  10771. public PhysicalStoreWin7(string primaryPath, bool production)
  10772. {
  10773. TSPrimary = File.Open(primaryPath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
  10774. TSSecondary = File.Open(primaryPath.Replace("-0.", "-1."), FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
  10775. Production = production;
  10776. ​
  10777. Deserialize(PhysStoreCrypto.DecryptPhysicalStore(TSPrimary.ReadAllBytes(), production, PSVersion.Win7));
  10778. TSPrimary.Seek(0, SeekOrigin.Begin);
  10779. }
  10780. ​
  10781. public void Dispose()
  10782. {
  10783. if (TSPrimary.CanWrite && TSSecondary.CanWrite)
  10784. {
  10785. byte[] data = PhysStoreCrypto.EncryptPhysicalStore(Serialize(), Production, PSVersion.Win7);
  10786. ​
  10787. TSPrimary.SetLength(data.LongLength);
  10788. TSSecondary.SetLength(data.LongLength);
  10789. ​
  10790. TSPrimary.Seek(0, SeekOrigin.Begin);
  10791. TSSecondary.Seek(0, SeekOrigin.Begin);
  10792. ​
  10793. TSPrimary.WriteAllBytes(data);
  10794. TSSecondary.WriteAllBytes(data);
  10795. ​
  10796. TSPrimary.Close();
  10797. TSSecondary.Close();
  10798. }
  10799. }
  10800. ​
  10801. public byte[] ReadRaw()
  10802. {
  10803. byte[] data = PhysStoreCrypto.DecryptPhysicalStore(TSPrimary.ReadAllBytes(), Production, PSVersion.Win7);
  10804. TSPrimary.Seek(0, SeekOrigin.Begin);
  10805. return data;
  10806. }
  10807. ​
  10808. public void WriteRaw(byte[] data)
  10809. {
  10810. byte[] encrData = PhysStoreCrypto.EncryptPhysicalStore(data, Production, PSVersion.Win7);
  10811. ​
  10812. TSPrimary.SetLength(encrData.LongLength);
  10813. TSSecondary.SetLength(encrData.LongLength);
  10814. ​
  10815. TSPrimary.Seek(0, SeekOrigin.Begin);
  10816. TSSecondary.Seek(0, SeekOrigin.Begin);
  10817. ​
  10818. TSPrimary.WriteAllBytes(encrData);
  10819. TSSecondary.WriteAllBytes(encrData);
  10820. ​
  10821. TSPrimary.Close();
  10822. TSSecondary.Close();
  10823. }
  10824. ​
  10825. public IEnumerable<PSBlock> FindBlocks(string valueSearch)
  10826. {
  10827. List<PSBlock> results = new List<PSBlock>();
  10828. ​
  10829. foreach (Win7Block block in Blocks)
  10830. {
  10831. if (block.ValueAsStr.Contains(valueSearch))
  10832. {
  10833. results.Add(new PSBlock
  10834. {
  10835. Type = block.Type,
  10836. Flags = block.Flags,
  10837. Key = block.Key,
  10838. Value = block.Value,
  10839. Data = block.Data
  10840. });
  10841. }
  10842. }
  10843. ​
  10844. return results;
  10845. }
  10846. ​
  10847. public IEnumerable<PSBlock> FindBlocks(uint valueSearch)
  10848. {
  10849. List<PSBlock> results = new List<PSBlock>();
  10850. ​
  10851. foreach (Win7Block block in Blocks)
  10852. {
  10853. if (block.ValueAsInt == valueSearch)
  10854. {
  10855. results.Add(new PSBlock
  10856. {
  10857. Type = block.Type,
  10858. Flags = block.Flags,
  10859. Key = block.Key,
  10860. Value = block.Value,
  10861. Data = block.Data
  10862. });
  10863. }
  10864. }
  10865. ​
  10866. return results;
  10867. }
  10868. }
  10869. }
  10870. ​
  10871. ​
  10872. // LibTSforge/PhysicalStore/VariableBag.cs
  10873. namespace LibTSforge.PhysicalStore
  10874. {
  10875. using System;
  10876. using System.Collections.Generic;
  10877. using System.IO;
  10878. ​
  10879. public enum CRCBlockType : uint
  10880. {
  10881. UINT = 1 << 0,
  10882. STRING = 1 << 1,
  10883. BINARY = 1 << 2
  10884. }
  10885. ​
  10886. public abstract class CRCBlock
  10887. {
  10888. public CRCBlockType DataType;
  10889. public byte[] Key;
  10890. public string KeyAsStr
  10891. {
  10892. get
  10893. {
  10894. return Utils.DecodeString(Key);
  10895. }
  10896. set
  10897. {
  10898. Key = Utils.EncodeString(value);
  10899. }
  10900. }
  10901. public byte[] Value;
  10902. public string ValueAsStr
  10903. {
  10904. get
  10905. {
  10906. return Utils.DecodeString(Value);
  10907. }
  10908. set
  10909. {
  10910. Value = Utils.EncodeString(value);
  10911. }
  10912. }
  10913. public uint ValueAsInt
  10914. {
  10915. get
  10916. {
  10917. return BitConverter.ToUInt32(Value, 0);
  10918. }
  10919. set
  10920. {
  10921. Value = BitConverter.GetBytes(value);
  10922. }
  10923. }
  10924. ​
  10925. public abstract void Encode(BinaryWriter writer);
  10926. public abstract void Decode(BinaryReader reader);
  10927. public abstract uint CRC();
  10928. }
  10929. ​
  10930. public class CRCBlockVista : CRCBlock
  10931. {
  10932. public override void Encode(BinaryWriter writer)
  10933. {
  10934. uint crc = CRC();
  10935. writer.Write((uint)DataType);
  10936. writer.Write(0);
  10937. writer.Write(Key.Length);
  10938. writer.Write(Value.Length);
  10939. writer.Write(crc);
  10940. ​
  10941. writer.Write(Key);
  10942. ​
  10943. writer.Write(Value);
  10944. }
  10945. ​
  10946. public override void Decode(BinaryReader reader)
  10947. {
  10948. uint type = reader.ReadUInt32();
  10949. reader.ReadUInt32();
  10950. uint lenName = reader.ReadUInt32();
  10951. uint lenVal = reader.ReadUInt32();
  10952. uint crc = reader.ReadUInt32();
  10953. ​
  10954. byte[] key = reader.ReadBytes((int)lenName);
  10955. byte[] value = reader.ReadBytes((int)lenVal);
  10956. ​
  10957. DataType = (CRCBlockType)type;
  10958. Key = key;
  10959. Value = value;
  10960. ​
  10961. if (CRC() != crc)
  10962. {
  10963. throw new InvalidDataException("Invalid CRC in variable bag.");
  10964. }
  10965. }
  10966. ​
  10967. public override uint CRC()
  10968. {
  10969. return Utils.CRC32(Value);
  10970. }
  10971. }
  10972. ​
  10973. public class CRCBlockModern : CRCBlock
  10974. {
  10975. public override void Encode(BinaryWriter writer)
  10976. {
  10977. uint crc = CRC();
  10978. writer.Write(crc);
  10979. writer.Write((uint)DataType);
  10980. writer.Write(Key.Length);
  10981. writer.Write(Value.Length);
  10982. ​
  10983. writer.Write(Key);
  10984. writer.Align(8);
  10985. ​
  10986. writer.Write(Value);
  10987. writer.Align(8);
  10988. }
  10989. ​
  10990. public override void Decode(BinaryReader reader)
  10991. {
  10992. uint crc = reader.ReadUInt32();
  10993. uint type = reader.ReadUInt32();
  10994. uint lenName = reader.ReadUInt32();
  10995. uint lenVal = reader.ReadUInt32();
  10996. ​
  10997. byte[] key = reader.ReadBytes((int)lenName);
  10998. reader.Align(8);
  10999. ​
  11000. byte[] value = reader.ReadBytes((int)lenVal);
  11001. reader.Align(8);
  11002. ​
  11003. DataType = (CRCBlockType)type;
  11004. Key = key;
  11005. Value = value;
  11006. ​
  11007. if (CRC() != crc)
  11008. {
  11009. throw new InvalidDataException("Invalid CRC in variable bag.");
  11010. }
  11011. }
  11012. ​
  11013. public override uint CRC()
  11014. {
  11015. BinaryWriter wtemp = new BinaryWriter(new MemoryStream());
  11016. wtemp.Write(0);
  11017. wtemp.Write((uint)DataType);
  11018. wtemp.Write(Key.Length);
  11019. wtemp.Write(Value.Length);
  11020. wtemp.Write(Key);
  11021. wtemp.Write(Value);
  11022. return Utils.CRC32(wtemp.GetBytes());
  11023. }
  11024. }
  11025. ​
  11026. public class VariableBag
  11027. {
  11028. public List<CRCBlock> Blocks = new List<CRCBlock>();
  11029. private readonly PSVersion Version;
  11030. ​
  11031. private void Deserialize(byte[] data)
  11032. {
  11033. int len = data.Length;
  11034. ​
  11035. BinaryReader reader = new BinaryReader(new MemoryStream(data));
  11036. ​
  11037. while (reader.BaseStream.Position < len - 0x10)
  11038. {
  11039. CRCBlock block;
  11040. ​
  11041. if (Version == PSVersion.Vista)
  11042. {
  11043. block = new CRCBlockVista();
  11044. }
  11045. else
  11046. {
  11047. block = new CRCBlockModern();
  11048. }
  11049. ​
  11050. block.Decode(reader);
  11051. Blocks.Add(block);
  11052. }
  11053. }
  11054. ​
  11055. public byte[] Serialize()
  11056. {
  11057. BinaryWriter writer = new BinaryWriter(new MemoryStream());
  11058. ​
  11059. foreach (CRCBlock block in Blocks)
  11060. {
  11061. if (Version == PSVersion.Vista)
  11062. {
  11063. ((CRCBlockVista)block).Encode(writer);
  11064. } else
  11065. {
  11066. ((CRCBlockModern)block).Encode(writer);
  11067. }
  11068. }
  11069. ​
  11070. return writer.GetBytes();
  11071. }
  11072. ​
  11073. public CRCBlock GetBlock(string key)
  11074. {
  11075. foreach (CRCBlock block in Blocks)
  11076. {
  11077. if (block.KeyAsStr == key)
  11078. {
  11079. return block;
  11080. }
  11081. }
  11082. ​
  11083. return null;
  11084. }
  11085. ​
  11086. public void SetBlock(string key, byte[] value)
  11087. {
  11088. for (int i = 0; i < Blocks.Count; i++)
  11089. {
  11090. CRCBlock block = Blocks[i];
  11091. ​
  11092. if (block.KeyAsStr == key)
  11093. {
  11094. block.Value = value;
  11095. Blocks[i] = block;
  11096. break;
  11097. }
  11098. }
  11099. }
  11100. ​
  11101. public void DeleteBlock(string key)
  11102. {
  11103. foreach (CRCBlock block in Blocks)
  11104. {
  11105. if (block.KeyAsStr == key)
  11106. {
  11107. Blocks.Remove(block);
  11108. return;
  11109. }
  11110. }
  11111. }
  11112. ​
  11113. public VariableBag(byte[] data, PSVersion version)
  11114. {
  11115. Version = version;
  11116. Deserialize(data);
  11117. }
  11118. ​
  11119. public VariableBag(PSVersion version)
  11120. {
  11121. Version = version;
  11122. }
  11123. }
  11124. }
  11125. '@
  11126. $ErrorActionPreference = 'Stop'
  11127. $binPath = "$env:_work\BIN\LibTSforge.dll"
  11128. $psMajorVer = (Get-Host).Version.Major
  11129. $build = [System.Environment]::OSVersion.Version.Build
  11130. ​
  11131. if (Test-Path -LiteralPath $binPath) {
  11132. Write-Host "LibTSforge.dll found in BIN folder. Loading the DLL..."
  11133. Add-Type -Path $binPath
  11134. }
  11135. else {
  11136. $cp = [CodeDom.Compiler.CompilerParameters] [string[]]@("System.dll", "System.Core.dll", "System.ServiceProcess.dll", "System.Xml.dll", "System.Xml.Linq.dll")
  11137. if ($psMajorVer -le 2) { $cp.CompilerOptions = "/define:POWERSHELL2 /unsafe" } else { $cp.CompilerOptions = "/unsafe" }
  11138. $lang = if ($psMajorVer -gt 2) { "CSharp" } else { "CSharpVersion3" }
  11139. ​
  11140. $ctemp = "$env:SystemRoot\Temp\"
  11141. if (-Not (Test-Path -Path $ctemp)) { New-Item -Path $ctemp -ItemType Directory > $null }
  11142. $env:TMP = $ctemp
  11143. $env:TEMP = $ctemp
  11144. ​
  11145. $cp.GenerateInMemory = $true
  11146. Add-Type -Language $lang -TypeDefinition $src -CompilerParameters $cp
  11147. }
  11148. ​
  11149. if ($env:_debug -eq '0') {
  11150. [LibTSforge.Logger]::HideOutput = $true
  11151. }
  11152. [void][LibTSforge.Utils]::Wow64EnableWow64FsRedirection($false)
  11153. $ver = [LibTSforge.Utils]::DetectVersion()
  11154. $prod = [LibTSforge.SPP.SPPUtils]::DetectCurrentKey()
  11155. $tsactids = @($args)
  11156. ​
  11157. function Get-WmiInfo {
  11158. param ([string]$tsactid, [string]$property)
  11159. $query = "SELECT ID, $property FROM SoftwareLicensingProduct WHERE ID='$tsactid'"
  11160. $record = Get-WmiObject -Query $query
  11161. if ($record) {
  11162. return $record.$property
  11163. }
  11164. }
  11165. ​
  11166. function slGetSkuInfo($SkuId) {
  11167. $t = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0)
  11168. $t.DefinePInvokeMethod('SLOpen', 'slc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  11169. $t.DefinePInvokeMethod('SLClose', 'slc.dll', 22, 1, [IntPtr], @([IntPtr]), 1, 3).SetImplementationFlags(128)
  11170. $t.DefinePInvokeMethod('SLGetProductSkuInformation', 'slc.dll', 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  11171. $w = $t.CreateType()
  11172. $hSLC = 0
  11173. try {
  11174. [void]$w::SLOpen([ref]$hSLC)
  11175. $c = 0; $b = 0
  11176. $r = $w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, "msft:sl/EUL/PHONE/PUBLIC", [ref]$null, [ref]$c, [ref]$b)
  11177. return ($r -eq 0)
  11178. }
  11179. finally {
  11180. [void]$w::SLClose($hSLC)
  11181. }
  11182. }
  11183. ​
  11184. if (-not $env:resetstuff) {
  11185. foreach ($tsactid in $tsactids) {
  11186. try {
  11187. $activated = $null
  11188. $prodDes = Get-WmiInfo -tsactid $tsactid -property "Description"
  11189. $prodName = Get-WmiInfo -tsactid $tsactid -property "Name"
  11190. if ($prodName) {
  11191. $nameParts = $prodName -split ',', 2
  11192. $prodName = if ($nameParts.Count -gt 1) { ($nameParts[1].Trim() -split '[ ,]')[0] } else { $null }
  11193. }
  11194. if (-not $env:_vis -and -not $env:oldks) {
  11195. [LibTSforge.Modifiers.GenPKeyInstall]::InstallGenPKey($ver, $prod, $tsactid)
  11196. }
  11197. if ($prodName -match 'Office' -and $prodDes -notmatch 'KMS' -and -not (slGetSkuInfo($tsactid))) {
  11198. $licenseStatus = Get-WmiInfo -tsactid $tsactid -property "LicenseStatus"
  11199. if ($licenseStatus -eq 1) {
  11200. Write-Host "[$prodName] is already permanently activated." -ForegroundColor White -BackgroundColor DarkGreen
  11201. continue
  11202. }
  11203. }
  11204. if ($env:tsmethod -eq "StaticCID") {
  11205. [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  11206. $attempts = @(
  11207. @(100055, 1000043, 1338662172562478),
  11208. @(1345, 1003020, 6311608238084405)
  11209. )
  11210. foreach ($params in $attempts) {
  11211. [LibTSforge.Modifiers.SetIIDParams]::SetParams($ver, $prod, $tsactid, [LibTSforge.SPP.PKeyAlgorithm]::PKEY2009, $params[0], $params[1], $params[2])
  11212. $instId = [LibTSforge.SPP.SLApi]::GetInstallationID($tsactid)
  11213. $confId = [ActivationWs.ActivationHelper]::CallWebService(1, $instId, "31337-42069-123-456789-04-1337-2600.0000-2542001")
  11214. $result = [LibTSforge.SPP.SLApi]::DepositConfirmationID($tsactid, $instId, $confId)
  11215. if ($result -eq 0) { break }
  11216. }
  11217. [LibTSforge.SPP.SPPUtils]::RestartSPP($ver)
  11218. }
  11219. elseif ($env:tsmethod -eq "KMS4k") {
  11220. [LibTSforge.Activators.KMS4k]::Activate($ver, $prod, $tsactid)
  11221. }
  11222. else {
  11223. [LibTSforge.Activators.ZeroCID]::Activate($ver, $prod, $tsactid)
  11224. }
  11225. if ($env:tsmethod -eq "KMS4k") {
  11226. $GracePeriodStatus = Get-WmiInfo -tsactid $tsactid -property "GracePeriodRemaining"
  11227. if ($GracePeriodStatus -eq 259200 -or ([datetime]::Now.AddMinutes($GracePeriodStatus)).Year -gt 2038) {
  11228. if ((($build -ge 26100 -and $GracePeriodStatus -ge 259200) -or
  11229. ($build -lt 26100 -and $GracePeriodStatus -gt 259200))) {
  11230. $activated = 1
  11231. }
  11232. }
  11233. }
  11234. else {
  11235. $licenseStatus = Get-WmiInfo -tsactid $tsactid -property "LicenseStatus"
  11236. if ($licenseStatus -eq 1) { $activated = 1 }
  11237. }
  11238. if ($activated) {
  11239. if ($prodDes -match 'KMS' -and $prodDes -notmatch 'CLIENT') {
  11240. [LibTSforge.Modifiers.KMSHostCharge]::Charge($ver, $prod, $tsactid)
  11241. Write-Host "[$prodName] CSVLK is permanently activated with $env:tsmethod." -ForegroundColor White -BackgroundColor DarkGreen
  11242. Write-Host "[$prodName] CSVLK is charged with 25 clients for 30 days." -ForegroundColor White -BackgroundColor DarkGreen
  11243. }
  11244. else {
  11245. if ($env:tsmethod -eq "KMS4k") {
  11246. if ($build -ge 26100) {
  11247. Write-Host "[$prodName] is activated with KMS4k for over 4,000 years." -ForegroundColor White -BackgroundColor DarkGreen
  11248. Write-Host "From build 26100.7019, Windows will always display and stay at 180 days remaining if the actual period is longer." -ForegroundColor White -BackgroundColor Darkgray
  11249. }
  11250. else {
  11251. Write-Host "[$prodName] is activated till $([DateTime]::Now.AddMinutes($GracePeriodStatus).ToString('yyyy-MM-dd HH:mm:ss')) with $env:tsmethod." -ForegroundColor White -BackgroundColor DarkGreen
  11252. }
  11253. }
  11254. else {
  11255. Write-Host "[$prodName] is permanently activated with $env:tsmethod." -ForegroundColor White -BackgroundColor DarkGreen
  11256. }
  11257. }
  11258. }
  11259. else {
  11260. Write-Host "[$prodName] activation has failed." -ForegroundColor White -BackgroundColor DarkRed
  11261. $errcode = 3
  11262. }
  11263. }
  11264. catch {
  11265. $errcode = 3
  11266. Write-Host "$($_.Exception.Message)" -ForegroundColor Red -BackgroundColor Black
  11267. Write-Host "[$prodName] activation has failed." -ForegroundColor White -BackgroundColor DarkRed
  11268. }
  11269. }
  11270. }
  11271. ​
  11272. if ($env:resetstuff) {
  11273. try {
  11274. if (-not $env:_vis) { [LibTSforge.Modifiers.TamperedFlagsDelete]::DeleteTamperFlags($ver, $prod) }
  11275. [LibTSforge.SPP.SLApi]::RefreshLicenseStatus()
  11276. [LibTSforge.Modifiers.RearmReset]::Reset($ver, $prod)
  11277. [LibTSforge.Modifiers.GracePeriodReset]::Reset($ver, $prod)
  11278. if (-not $env:_vis) { [LibTSforge.Modifiers.KeyChangeLockDelete]::Delete($ver, $prod) }
  11279. }
  11280. catch {
  11281. $errcode = 3
  11282. Write-Host "$($_.Exception.Message)" -ForegroundColor Red -BackgroundColor Black
  11283. }
  11284. }
  11285. ​
  11286. Exit $errcode
  11287. :tsforge:
  11288. ​
  11289. ::========================================================================================================================================
  11290. ​
  11291. :: Get Windows Activation ID
  11292. ​
  11293. :wintsid:
  11294. $SysPath = "$env:SystemRoot\System32"
  11295. if (Test-Path "$env:SystemRoot\Sysnative\reg.exe") {
  11296. $SysPath = "$env:SystemRoot\Sysnative"
  11297. }
  11298. ​
  11299. function Windows-ActID {
  11300. param (
  11301. [string]$edition,
  11302. [string]$keytype
  11303. )
  11304. $filePatterns = @(
  11305. "$SysPath\spp\tokens\skus\$edition\$edition*.xrm-ms",
  11306. "$SysPath\spp\tokens\skus\Security-SPP-Component-SKU-$edition\*-$edition-*.xrm-ms"
  11307. )
  11308. switch ($keytype) {
  11309. "zero" {
  11310. $licenseTypes = @('OEM_DM', 'OEM_COA_SLP', 'OEM_COA_NSLP', 'MAK', 'RETAIL')
  11311. }
  11312. "ks" {
  11313. $licenseTypes = @('KMSCLIENT')
  11314. }
  11315. "avma" {
  11316. $licenseTypes = @('VIRTUAL_MACHINE')
  11317. }
  11318. "kmshost" {
  11319. $licenseTypes = @('KMS_')
  11320. }
  11321. }
  11322. $softwareLicensingProducts = Get-WmiObject -Query "SELECT ID, Description, LicenseFamily FROM SoftwareLicensingProduct WHERE ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f'" | Where-Object { $_.LicenseFamily -eq $edition }
  11323. $orderedLicenses = @()
  11324. foreach ($type in $licenseTypes) {
  11325. $orderedLicenses += $softwareLicensingProducts | Where-Object { $_.Description -match $type } | Select-Object -ExpandProperty ID
  11326. }
  11327. $fileIds = @()
  11328. $muiLockedIds = @()
  11329. $kmsCountedIdCounts = @{}
  11330. ​
  11331. $t = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0)
  11332. ​
  11333. $methods = @(
  11334. @{name = 'SLOpen'; returnType = [Int32]; parameters = @([IntPtr].MakeByRefType()) },
  11335. @{name = 'SLClose'; returnType = [Int32]; parameters = @([IntPtr]) },
  11336. @{name = 'SLGetProductSkuInformation'; returnType = [Int32]; parameters = @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()) },
  11337. @{name = 'SLGetLicense'; returnType = [Int32]; parameters = @([IntPtr], [Guid].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()) }
  11338. )
  11339. foreach ($method in $methods) {
  11340. $t.DefinePInvokeMethod($method.name, 'slc.dll', 22, 1, $method.returnType, $method.parameters, 1, 3).SetImplementationFlags(128)
  11341. }
  11342. $w = $t.CreateType()
  11343. $m = [Runtime.InteropServices.Marshal]
  11344. ​
  11345. function GetLicenseInfo($SkuId, $checkType) {
  11346. $result = $false
  11347. $c = 0; $b = 0
  11348. [void]$w::SLGetProductSkuInformation($hSLC, [ref][Guid]$SkuId, "fileId", [ref]$null, [ref]$c, [ref]$b)
  11349. $FileId = $m::PtrToStringUni($b)
  11350. $c = 0; $b = 0
  11351. [void]$w::SLGetLicense($hSLC, [ref][Guid]$FileId, [ref]$c, [ref]$b)
  11352. $blob = New-Object byte[] $c; $m::Copy($b, $blob, 0, $c)
  11353. $cont = [Text.Encoding]::UTF8.GetString($blob)
  11354. $xml = [xml]$cont.SubString($cont.IndexOf('<r'))
  11355. if ($checkType -eq 'MUI') {
  11356. $xml.licenseGroup.license[0].grant | foreach {
  11357. $_.allConditions.allConditions.productPolicies.policyStr | where { $_.name -eq 'Kernel-MUI-Language-Allowed' } | foreach {
  11358. if ($_.InnerText -ne 'EMPTY') { $result = $true }
  11359. }
  11360. }
  11361. }
  11362. elseif ($checkType -eq 'KMS') {
  11363. $xml.licenseGroup.license[0].grant | foreach {
  11364. $_.allConditions.allConditions.productPolicies.policyStr | where { $_.name -eq 'Security-SPP-KmsCountedIdList' } | foreach {
  11365. $result = ($_.InnerText.Replace(' ', '').Replace("`n", '') -split ',').Count
  11366. }
  11367. }
  11368. }
  11369. return $result
  11370. }
  11371. ​
  11372. $hSLC = 0; [void]$w::SLOpen([ref]$hSLC)
  11373. ​
  11374. foreach ($id in $orderedLicenses) {
  11375. if ($keytype -eq 'kmshost') {
  11376. $kmsCount = GetLicenseInfo $id 'KMS'
  11377. if ($kmsCount -gt 0) {
  11378. $kmsCountedIdCounts[$id] = $kmsCount
  11379. }
  11380. }
  11381. if ($edition -notcontains "CountrySpecific" -and (GetLicenseInfo $id 'MUI')) {
  11382. $muiLockedIds += $id
  11383. }
  11384. }
  11385. foreach ($filePattern in $filePatterns) {
  11386. $files = Get-ChildItem -Path $filePattern -Filter '*.xrm-ms' -ErrorAction SilentlyContinue
  11387. foreach ($file in $files) {
  11388. if ($null -ne $file.FullName) {
  11389. $content = Get-Content -Path $file.FullName -ErrorAction SilentlyContinue | Out-String
  11390. foreach ($id in $orderedLicenses) {
  11391. if ($content -match "name=`"productSkuId`">\{$id\}" -and -not ($file.Name -match 'Beta|Test')) {
  11392. $fileIds += $id
  11393. }
  11394. }
  11395. }
  11396. }
  11397. }
  11398. if ($kmsCountedIdCounts.Count -gt 0) {
  11399. $idWithMostIds = $kmsCountedIdCounts.GetEnumerator() | Sort-Object Value -Descending
  11400. $fileIds = $idWithMostIds | Select-Object -ExpandProperty Key
  11401. }
  11402. else {
  11403. if ($fileIds.Count -eq 0) {
  11404. $fileIds = $orderedLicenses
  11405. }
  11406. $fileIds = $orderedLicenses | Where-Object { $fileIds -contains $_ -and $muiLockedIds -notcontains $_ } | Select-Object -Unique
  11407. }
  11408. [void]$w::SLClose($hSLC)
  11409. $pkeyconfig = "$SysPath\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms"
  11410. if ($keytype -eq 'kmshost') {
  11411. $csvlkPath = "$SysPath\spp\tokens\pkeyconfig\pkeyconfig-csvlk.xrm-ms"
  11412. if (Test-Path $csvlkPath) {
  11413. $pkeyconfig = $csvlkPath
  11414. }
  11415. }
  11416. $data = [xml][Text.Encoding]::UTF8.GetString([Convert]::FromBase64String(([xml](get-content $pkeyconfig)).licenseGroup.license.otherInfo.infoTables.infoList.infoBin.InnerText))
  11417. $betaIds = @()
  11418. $excludedIds = @()
  11419. $checkedIds = @()
  11420. foreach ($id in $fileIds) {
  11421. $actConfig = $data.ProductKeyConfiguration.Configurations.Configuration | Where-Object { $_.ActConfigId -eq "{$id}" }
  11422. if ($actConfig) {
  11423. $productDescription = $actConfig.ProductDescription
  11424. $productEditionID = $actConfig.EditionID
  11425. if ($productDescription -match 'MUI locked|Tencent|Qihoo|WAU') {
  11426. $excludedIds += $id
  11427. continue
  11428. }
  11429. if ($productDescription -match 'Beta|RC |Next |Test|Pre-') {
  11430. $betaIds += $id
  11431. continue
  11432. }
  11433. if ($keytype -ne 'kmshost' -and $productEditionID -eq '$edition') {
  11434. $checkedIds += $id
  11435. continue
  11436. }
  11437. $refGroupId = $actConfig.RefGroupId
  11438. $publicKey = $data.ProductKeyConfiguration.PublicKeys.PublicKey | Where-Object { $_.GroupId -eq $refGroupId -and $_.AlgorithmId -eq 'msft:rm/algorithm/pkey/2009' }
  11439. if ($publicKey) {
  11440. $keyRanges = $data.ProductKeyConfiguration.KeyRanges.KeyRange | Where-Object { $_.RefActConfigId -eq "{$id}" }
  11441. foreach ($keyRange in $keyRanges) {
  11442. if ($keyRange.EulaType -match 'WAU') {
  11443. $excludedIds += $id
  11444. break
  11445. }
  11446. }
  11447. }
  11448. }
  11449. }
  11450. $prefinalIds = @()
  11451. $finalIds = @()
  11452. $prefinalIds = $fileIds | Where-Object { $excludedIds -notcontains $_ } | Select-Object -Unique
  11453. $finalIds = $prefinalIds | Where-Object { $betaIds -notcontains $_ } | Select-Object -Unique
  11454. if ($finalIds.Count -eq 0) {
  11455. $finalIds = $prefinalIds
  11456. }
  11457. if ($checkedIds.Count -gt 0) {
  11458. $finalIds = $checkedIds + $finalIds
  11459. }
  11460. $firstId = $finalIds | Select-Object -First 1
  11461. return $firstId.ToLower()
  11462. }
  11463. ​
  11464. Windows-ActID -edition "$env:tsedition" -keytype "$env:keytype"
  11465. :wintsid:
  11466. ​
  11467. ::========================================================================================================================================
  11468. ​
  11469. :: Get Office Activation ID
  11470. ​
  11471. :offtsid:
  11472. function Office-ActID {
  11473. param (
  11474. [string]$pkeypath,
  11475. [string]$edition,
  11476. [string]$keytype
  11477. )
  11478. ​
  11479. switch ($keytype) {
  11480. "zero" { $productKeyTypes = @("OEM:NONSLP","Volume:MAK","Retail") }
  11481. "ks" { $productKeyTypes = @("Volume:GVLK") }
  11482. }
  11483. ​
  11484. $data = [xml][Text.Encoding]::UTF8.GetString([Convert]::FromBase64String(([xml](Get-Content $pkeypath)).licenseGroup.license.otherInfo.infoTables.infoList.infoBin.InnerText))
  11485. $configurations = $data.ProductKeyConfiguration.Configurations.Configuration
  11486. ​
  11487. $filteredConfigs = @()
  11488. foreach ($type in $productKeyTypes) {
  11489. $filteredConfigs += $configurations | Where-Object {
  11490. $_.EditionId -eq $edition -and
  11491. $_.ProductKeyType -eq $type -and
  11492. $_.ProductDescription -notmatch 'demo|MSDN|PIN'
  11493. }
  11494. }
  11495. ​
  11496. $filterPreview = $filteredConfigs | Where-Object { $_.ProductDescription -notmatch 'preview|c2r' }
  11497. ​
  11498. if ($filterPreview.Count -ne 0) {
  11499. $filteredConfigs = $filterPreview
  11500. }
  11501. ​
  11502. $firstConfig = ($filteredConfigs | Select-Object -First 1).ActConfigID -replace '^\{|\}$', ''
  11503. return $firstConfig.ToLower()
  11504. }
  11505. ​
  11506. Office-ActID -pkeypath "$env:pkeypath" -edition "$env:_License" -keytype "$env:keytype"
  11507. :offtsid:
  11508. ​
  11509. ::========================================================================================================================================
  11510. ​
  11511. :: 1st column = Office version
  11512. :: 2nd column = Volume or free retail product
  11513. :: 3rd column = Retail product names that needs to be converted to the Volume product mentioned in 2nd column
  11514. :: Separator = "_"
  11515. ​
  11516. :tsksdata
  11517. ​
  11518. set f=
  11519. for %%# in (
  11520. :: Office 2013
  11521. 15_AccessVolume_-AccessRetail-
  11522. 15_AccessRuntimeRetail
  11523. 15_ExcelVolume_-ExcelRetail-
  11524. 15_GrooveVolume_-GrooveRetail-
  11525. 15_InfoPathVolume_-InfoPathRetail-
  11526. 15_LyncAcademicRetail
  11527. 15_LyncEntryRetail
  11528. 15_LyncVolume_-LyncRetail-
  11529. 15_MondoRetail
  11530. 15_MondoVolume_-O365BusinessRetail-O365HomePremRetail-O365ProPlusRetail-O365SmallBusPremRetail-
  11531. 15_OneNoteFreeRetail
  11532. 15_OneNoteVolume_-OneNoteRetail-
  11533. 15_OutlookVolume_-OutlookRetail-
  11534. 15_PowerPointVolume_-PowerPointRetail-
  11535. 15_ProjectProVolume_-ProjectProRetail-
  11536. 15_ProjectStdVolume_-ProjectStdRetail-
  11537. 15_ProPlusVolume_-ProPlusRetail-ProfessionalPipcRetail-ProfessionalRetail-
  11538. 15_PublisherVolume_-PublisherRetail-
  11539. 15_SPDRetail
  11540. 15_StandardVolume_-StandardRetail-HomeBusinessPipcRetail-HomeBusinessRetail-HomeStudentARMRetail-HomeStudentPlusARMRetail-HomeStudentRetail-PersonalPipcRetail-PersonalRetail-
  11541. 15_VisioProVolume_-VisioProRetail-
  11542. 15_VisioStdVolume_-VisioStdRetail-
  11543. 15_WordVolume_-WordRetail-
  11544. :: Office 2016
  11545. 16_AccessRuntimeRetail
  11546. 16_AccessVolume_-AccessRetail-
  11547. 16_ExcelVolume_-ExcelRetail-
  11548. 16_MondoRetail
  11549. 16_MondoVolume_-O365AppsBasicRetail-O365BusinessRetail-O365EduCloudRetail-O365HomePremRetail-O365ProPlusRetail-O365SmallBusPremRetail-
  11550. 16_OneNoteFreeRetail
  11551. 16_OneNoteVolume_-OneNoteRetail-OneNote2021Retail-
  11552. 16_OutlookVolume_-OutlookRetail-
  11553. 16_PowerPointVolume_-PowerPointRetail-
  11554. 16_ProjectProVolume_-ProjectProRetail-
  11555. 16_ProjectProXVolume
  11556. 16_ProjectStdVolume_-ProjectStdRetail-
  11557. 16_ProjectStdXVolume
  11558. 16_ProPlusVolume_-ProPlusRetail-ProfessionalPipcRetail-ProfessionalRetail-
  11559. 16_PublisherVolume_-PublisherRetail-
  11560. 16_SkypeServiceBypassRetail
  11561. 16_SkypeforBusinessEntryRetail
  11562. 16_SkypeforBusinessVolume_-SkypeforBusinessRetail-
  11563. 16_StandardVolume_-StandardRetail-HomeBusinessPipcRetail-HomeBusinessRetail-HomeStudentARMRetail-HomeStudentPlusARMRetail-HomeStudentRetail-HomeStudentVNextRetail-PersonalPipcRetail-PersonalRetail-
  11564. 16_VisioProVolume_-VisioProRetail-
  11565. 16_VisioProXVolume
  11566. 16_VisioStdVolume_-VisioStdRetail-
  11567. 16_VisioStdXVolume
  11568. 16_WordVolume_-WordRetail-
  11569. :: Office 2019
  11570. 16_AccessRuntime2019Retail
  11571. 16_Access2019Volume_-Access2019Retail-
  11572. 16_Excel2019Volume_-Excel2019Retail-
  11573. 16_Outlook2019Volume_-Outlook2019Retail-
  11574. 16_PowerPoint2019Volume_-PowerPoint2019Retail-
  11575. 16_ProjectPro2019Volume_-ProjectPro2019Retail-
  11576. 16_ProjectStd2019Volume_-ProjectStd2019Retail-
  11577. 16_ProPlus2019Volume_-ProPlus2019Retail-Professional2019Retail-
  11578. 16_Publisher2019Volume_-Publisher2019Retail-
  11579. 16_SkypeforBusiness2019Volume_-SkypeforBusiness2019Retail-
  11580. 16_SkypeforBusinessEntry2019Retail
  11581. 16_Standard2019Volume_-Standard2019Retail-HomeBusiness2019Retail-HomeStudentARM2019Retail-HomeStudentPlusARM2019Retail-HomeStudent2019Retail-Personal2019Retail-
  11582. 16_VisioPro2019Volume_-VisioPro2019Retail-
  11583. 16_VisioStd2019Volume_-VisioStd2019Retail-
  11584. 16_Word2019Volume_-Word2019Retail-
  11585. :: Office 2021
  11586. :: OneNote2021Volume KMS license is not available
  11587. 16_AccessRuntime2021Retail
  11588. 16_Access2021Volume_-Access2021Retail-
  11589. 16_Excel2021Volume_-Excel2021Retail-
  11590. 16_Outlook2021Volume_-Outlook2021Retail-
  11591. 16_OneNoteFree2021Retail
  11592. 16_PowerPoint2021Volume_-PowerPoint2021Retail-
  11593. 16_ProjectPro2021Volume_-ProjectPro2021Retail-
  11594. 16_ProjectStd2021Volume_-ProjectStd2021Retail-
  11595. 16_ProPlus2021Volume_-ProPlus2021Retail-Professional2021Retail-
  11596. 16_Publisher2021Volume_-Publisher2021Retail-
  11597. 16_SkypeforBusiness2021Volume_-SkypeforBusiness2021Retail-
  11598. 16_Standard2021Volume_-Standard2021Retail-HomeBusiness2021Retail-HomeStudent2021Retail-Personal2021Retail-
  11599. 16_VisioPro2021Volume_-VisioPro2021Retail-
  11600. 16_VisioStd2021Volume_-VisioStd2021Retail-
  11601. 16_Word2021Volume_-Word2021Retail-
  11602. :: Office 2024
  11603. 16_Access2024Volume_-Access2024Retail-
  11604. 16_Excel2024Volume_-Excel2024Retail-
  11605. 16_Outlook2024Volume_-Outlook2024Retail-
  11606. 16_PowerPoint2024Volume_-PowerPoint2024Retail-
  11607. 16_ProjectPro2024Volume_-ProjectPro2024Retail-
  11608. 16_ProjectStd2024Volume_-ProjectStd2024Retail-
  11609. 16_ProPlus2024Volume_-ProPlus2024Retail-
  11610. 16_SkypeforBusiness2024Volume
  11611. 16_Standard2024Volume_-Home2024Retail-HomeBusiness2024Retail-
  11612. 16_VisioPro2024Volume_-VisioPro2024Retail-
  11613. 16_VisioStd2024Volume_-VisioStd2024Retail-
  11614. 16_Word2024Volume_-Word2024Retail-
  11615. ) do (
  11616. for /f "tokens=1-3 delims=_" %%A in ("%%#") do (
  11617. ​
  11618. if %1==chkprod if "%oVer%"=="%%A" if not defined foundprod (
  11619. if /i "%%B"=="%2" set foundprod=1
  11620. )
  11621. ​
  11622. if %1==getinfo if "%oVer%"=="%%A" (
  11623. echo: %%C | find /i "-%2-" %nul% && (
  11624. set _License=%%B
  11625. set _altoffid=%%B
  11626. )
  11627. )
  11628. ​
  11629. )
  11630. )
  11631. exit /b
  11632. ​
  11633. ::========================================================================================================================================
  11634. ​
  11635. :ts_getedition
  11636. ​
  11637. set tsedition=
  11638. set _wtarget=
  11639. ​
  11640. if %_wmic% EQU 1 set "chkedi=for /f "tokens=2 delims==" %%a in ('"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL) get LicenseFamily /VALUE" %nul6%')"
  11641. if %_wmic% EQU 0 set "chkedi=for /f "tokens=2 delims==" %%a in ('%psc% "(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}" %nul6%')"
  11642. %chkedi% do if not errorlevel 1 call set "_wtarget= !_wtarget! %%a "
  11643. ​
  11644. :: SKU and Edition ID database
  11645. ​
  11646. for %%# in (
  11647. 1:Ultimate
  11648. 2:HomeBasic
  11649. 3:HomePremium
  11650. 4:Enterprise
  11651. 5:HomeBasicN
  11652. 6:Business
  11653. 7:ServerStandard
  11654. 8:ServerDatacenter
  11655. 9:ServerSBSStandard
  11656. 10:ServerEnterprise
  11657. 11:Starter
  11658. 12:ServerDatacenterCore
  11659. 13:ServerStandardCore
  11660. 14:ServerEnterpriseCore
  11661. 15:ServerEnterpriseIA64
  11662. 16:BusinessN
  11663. 17:ServerWeb
  11664. 18:ServerHPC
  11665. 19:ServerHomeStandard
  11666. 20:ServerStorageExpress
  11667. 21:ServerStorageStandard
  11668. 22:ServerStorageWorkgroup
  11669. 23:ServerStorageEnterprise
  11670. 24:ServerWinSB
  11671. 25:ServerSBSPremium
  11672. 26:HomePremiumN
  11673. 27:EnterpriseN
  11674. 28:UltimateN
  11675. 29:ServerWebCore
  11676. 30:ServerMediumBusinessManagement
  11677. 31:ServerMediumBusinessSecurity
  11678. 32:ServerMediumBusinessMessaging
  11679. 33:ServerWinFoundation
  11680. 34:ServerHomePremium
  11681. 35:ServerWinSBV
  11682. 36:ServerStandardV
  11683. 37:ServerDatacenterV
  11684. 38:ServerEnterpriseV
  11685. 39:ServerDatacenterVCore
  11686. 40:ServerStandardVCore
  11687. 41:ServerEnterpriseVCore
  11688. 42:ServerHyperCore
  11689. 43:ServerStorageExpressCore
  11690. 44:ServerStorageStandardCore
  11691. 45:ServerStorageWorkgroupCore
  11692. 46:ServerStorageEnterpriseCore
  11693. 47:StarterN
  11694. 48:Professional
  11695. 49:ProfessionalN
  11696. 50:ServerSolution
  11697. 51:ServerForSBSolutions
  11698. 52:ServerSolutionsPremium
  11699. 53:ServerSolutionsPremiumCore
  11700. 54:ServerSolutionEM
  11701. 55:ServerForSBSolutionsEM
  11702. 56:ServerEmbeddedSolution
  11703. 57:ServerEmbeddedSolutionCore
  11704. 58:ProfessionalEmbedded
  11705. 59:ServerEssentialManagement
  11706. 60:ServerEssentialAdditional
  11707. 61:ServerEssentialManagementSvc
  11708. 62:ServerEssentialAdditionalSvc
  11709. 63:ServerSBSPremiumCore
  11710. 64:ServerHPCV
  11711. 65:Embedded
  11712. 66:StarterE
  11713. 67:HomeBasicE
  11714. 68:HomePremiumE
  11715. 69:ProfessionalE
  11716. 70:EnterpriseE
  11717. 71:UltimateE
  11718. 72:EnterpriseEval
  11719. 74:Prerelease
  11720. 76:ServerMultiPointStandard
  11721. 77:ServerMultiPointPremium
  11722. 79:ServerStandardEval
  11723. 80:ServerDatacenterEval
  11724. 81:PrereleaseARM
  11725. 82:PrereleaseN
  11726. 84:EnterpriseNEval
  11727. 85:EmbeddedAutomotive
  11728. 86:EmbeddedIndustryA
  11729. 87:ThinPC
  11730. 88:EmbeddedA
  11731. 89:EmbeddedIndustry
  11732. 90:EmbeddedE
  11733. 91:EmbeddedIndustryE
  11734. 92:EmbeddedIndustryAE
  11735. 93:ProfessionalPlus
  11736. 95:ServerStorageWorkgroupEval
  11737. 96:ServerStorageStandardEval
  11738. 97:CoreARM
  11739. 98:CoreN
  11740. 99:CoreCountrySpecific
  11741. 100:CoreSingleLanguage
  11742. 101:Core
  11743. 103:ProfessionalWMC
  11744. 104:MobileCore
  11745. 105:EmbeddedIndustryEval
  11746. 106:EmbeddedIndustryEEval
  11747. 107:EmbeddedEval
  11748. 108:EmbeddedEEval
  11749. 109:CoreSystemServer
  11750. 110:ServerCloudStorage
  11751. 111:CoreConnected
  11752. 112:ProfessionalStudent
  11753. 113:CoreConnectedN
  11754. 114:ProfessionalStudentN
  11755. 115:CoreConnectedSingleLanguage
  11756. 116:CoreConnectedCountrySpecific
  11757. 117:ConnectedCar
  11758. 118:IndustryHandheld
  11759. 119:PPIPRO
  11760. 120:ServerARM64
  11761. 121:Education
  11762. 122:EducationN
  11763. 123:IoTUAP
  11764. 124:ServerHI
  11765. 125:EnterpriseS
  11766. 126:EnterpriseSN
  11767. 127:ProfessionalS
  11768. 128:ProfessionalSN
  11769. 129:EnterpriseSEval
  11770. 130:EnterpriseSNEval
  11771. 131:IoTUAPCommercial
  11772. 133:MobileEnterprise
  11773. 134:AnalogOneCoreEnterprise
  11774. 135:AnalogOneCore
  11775. 136:Holographic
  11776. 138:ProfessionalSingleLanguage
  11777. 139:ProfessionalCountrySpecific
  11778. 140:EnterpriseSubscription
  11779. 141:EnterpriseSubscriptionN
  11780. 143:ServerDatacenterNano
  11781. 144:ServerStandardNano
  11782. 145:ServerDatacenterACor
  11783. 146:ServerStandardACor
  11784. 147:ServerDatacenterCor
  11785. 148:ServerStandardCor
  11786. 149:UtilityVM
  11787. 159:ServerDatacenterEvalCor
  11788. 160:ServerStandardEvalCor
  11789. 161:ProfessionalWorkstation
  11790. 162:ProfessionalWorkstationN
  11791. 163:ServerAzure
  11792. 164:ProfessionalEducation
  11793. 165:ProfessionalEducationN
  11794. 168:ServerAzureCor
  11795. 169:ServerAzureNano
  11796. 171:EnterpriseG
  11797. 172:EnterpriseGN
  11798. 173:BusinessSubscription
  11799. 174:BusinessSubscriptionN
  11800. 175:ServerRdsh
  11801. 178:Cloud
  11802. 179:CloudN
  11803. 180:HubOS
  11804. 182:OneCoreUpdateOS
  11805. 183:CloudE
  11806. 184:Andromeda
  11807. 185:IoTOS
  11808. 186:CloudEN
  11809. 187:IoTEdgeOS
  11810. 188:IoTEnterprise
  11811. 189:ModernPC
  11812. 191:IoTEnterpriseS
  11813. 192:SystemOS
  11814. 193:NativeOS
  11815. 194:GameCoreXbox
  11816. 195:GameOS
  11817. 196:DurangoHostOS
  11818. 197:ScarlettHostOS
  11819. 198:Keystone
  11820. 199:CloudHost
  11821. 200:CloudMOS
  11822. 201:CloudCore
  11823. 202:CloudEditionN
  11824. 203:CloudEdition
  11825. 204:WinVOS
  11826. 205:IoTEnterpriseSK
  11827. 206:IoTEnterpriseK
  11828. 207:IoTEnterpriseSEval
  11829. 208:AgentBridge
  11830. 209:NanoHost
  11831. 210:WNC
  11832. 406:ServerAzureStackHCICor
  11833. 407:ServerTurbine
  11834. 408:ServerTurbineCor
  11835. ​
  11836. REM Some old edition names with same SKU ID
  11837. ​
  11838. 4:ProEnterprise
  11839. 6:ProStandard
  11840. 10:ProSBS
  11841. 16:ProStandardN
  11842. 18:ServerComputeCluster
  11843. 19:ServerHome
  11844. 30:ServerMidmarketStandard
  11845. 31:ServerMidmarketEdge
  11846. 32:ServerMidmarketPremium
  11847. 33:ServerSBSPrime
  11848. 42:ServerHyper
  11849. 64:ServerComputeClusterV
  11850. 85:EmbeddedIapetus
  11851. 86:EmbeddedTethys
  11852. 88:EmbeddedDione
  11853. 89:EmbeddedRhea
  11854. 90:EmbeddedEnceladus
  11855. 109:ServerNano
  11856. 124:ServerCloudHostInfrastructure
  11857. 133:MobileBusiness
  11858. 134:HololensEnterprise
  11859. 145:ServerDatacenterSCor
  11860. 146:ServerStandardSCor
  11861. 147:ServerDatacenterWSCor
  11862. 148:ServerStandardWSCor
  11863. 189:Lite
  11864. ) do (
  11865. for /f "tokens=1-2 delims=:" %%A in ("%%#") do if "%osSKU%"=="%%A" if not defined tsedition (
  11866. echo "%_wtarget%" | find /i " %%B " %nul% && set tsedition=%%B
  11867. )
  11868. )
  11869. ​
  11870. if defined tsedition exit /b
  11871. ​
  11872. set d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('GetEditionNameFromId', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [IntPtr].MakeByRefType()), 1, 3);
  11873. set d1=%d1% $out = 0; [void]$TypeBuilder.CreateType()::GetEditionNameFromId(%osSKU%, [ref]$out);$s=[Runtime.InteropServices.Marshal]::PtrToStringUni($out); $s
  11874. ​
  11875. for %%# in (pkeyhelper.dll) do @if not "%%~$PATH:#"=="" (
  11876. for /f %%a in ('%psc% "%d1%"') do if not errorlevel 1 (
  11877. echo "%_wtarget%" | find /i " %%a " %nul% && set tsedition=%%a
  11878. )
  11879. )
  11880. ​
  11881. exit /b
  11882. ​
  11883. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  11884. ​
  11885. :: Online KMS activation, external server selection and renewal task creation removed.
  11886. :: Shared local helpers used by the other modules are retained below.
  11887. ​
  11888. :ks_osppready
  11889. ​
  11890. if not defined _config exit /b
  11891. ​
  11892. echo: %_config% | find /i "propertyBag" %nul1% && (
  11893. set "_osppt=REG_DWORD"
  11894. set "_osppready=%o15c2r_reg%"
  11895. ) || (
  11896. set "_osppt=REG_SZ"
  11897. set "_osppready=%_config%"
  11898. )
  11899. ​
  11900. reg add %_osppready% /f /v %_altoffid%.OSPPReady /t %_osppt% /d 1 %nul1%
  11901. ​
  11902. :: Office builds before 16.0.10730.20102 need the Installed license product ID in ProductReleaseIds, otherwise product info may not fully reflect
  11903. ​
  11904. if exist "%_oLPath%\Word2019VL_KMS_Client_AE*.xrm-ms" exit /b
  11905. ​
  11906. reg query %_prids% | findstr /I "%_altoffid%" %nul1%
  11907. if %errorlevel% NEQ 0 (
  11908. for /f "skip=2 tokens=2*" %%a in ('reg query %_prids%') do reg add %_prids% /t REG_SZ /d "%%b,%_altoffid%" /f %nul1%
  11909. )
  11910. exit /b
  11911. ​
  11912. ::========================================================================================================================================
  11913. ​
  11914. ​
  11915. :_taskclear-cache
  11916. ​
  11917. set w=
  11918. for %%# in (SppE%w%xtComObj.exe sppsvc.exe SLsvc.exe) do (
  11919. reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ima%w%ge File Execu%w%tion Options\%%#" /f %nul%
  11920. )
  11921. ​
  11922. set "OPPk=SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform"
  11923. ​
  11924. if %winbuild% LSS 7600 (
  11925. reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SL" %nul% && (
  11926. set "SPPk=SOFTWARE\Microsoft\Windows NT\CurrentVersion\SL"
  11927. )
  11928. )
  11929. if not defined SPPk (
  11930. set "SPPk=SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform"
  11931. )
  11932. ​
  11933. set "slp=SoftwareLicensingProduct"
  11934. set "ospp=OfficeSoftwareProtectionProduct"
  11935. ​
  11936. set "_wApp=55c92734-d682-4d71-983e-d6ec3f16059f"
  11937. set "_oApp=0ff1ce15-a989-479d-af46-f275c6370663"
  11938. set "_oA14=59a52881-a989-479d-af46-f275c6370663"
  11939. ​
  11940. %nul% reg delete "HKLM\%SPPk%" /f /v KeyManagementServiceName
  11941. %nul% reg delete "HKLM\%SPPk%" /f /v KeyManagementServiceName /reg:32
  11942. %nul% reg delete "HKLM\%SPPk%" /f /v KeyManagementServicePort
  11943. %nul% reg delete "HKLM\%SPPk%" /f /v KeyManagementServicePort /reg:32
  11944. %nul% reg delete "HKLM\%SPPk%" /f /v DisableDnsPublishing
  11945. %nul% reg delete "HKLM\%SPPk%" /f /v DisableKeyManagementServiceHostCaching
  11946. %nul% reg delete "HKLM\%SPPk%\%_wApp%" /f
  11947. if %winbuild% GEQ 9200 (
  11948. %nul% reg delete "HKLM\%SPPk%\%_oApp%" /f
  11949. %nul% reg delete "HKLM\%SPPk%\%_oApp%" /f /reg:32
  11950. )
  11951. if %winbuild% GEQ 9600 (
  11952. %nul% reg delete "HKU\S-1-5-20\%SPPk%\%_wApp%" /f
  11953. %nul% reg delete "HKU\S-1-5-20\%SPPk%\%_oApp%" /f
  11954. )
  11955. %nul% reg delete "HKLM\%OPPk%" /f /v KeyManagementServiceName
  11956. %nul% reg delete "HKLM\%OPPk%" /f /v KeyManagementServicePort
  11957. %nul% reg delete "HKLM\%OPPk%" /f /v DisableDnsPublishing
  11958. %nul% reg delete "HKLM\%OPPk%" /f /v DisableKeyManagementServiceHostCaching
  11959. %nul% reg delete "HKLM\%OPPk%\%_oA14%" /f
  11960. %nul% reg delete "HKLM\%OPPk%\%_oApp%" /f
  11961. ​
  11962. exit /b
  11963. ​
  11964. ::========================================================================================================================================
  11965. ​
  11966. ​
  11967. :k_pkey
  11968. ​
  11969. call :dk_reflection
  11970. ​
  11971. set d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('SkuGetProductKeyForEdition', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([int], [String], [String].MakeByRefType(), [String].MakeByRefType()), 1, 3);
  11972. set d1=%d1% $out = ''; [void]$TypeBuilder.CreateType()::SkuGetProductKeyForEdition(%1, %2, [ref]$out, [ref]$null); $out
  11973. ​
  11974. set pkey=
  11975. for /f %%a in ('%psc% "%d1%"') do if not errorlevel 1 (set pkey=%%a)
  11976. exit /b
  11977. ​
  11978. :: Get channel name for the key which was extracted from pkeyhelper.dll
  11979. ​
  11980. :k_pkeychannel
  11981. ​
  11982. set k=%1
  11983. set m=[Runtime.InteropServices.Marshal]
  11984. set p=%SysPath%\spp\tokens\pkeyconfig\pkeyconfig.xrm-ms
  11985. ​
  11986. set d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('PidGenX', 'pidgenx.dll', 'Public, Static', 1, [int], @([String], [String], [String], [int], [IntPtr], [IntPtr], [IntPtr]), 1, 3);
  11987. set d1=%d1% $r = [byte[]]::new(0x04F8); $r[0] = 0xF8; $r[1] = 0x04; $f = %m%::AllocHGlobal(0x04F8); %m%::Copy($r, 0, $f, 0x04F8);
  11988. set d1=%d1% [void]$TypeBuilder.CreateType()::PidGenX('%k%', '%p%', '00000', 0, 0, 0, $f); %m%::Copy($f, $r, 0, 0x04F8); %m%::FreeHGlobal($f); [Text.Encoding]::Unicode.GetString($r, 1016, 128)
  11989. ​
  11990. set pkeychannel=
  11991. for /f %%a in ('%psc% "%d1%"') do if not errorlevel 1 (set pkeychannel=%%a)
  11992. exit /b
  11993. ​
  11994. ​
  11995. :msiofficedata
  11996. ​
  11997. for %%# in (
  11998. 14_4d463c2c-0505-4626-8cdb-a4da82e2d8ed_0015_AccessR
  11999. 14_745fb377-0a59-4ca9-b9a9-c359557a2c4e_001C_AccessRuntimeR
  12000. 14_95ab3ec8-4106-4f9d-b632-03c019d1d23f_0015_AccessVL
  12001. 14_4eaff0d0-c6cb-4187-94f3-c7656d49a0aa_0016_ExcelR_[HSExcelR]
  12002. 14_71dc86ff-f056-40d0-8ffb-9592705c9b76_0016_ExcelVL
  12003. 14_7004b7f0-6407-4f45-8eac-966e5f868bde_00BA_GrooveR
  12004. 14_fdad0dfa-417d-4b4f-93e4-64ea8867b7fd_00BA_GrooveVL
  12005. 14_7b7d1f17-fdcb-4820-9789-9bec6e377821_0013_HomeBusinessR_[HomeBusinessDemoR]
  12006. 14_19316117-30a8-4773-8fd9-7f7231f4e060_011E_HomeBusinessSubR
  12007. 14_09e2d37e-474b-4121-8626-58ad9be5776f_002F_HomeStudentR_[HomeStudentDemoR]
  12008. 14_ef1da464-01c8-43a6-91af-e4e5713744f9_0044_InfoPathR
  12009. 14_85e22450-b741-430c-a172-a37962c938af_0044_InfoPathVL
  12010. 14_14f5946a-debc-4716-babc-7e2c240fec08_000F_MondoR
  12011. 14_533b656a-4425-480b-8e30-1a2358898350_000F_MondoVL
  12012. 14_c1ceda8b-c578-4d5d-a4aa-23626be4e234_003D_ProfessionalR_[OEM-SingleImage]Exception
  12013. 14_3f7aa693-9a7e-44fc-9309-bb3d8e604925_00A1_OneNoteR_[HSOneNoteR]
  12014. 14_6860b31f-6a67-48b8-84b9-e312b3485c4b_00A1_OneNoteVL
  12015. 14_fbf4ac36-31c8-4340-8666-79873129cf40_001A_OutlookR
  12016. 14_a9aeabd8-63b8-4079-a28e-f531807fd6b8_001A_OutlookVL
  12017. 14_acb51361-c0db-4895-9497-1831c41f31a6_0033_PersonalR_[PersonalDemoR,PersonalPrepaidR]
  12018. 14_133c8359-4e93-4241-8118-30bb18737ea0_0018_PowerPointR_[HSPowerPointR]
  12019. 14_38252940-718c-4aa6-81a4-135398e53851_0018_PowerPointVL
  12020. 14_8b559c37-0117-413e-921b-b853aeb6e210_0014_ProfessionalR_[ProfessionalAcadR,ProfessionalDemoR]
  12021. 14_725714d7-d58f-4d12-9fa8-35873c6f7215_003B_ProjectProR_[ProjectProMSDNR]
  12022. 14_4d06f72e-fd50-4bc2-a24b-d448d7f17ef2_011F_ProjectProSubR
  12023. 14_1cf57a59-c532-4e56-9a7d-ffa2fe94b474_003B_ProjectProVL
  12024. 14_688f6589-2bd9-424e-a152-b13f36aa6de1_003A_ProjectStdR
  12025. 14_11b39439-6b93-4642-9570-f2eb81be2238_003A_ProjectStdVL
  12026. 14_71af7e84-93e6-4363-9b69-699e04e74071_0011_ProPlusR_[ProPlusAcadR,ProPlusMSDNR,Sub4R]
  12027. 14_e98ef0c0-71c4-42ce-8305-287d8721e26c_011D_ProPlusSubR
  12028. 14_fdf3ecb9-b56f-43b2-a9b8-1b48b6bae1a7_0011_ProPlusVL_[ProPlusAcadVL]
  12029. 14_98677603-a668-4fa4-9980-3f1f05f78f69_0019_PublisherR
  12030. 14_3d014759-b128-4466-9018-e80f6320d9d0_0019_PublisherVL
  12031. 14_dbe3aee0-5183-4ff7-8142-66050173cb01_008B_SmallBusBasicsR_[SmallBusBasicsMSDNR]
  12032. 14_8090771e-d41a-4482-929e-de87f1f47e46_008B_SmallBusBasicsVL
  12033. 14_b78df69e-0966-40b1-ae85-30a5134dedd0_0017_SPDR
  12034. 14_d3422cfb-8d8b-4ead-99f9-eab0ccd990d7_0012_StandardR
  12035. 14_1f76e346-e0be-49bc-9954-70ec53a4fcfe_0012_StandardVL_[StandardAcadVL]
  12036. 14_2745e581-565a-4670-ae90-6bf7c57ffe43_0066_StarterR
  12037. 14_66cad568-c2dc-459d-93ec-2f3cb967ee34_0057_VisioSIR_Prem[Pro,Std]Exception
  12038. 14_36756cb8-8e69-4d11-9522-68899507cd6a_0057_VisioSIVL_Prem[Pro,Std]Exception
  12039. 14_db3bbc9c-ce52-41d1-a46f-1a1d68059119_001B_WordR_[HSWordR]
  12040. 14_98d4050e-9c98-49bf-9be1-85e12eb3ab13_001B_WordVL
  12041. :: Office 2013
  12042. 15_ab4d047b-97cf-4126-a69f-34df08e2f254_0015_AccessRetail
  12043. 15_259de5be-492b-44b3-9d78-9645f848f7b0_001C_AccessRuntimeRetail
  12044. 15_4374022d-56b8-48c1-9bb7-d8f2fc726343_0015_AccessVolume
  12045. 15_1b1d9bd5-12ea-4063-964c-16e7e87d6e08_0016_ExcelRetail
  12046. 15_ac1ae7fd-b949-4e04-a330-849bc40638cf_0016_ExcelVolume
  12047. 15_cfaf5356-49e3-48a8-ab3c-e729ab791250_00BA_GrooveRetail
  12048. 15_4825ac28-ce41-45a7-9e6e-1fed74057601_00BA_GrooveVolume
  12049. 15_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_00E7_HomeBusinessPipcRetail
  12050. 15_cd256150-a898-441f-aac0-9f8f33390e45_0013_HomeBusinessRetail
  12051. 15_1fdfb4e4-f9c9-41c4-b055-c80daf00697d_00CE_HomeStudentARMRetail
  12052. 15_ebef9f05-5273-404a-9253-c5e252f50555_00DA_HomeStudentPlusARMRetail
  12053. 15_98685d21-78bd-4c62-bc4f-653344a63035_002F_HomeStudentRetail
  12054. 15_44984381-406e-4a35-b1c3-e54f499556e2_0044_InfoPathRetail
  12055. 15_9e016989-4007-42a6-8051-64eb97110cf2_0044_InfoPathVolume
  12056. 15_9103f3ce-1084-447a-827e-d6097f68c895_00EA_LyncAcademicRetail
  12057. 15_ff693bf4-0276-4ddb-bb42-74ef1a0c9f4d_012D_LyncEntryRetail
  12058. 15_fada6658-bfc6-4c4e-825a-59a89822cda8_012C_LyncRetail
  12059. 15_e1264e10-afaf-4439-a98b-256df8bb156f_012C_LyncVolume
  12060. 15_3169c8df-f659-4f95-9cc6-3115e6596e83_000F_MondoRetail
  12061. 15_f33485a0-310b-4b72-9a0e-b1d605510dbd_000F_MondoVolume
  12062. 15_3391e125-f6e4-4b1e-899c-a25e6092d40d_00A1_OneNoteFreeRetail
  12063. 15_8b524bcc-67ea-4876-a509-45e46f6347e8_00A1_OneNoteRetail
  12064. 15_b067e965-7521-455b-b9f7-c740204578a2_00A1_OneNoteVolume
  12065. 15_12004b48-e6c8-4ffa-ad5a-ac8d4467765a_001A_OutlookRetail
  12066. 15_8d577c50-ae5e-47fd-a240-24986f73d503_001A_OutlookVolume
  12067. 15_5aab8561-1686-43f7-9ff5-2c861da58d17_00E6_PersonalPipcRetail
  12068. 15_17e9df2d-ed91-4382-904b-4fed6a12caf0_0033_PersonalRetail
  12069. 15_31743b82-bfbc-44b6-aa12-85d42e644d5b_0018_PowerPointRetail
  12070. 15_e40dcb44-1d5c-4085-8e8f-943f33c4f004_0018_PowerPointVolume
  12071. 15_4e26cac1-e15a-4467-9069-cb47b67fe191_00E8_ProfessionalPipcRetail
  12072. 15_44bc70e2-fb83-4b09-9082-e5557e0c2ede_0014_ProfessionalRetail
  12073. 15_f2435de4-5fc0-4e5b-ac97-34f515ec5ee7_003B_ProjectProRetail
  12074. 15_ed34dc89-1c27-4ecd-8b2f-63d0f4cedc32_003B_ProjectProVolume
  12075. 15_5517e6a2-739b-4822-946f-7f0f1c5934b1_003A_ProjectStdRetail
  12076. 15_2b9e4a37-6230-4b42-bee2-e25ce86c8c7a_003A_ProjectStdVolume
  12077. 15_064383fa-1538-491c-859b-0ecab169a0ab_0011_ProPlusRetail
  12078. 15_2b88c4f2-ea8f-43cd-805e-4d41346e18a7_0011_ProPlusVolume
  12079. 15_c3a0814a-70a4-471f-af37-2313a6331111_0019_PublisherRetail
  12080. 15_38ea49f6-ad1d-43f1-9888-99a35d7c9409_0019_PublisherVolume
  12081. 15_ba3e3833-6a7e-445a-89d0-7802a9a68588_0017_SPDRetail
  12082. 15_32255c0a-16b4-4ce2-b388-8a4267e219eb_0012_StandardRetail
  12083. 15_a24cca51-3d54-4c41-8a76-4031f5338cb2_0012_StandardVolume
  12084. 15_15d12ad4-622d-4257-976c-5eb3282fb93d_0051_VisioProRetail
  12085. 15_3e4294dd-a765-49bc-8dbd-cf8b62a4bd3d_0051_VisioProVolume
  12086. 15_dae597ce-5823-4c77-9580-7268b93a4b23_0053_VisioStdRetail
  12087. 15_44a1f6ff-0876-4edb-9169-dbb43101ee89_0053_VisioStdVolume
  12088. 15_191509f2-6977-456f-ab30-cf0492b1e93a_001B_WordRetail
  12089. 15_9cedef15-be37-4ff0-a08a-13a045540641_001B_WordVolume
  12090. :: Office 365 - 15.0 version
  12091. 15_befee371-a2f5-4648-85db-a2c55fdf324c_00E9_O365BusinessRetail
  12092. 15_537ea5b5-7d50-4876-bd38-a53a77caca32_00D6_O365HomePremRetail
  12093. 15_149dbce7-a48e-44db-8364-a53386cd4580_00D4_O365ProPlusRetail
  12094. 15_bacd4614-5bef-4a5e-bafc-de4c788037a2_00D5_O365SmallBusPremRetail
  12095. :: Office 365 - 16.0 version
  12096. 16_6337137e-7c07-4197-8986-bece6a76fc33_00E9_O365BusinessRetail
  12097. 16_2f5c71b4-5b7a-4005-bb68-f9fac26f2ea3_00D6_O365EduCloudRetail
  12098. 16_537ea5b5-7d50-4876-bd38-a53a77caca32_00D6_O365HomePremRetail
  12099. 16_149dbce7-a48e-44db-8364-a53386cd4580_00D4_O365ProPlusRetail
  12100. 16_bacd4614-5bef-4a5e-bafc-de4c788037a2_00D5_O365SmallBusPremRetail
  12101. :: Office 2016
  12102. 16_bfa358b0-98f1-4125-842e-585fa13032e6_0015_AccessRetail
  12103. 16_9d9faf9e-d345-4b49-afce-68cb0a539c7c_001C_AccessRuntimeRetail
  12104. 16_3b2fa33f-cd5a-43a5-bd95-f49f3f546b0b_0015_AccessVolume
  12105. 16_424d52ff-7ad2-4bc7-8ac6-748d767b455d_0016_ExcelRetail
  12106. 16_685062a7-6024-42e7-8c5f-6bb9e63e697f_0016_ExcelVolume
  12107. 16_c02fb62e-1cd5-4e18-ba25-e0480467ffaa_00E7_HomeBusinessPipcRetail
  12108. 16_86834d00-7896-4a38-8fae-32f20b86fa2b_0013_HomeBusinessRetail
  12109. 16_090896a0-ea98-48ac-b545-ba5da0eb0c9c_00CE_HomeStudentARMRetail
  12110. 16_6bbe2077-01a4-4269-bf15-5bf4d8efc0b2_00DA_HomeStudentPlusARMRetail
  12111. 16_c28acdb8-d8b3-4199-baa4-024d09e97c99_002F_HomeStudentRetail
  12112. 16_e2127526-b60c-43e0-bed1-3c9dc3d5a468_002F_HomeStudentVNextRetail
  12113. 16_b21367df-9545-4f02-9f24-240691da0e58_000F_MondoRetail
  12114. 16_2cd0ea7e-749f-4288-a05e-567c573b2a6c_000F_MondoVolume
  12115. 16_436366de-5579-4f24-96db-3893e4400030_00A3_OneNoteFreeRetail
  12116. 16_83ac4dd9-1b93-40ed-aa55-ede25bb6af38_00A1_OneNoteRetail
  12117. 16_23b672da-a456-4860-a8f3-e062a501d7e8_00A1_OneNoteVolume
  12118. 16_5a670809-0983-4c2d-8aad-d3c2c5b7d5d1_001A_OutlookRetail
  12119. 16_50059979-ac6f-4458-9e79-710bcb41721a_001A_OutlookVolume
  12120. 16_5aab8561-1686-43f7-9ff5-2c861da58d17_00E6_PersonalPipcRetail
  12121. 16_a9f645a1-0d6a-4978-926a-abcb363b72a6_0033_PersonalRetail
  12122. 16_f32d1284-0792-49da-9ac6-deb2bc9c80b6_0018_PowerPointRetail
  12123. 16_9b4060c9-a7f5-4a66-b732-faf248b7240f_0018_PowerPointVolume
  12124. 16_4e26cac1-e15a-4467-9069-cb47b67fe191_00E8_ProfessionalPipcRetail
  12125. 16_d64edc00-7453-4301-8428-197343fafb16_0014_ProfessionalRetail
  12126. 16_0f42f316-00b1-48c5-ada4-2f52b5720ad0_003B_ProjectProRetail
  12127. 16_82f502b5-b0b0-4349-bd2c-c560df85b248_003B_ProjectProVolume
  12128. 16_16728639-a9ab-4994-b6d8-f81051e69833_003B_ProjectProXVolume
  12129. 16_e9f0b3fc-962f-4944-ad06-05c10b6bcd5e_003A_ProjectStdRetail
  12130. 16_82e6b314-2a62-4e51-9220-61358dd230e6_003A_ProjectStdVolume
  12131. 16_431058f0-c059-44c5-b9e7-ed2dd46b6789_003A_ProjectStdXVolume
  12132. 16_de52bd50-9564-4adc-8fcb-a345c17f84f9_0011_ProPlusRetail
  12133. 16_c47456e3-265d-47b6-8ca0-c30abbd0ca36_0011_ProPlusVolume
  12134. 16_6e0c1d99-c72e-4968-bcb7-ab79e03e201e_0019_PublisherRetail
  12135. 16_fcc1757b-5d5f-486a-87cf-c4d6dedb6032_0019_PublisherVolume
  12136. 16_971cd368-f2e1-49c1-aedd-330909ce18b6_012D_SkypeforBusinessEntryRetail
  12137. 16_418d2b9f-b491-4d7f-84f1-49e27cc66597_012C_SkypeforBusinessRetail
  12138. 16_03ca3b9a-0869-4749-8988-3cbc9d9f51bb_012C_SkypeforBusinessVolume
  12139. 16_9103f3ce-1084-447a-827e-d6097f68c895_012C_SkypeServiceBypassRetail
  12140. 16_4a31c291-3a12-4c64-b8ab-cd79212be45e_0012_StandardRetail
  12141. 16_0ed94aac-2234-4309-ba29-74bdbb887083_0012_StandardVolume
  12142. 16_2dfe2075-2d04-4e43-816a-eb60bbb77574_0051_VisioProRetail
  12143. 16_295b2c03-4b1c-4221-b292-1411f468bd02_0051_VisioProVolume
  12144. 16_0594dc12-8444-4912-936a-747ca742dbdb_0051_VisioProXVolume
  12145. 16_c76dbcbc-d71b-4f45-b5b3-b7494cb4e23e_0053_VisioStdRetail
  12146. 16_44151c2d-c398-471f-946f-7660542e3369_0053_VisioStdVolume
  12147. 16_1d1c6879-39a3-47a5-9a6d-aceefa6a289d_0053_VisioStdXVolume
  12148. 16_cacaa1bf-da53-4c3b-9700-11738ef1c2a5_001B_WordRetail
  12149. 16_c3000759-551f-4f4a-bcac-a4b42cbf1de2_001B_WordVolume
  12150. ) do (
  12151. for /f "tokens=1-5 delims=_" %%A in ("%%#") do (
  12152. ​
  12153. if "%oVer%"=="%%A" (
  12154. reg query "%1\Registration\{%%B}" /v ProductCode %nul2% | find /i "-%%C-" %nul% && (
  12155. reg query "%1\Common\InstalledPackages" %nul2% | find /i "-%%C-" %nul% && (
  12156. if defined _oIds (set _oIds=!_oIds! %%D) else (set _oIds=%%D)
  12157. if /i 003D==%%C set SingleImage=1
  12158. )
  12159. )
  12160. )
  12161. ​
  12162. )
  12163. )
  12164. exit /b
  12165. ​
  12166. ::========================================================================================================================================
  12167. ​
  12168. :: 1st column = Activation ID
  12169. :: 2nd column = GVLK / Free Office products keys
  12170. :: 3rd column = In case of Windows, its SKU ID. In case of Office, its Office version
  12171. :: 4th column = Edition ID
  12172. :: 5th column = In case of Windows, its Build Branch name in case same Edition ID is used in different OS versions with different key (For reference only)
  12173. :: In case of Office, its either a key type if its a free Office product or Retail product names that needs to be converted to the Edition ID mentioned in 4th column
  12174. :: In Office 2010, one highest VL edition from each primary product ID is selected, that's why Visio Prem key is mentioned but not for Visio Pro, Std
  12175. :: Separator = "_"
  12176. ​
  12177. ​
  12178. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  12179. ​
  12180. :check_actstatus
  12181. ​
  12182. cls
  12183. if not defined terminal (
  12184. mode 100, 36
  12185. %psc% "&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=35;$B.Height=300;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}" %nul%
  12186. )
  12187. ​
  12188. %psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':sppmgr\:.*';. ([scriptblock]::Create($f[1]))"
  12189. goto dk_done
  12190. ​
  12191. :sppmgr:
  12192. param (
  12193. [Parameter()]
  12194. [switch]
  12195. $All,
  12196. [Parameter()]
  12197. [switch]
  12198. $Dlv,
  12199. [Parameter()]
  12200. [switch]
  12201. $IID,
  12202. [Parameter()]
  12203. [switch]
  12204. $Pass
  12205. )
  12206. ​
  12207. function CONOUT($strObj)
  12208. {
  12209. Out-Host -Input $strObj
  12210. }
  12211. ​
  12212. function ExitScript($ExitCode = 0)
  12213. {
  12214. Exit $ExitCode
  12215. }
  12216. ​
  12217. if (-Not $PSVersionTable) {
  12218. "==== ERROR ====`r`n"
  12219. "Windows PowerShell 1.0 is not supported by this script."
  12220. ExitScript 1
  12221. }
  12222. ​
  12223. if ($ExecutionContext.SessionState.LanguageMode.value__ -NE 0) {
  12224. "==== ERROR ====`r`n"
  12225. "Windows PowerShell is not running in Full Language Mode."
  12226. ExitScript 1
  12227. }
  12228. ​
  12229. $winbuild = 1
  12230. try {
  12231. $winbuild = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("$env:SystemRoot\System32\kernel32.dll").FileBuildPart
  12232. } catch {
  12233. $winbuild = [int]([wmi]'Win32_OperatingSystem=@').BuildNumber
  12234. }
  12235. ​
  12236. if ($winbuild -EQ 1) {
  12237. "==== ERROR ====`r`n"
  12238. "Could not detect Windows build."
  12239. ExitScript 1
  12240. }
  12241. ​
  12242. if ($winbuild -LT 2600) {
  12243. "==== ERROR ====`r`n"
  12244. "This build of Windows is not supported by this script."
  12245. ExitScript 1
  12246. }
  12247. ​
  12248. if ($All.IsPresent)
  12249. {
  12250. $isAll = {CONOUT "`r"}
  12251. $noAll = {$null}
  12252. }
  12253. else
  12254. {
  12255. $isAll = {$null}
  12256. $noAll = {CONOUT "`r"}
  12257. }
  12258. $Dlv = $Dlv.IsPresent
  12259. $IID = $IID.IsPresent -Or $Dlv.IsPresent
  12260. ​
  12261. $NT6 = $winbuild -GE 6000
  12262. $NT7 = $winbuild -GE 7600
  12263. $NT8 = $winbuild -GE 9200
  12264. $NT9 = $winbuild -GE 9600
  12265. ​
  12266. $Admin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
  12267. ​
  12268. $line2 = "============================================================"
  12269. $line3 = "____________________________________________________________"
  12270. ​
  12271. function echoWindows
  12272. {
  12273. CONOUT "$line2"
  12274. CONOUT "=== Windows Status ==="
  12275. CONOUT "$line2"
  12276. & $noAll
  12277. }
  12278. ​
  12279. function echoOffice
  12280. {
  12281. if ($doMSG -EQ 0) {
  12282. return
  12283. }
  12284. ​
  12285. & $isAll
  12286. CONOUT "$line2"
  12287. CONOUT "=== Office Status ==="
  12288. CONOUT "$line2"
  12289. & $noAll
  12290. ​
  12291. $script:doMSG = 0
  12292. }
  12293. ​
  12294. function strGetRegistry($strKey, $strName)
  12295. {
  12296. try {
  12297. return [Microsoft.Win32.Registry]::GetValue($strKey, $strName, $null)
  12298. } catch {
  12299. return $null
  12300. }
  12301. }
  12302. ​
  12303. function CheckOhook
  12304. {
  12305. $ohook = 0
  12306. $paths = "${env:ProgramFiles}", "${env:ProgramW6432}", "${env:ProgramFiles(x86)}"
  12307. ​
  12308. 15, 16 | foreach `
  12309. {
  12310. $A = $_; $paths | foreach `
  12311. {
  12312. if (Test-Path "$($_)$('\Microsoft Office\Office')$($A)$('\sppc*dll')") {$ohook = 1}
  12313. }
  12314. }
  12315. ​
  12316. "System", "SystemX86" | foreach `
  12317. {
  12318. $A = $_; "Office 15", "Office" | foreach `
  12319. {
  12320. $B = $_; $paths | foreach `
  12321. {
  12322. if (Test-Path "$($_)$('\Microsoft ')$($B)$('\root\vfs\')$($A)$('\sppc*dll')") {$ohook = 1}
  12323. }
  12324. }
  12325. }
  12326. ​
  12327. if ($ohook -EQ 0) {
  12328. return
  12329. }
  12330. ​
  12331. & $isAll
  12332. CONOUT "$line2"
  12333. CONOUT "=== Office Ohook Status ==="
  12334. CONOUT "$line2"
  12335. $host.UI.WriteLine('Yellow', 'Black', "`r`nOhook for permanent Office activation is installed.`r`nYou can ignore the below mentioned Office activation status.")
  12336. & $noAll
  12337. }
  12338. ​
  12339. #region SSSS
  12340. function BoolToWStr($bVal) {
  12341. ("TRUE", "FALSE")[!$bVal]
  12342. }
  12343. ​
  12344. function InitializePInvoke($LaDll, $bOffice) {
  12345. $LaName = [IO.Path]::GetFileNameWithoutExtension($LaDll)
  12346. $SLApp = $NT7 -Or $bOffice -Or ($LaName -EQ 'sppc' -And [Diagnostics.FileVersionInfo]::GetVersionInfo("$SysPath\sppc.dll").FilePrivatePart -GE 16501)
  12347. $Win32 = $null
  12348. ​
  12349. $Marshal = [System.Runtime.InteropServices.Marshal]
  12350. $Module = [AppDomain]::CurrentDomain.DefineDynamicAssembly(($LaName+"_Assembly"), 'Run').DefineDynamicModule(($LaName+"_Module"), $False)
  12351. $Class = $Module.DefineType(($LaName+"_Methods"), 'Public, Abstract, Sealed, BeforeFieldInit', [Object], 0)
  12352. ​
  12353. $Class.DefinePInvokeMethod('SLClose', $LaDll, 22, 1, [Int32], @([IntPtr]), 1, 3).SetImplementationFlags(128)
  12354. $Class.DefinePInvokeMethod('SLOpen', $LaDll, 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  12355. $Class.DefinePInvokeMethod('SLGenerateOfflineInstallationId', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  12356. $Class.DefinePInvokeMethod('SLGetSLIDList', $LaDll, 22, 1, [Int32], @([IntPtr], [UInt32], [Guid].MakeByRefType(), [UInt32], [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  12357. $Class.DefinePInvokeMethod('SLGetLicensingStatusInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [Guid].MakeByRefType(), [IntPtr], [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  12358. $Class.DefinePInvokeMethod('SLGetPKeyInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  12359. $Class.DefinePInvokeMethod('SLGetProductSkuInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  12360. $Class.DefinePInvokeMethod('SLGetServiceInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  12361. if ($SLApp) {
  12362. $Class.DefinePInvokeMethod('SLGetApplicationInformation', $LaDll, 22, 1, [Int32], @([IntPtr], [Guid].MakeByRefType(), [String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  12363. }
  12364. if ($bOffice) {
  12365. $Win32 = $Class.CreateType()
  12366. return
  12367. }
  12368. if ($NT6) {
  12369. $Class.DefinePInvokeMethod('SLGetWindowsInformation', 'slc.dll', 22, 1, [Int32], @([String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  12370. $Class.DefinePInvokeMethod('SLGetWindowsInformationDWORD', 'slc.dll', 22, 1, [Int32], @([String], [UInt32].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  12371. $Class.DefinePInvokeMethod('SLIsGenuineLocal', 'slwga.dll', 22, 1, [Int32], @([Guid].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr]), 1, 3).SetImplementationFlags(128)
  12372. }
  12373. if ($NT7) {
  12374. $Class.DefinePInvokeMethod('SLIsWindowsGenuineLocal', 'slc.dll', 'Public, Static', 'Standard', [Int32], @([UInt32].MakeByRefType()), 'Winapi', 'Unicode').SetImplementationFlags('PreserveSig')
  12375. }
  12376. ​
  12377. if ($DllSubscription) {
  12378. $Class.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
  12379. $Struct = $Class.DefineNestedType('SubStatus', 'NestedPublic, SequentialLayout, Sealed, BeforeFieldInit', [ValueType], 0)
  12380. [void]$Struct.DefineField('dwEnabled', [UInt32], 'Public')
  12381. [void]$Struct.DefineField('dwSku', [UInt32], 6)
  12382. [void]$Struct.DefineField('dwState', [UInt32], 6)
  12383. $SubStatus = $Struct.CreateType()
  12384. }
  12385. ​
  12386. $Win32 = $Class.CreateType()
  12387. }
  12388. ​
  12389. function SlGetInfoIID($SkuId)
  12390. {
  12391. $bData = 0
  12392. ​
  12393. if ($Win32::SLGenerateOfflineInstallationId(
  12394. $hSLC,
  12395. [ref][Guid]$SkuId,
  12396. [ref]$bData
  12397. ))
  12398. {
  12399. return $null
  12400. }
  12401. else
  12402. {
  12403. return $Marshal::PtrToStringUni($bData)
  12404. }
  12405. }
  12406. ​
  12407. function SlReturnData($hrRet, $tData, $cData, $bData) {
  12408. if ($hrRet -NE 0 -Or $cData -EQ 0)
  12409. {
  12410. return $null
  12411. }
  12412. if ($tData -EQ 1)
  12413. {
  12414. return $Marshal::PtrToStringUni($bData)
  12415. }
  12416. elseif ($tData -EQ 4)
  12417. {
  12418. return $Marshal::ReadInt32($bData)
  12419. }
  12420. elseif ($tData -EQ 3 -And $cData -EQ 8)
  12421. {
  12422. return $Marshal::ReadInt64($bData)
  12423. }
  12424. else
  12425. {
  12426. return $null
  12427. }
  12428. }
  12429. ​
  12430. function SlGetInfoPKey($PkeyId, $Value)
  12431. {
  12432. $tData = 0
  12433. $cData = 0
  12434. $bData = 0
  12435. ​
  12436. $hrRet = $Win32::SLGetPKeyInformation(
  12437. $hSLC,
  12438. [ref][Guid]$PkeyId,
  12439. $Value,
  12440. [ref]$tData,
  12441. [ref]$cData,
  12442. [ref]$bData
  12443. )
  12444. ​
  12445. return SlReturnData $hrRet $tData $cData $bData
  12446. }
  12447. ​
  12448. function SlGetInfoSku($SkuId, $Value)
  12449. {
  12450. $tData = 0
  12451. $cData = 0
  12452. $bData = 0
  12453. ​
  12454. $hrRet = $Win32::SLGetProductSkuInformation(
  12455. $hSLC,
  12456. [ref][Guid]$SkuId,
  12457. $Value,
  12458. [ref]$tData,
  12459. [ref]$cData,
  12460. [ref]$bData
  12461. )
  12462. ​
  12463. return SlReturnData $hrRet $tData $cData $bData
  12464. }
  12465. ​
  12466. function SlGetInfoApp($AppId, $Value)
  12467. {
  12468. $tData = 0
  12469. $cData = 0
  12470. $bData = 0
  12471. ​
  12472. $hrRet = $Win32::SLGetApplicationInformation(
  12473. $hSLC,
  12474. [ref][Guid]$AppId,
  12475. $Value,
  12476. [ref]$tData,
  12477. [ref]$cData,
  12478. [ref]$bData
  12479. )
  12480. ​
  12481. return SlReturnData $hrRet $tData $cData $bData
  12482. }
  12483. ​
  12484. function SlGetInfoService($Value)
  12485. {
  12486. $tData = 0
  12487. $cData = 0
  12488. $bData = 0
  12489. ​
  12490. $hrRet = $Win32::SLGetServiceInformation(
  12491. $hSLC,
  12492. $Value,
  12493. [ref]$tData,
  12494. [ref]$cData,
  12495. [ref]$bData
  12496. )
  12497. ​
  12498. return SlReturnData $hrRet $tData $cData $bData
  12499. }
  12500. ​
  12501. function SlGetInfoSvcApp($strApp, $Value)
  12502. {
  12503. if ($SLApp)
  12504. {
  12505. return SlGetInfoApp $strApp $Value
  12506. }
  12507. else
  12508. {
  12509. return SlGetInfoService $Value
  12510. }
  12511. }
  12512. ​
  12513. function SlGetInfoLicensing($AppId, $SkuId)
  12514. {
  12515. $dwStatus = 0
  12516. $dwGrace = 0
  12517. $hrReason = 0
  12518. $qwValidity = 0
  12519. ​
  12520. $cStatus = 0
  12521. $pStatus = 0
  12522. ​
  12523. $hrRet = $Win32::SLGetLicensingStatusInformation(
  12524. $hSLC,
  12525. [ref][Guid]$AppId,
  12526. [ref][Guid]$SkuId,
  12527. 0,
  12528. [ref]$cStatus,
  12529. [ref]$pStatus
  12530. )
  12531. ​
  12532. if ($hrRet -NE 0 -Or $cStatus -EQ 0)
  12533. {
  12534. return
  12535. }
  12536. ​
  12537. [IntPtr]$ppStatus = [Int64]$pStatus + [Int64]40 * ($cStatus - 1)
  12538. $dwStatus = $Marshal::ReadInt32($ppStatus, 16)
  12539. $dwGrace = $Marshal::ReadInt32($ppStatus, 20)
  12540. $hrReason = $Marshal::ReadInt32($ppStatus, 28)
  12541. $qwValidity = $Marshal::ReadInt64($ppStatus, 32)
  12542. ​
  12543. if ($dwStatus -EQ 3)
  12544. {
  12545. $dwStatus = 5
  12546. }
  12547. if ($dwStatus -EQ 2)
  12548. {
  12549. if ($hrReason -EQ 0x4004F00D)
  12550. {
  12551. $dwStatus = 3
  12552. }
  12553. elseif ($hrReason -EQ 0x4004F065)
  12554. {
  12555. $dwStatus = 4
  12556. }
  12557. elseif ($hrReason -EQ 0x4004FC06)
  12558. {
  12559. $dwStatus = 6
  12560. }
  12561. }
  12562. ​
  12563. return
  12564. }
  12565. ​
  12566. function SlGetInfoSLID($AppId)
  12567. {
  12568. $cReturnIds = 0
  12569. $pReturnIds = 0
  12570. ​
  12571. $hrRet = $Win32::SLGetSLIDList(
  12572. $hSLC,
  12573. 0,
  12574. [ref][Guid]$AppId,
  12575. 1,
  12576. [ref]$cReturnIds,
  12577. [ref]$pReturnIds
  12578. )
  12579. ​
  12580. if ($hrRet -NE 0 -Or $cReturnIds -EQ 0)
  12581. {
  12582. return
  12583. }
  12584. ​
  12585. $a1List = @()
  12586. $a2List = @()
  12587. $a3List = @()
  12588. $a4List = @()
  12589. ​
  12590. foreach ($i in 0..($cReturnIds - 1))
  12591. {
  12592. $bytes = New-Object byte[] 16
  12593. $Marshal::Copy([Int64]$pReturnIds + [Int64]16 * $i, $bytes, 0, 16)
  12594. $actid = ([Guid]$bytes).Guid
  12595. $gPPK = SlGetInfoSku $actid "pkeyId"
  12596. $gAdd = SlGetInfoSku $actid "DependsOn"
  12597. if ($All.IsPresent) {
  12598. if ($null -EQ $gPPK -And $null -NE $gAdd) { $a1List += @{id = $actid; pk = $null; ex = $true} }
  12599. if ($null -EQ $gPPK -And $null -EQ $gAdd) { $a2List += @{id = $actid; pk = $null; ex = $false} }
  12600. }
  12601. if ($null -NE $gPPK -And $null -NE $gAdd) { $a3List += @{id = $actid; pk = $gPPK; ex = $true} }
  12602. if ($null -NE $gPPK -And $null -EQ $gAdd) { $a4List += @{id = $actid; pk = $gPPK; ex = $false} }
  12603. }
  12604. ​
  12605. return ($a1List + $a2List + $a3List + $a4List)
  12606. }
  12607. ​
  12608. function DetectSubscription {
  12609. try
  12610. {
  12611. $objSvc = New-Object PSObject
  12612. $wmiSvc = [wmisearcher]"SELECT SubscriptionType, SubscriptionStatus, SubscriptionEdition, SubscriptionExpiry FROM SoftwareLicensingService"
  12613. $wmiSvc.Options.Rewindable = $false
  12614. $wmiSvc.Get() | select -Expand Properties -EA 0 | foreach { $objSvc | Add-Member 8 $_.Name $_.Value }
  12615. $wmiSvc.Dispose()
  12616. }
  12617. catch
  12618. {
  12619. return
  12620. }
  12621. ​
  12622. if ($null -EQ $objSvc.SubscriptionType -Or $objSvc.SubscriptionType -EQ 120) {
  12623. return
  12624. }
  12625. ​
  12626. if ($objSvc.SubscriptionType -EQ 1) {
  12627. $SubMsgType = "Device based"
  12628. } else {
  12629. $SubMsgType = "User based"
  12630. }
  12631. ​
  12632. if ($objSvc.SubscriptionStatus -EQ 120) {
  12633. $SubMsgStatus = "Expired"
  12634. } elseif ($objSvc.SubscriptionStatus -EQ 100) {
  12635. $SubMsgStatus = "Disabled"
  12636. } elseif ($objSvc.SubscriptionStatus -EQ 1) {
  12637. $SubMsgStatus = "Active"
  12638. } else {
  12639. $SubMsgStatus = "Not active"
  12640. }
  12641. ​
  12642. $SubMsgExpiry = "Unknown"
  12643. if ($objSvc.SubscriptionExpiry) {
  12644. if ($objSvc.SubscriptionExpiry.Contains("unspecified") -EQ $false) {$SubMsgExpiry = $objSvc.SubscriptionExpiry}
  12645. }
  12646. ​
  12647. $SubMsgEdition = "Unknown"
  12648. if ($objSvc.SubscriptionEdition) {
  12649. if ($objSvc.SubscriptionEdition.Contains("UNKNOWN") -EQ $false) {$SubMsgEdition = $objSvc.SubscriptionEdition}
  12650. }
  12651. ​
  12652. CONOUT "`nSubscription information:"
  12653. CONOUT " Type : $SubMsgType"
  12654. CONOUT " Status : $SubMsgStatus"
  12655. CONOUT " Edition: $SubMsgEdition"
  12656. CONOUT " Expiry : $SubMsgExpiry"
  12657. }
  12658. ​
  12659. function DetectAdbaClient
  12660. {
  12661. $propADBA | foreach { set $_ (SlGetInfoSku $licID $_) }
  12662. DetectActType
  12663. CONOUT "`nAD Activation client information:"
  12664. CONOUT " Object Name: $ADActivationObjectName"
  12665. CONOUT " Domain Name: $ADActivationObjectDN"
  12666. CONOUT " CSVLK Extended PID: $ADActivationCsvlkPID"
  12667. CONOUT " CSVLK Activation ID: $ADActivationCsvlkSkuID"
  12668. }
  12669. ​
  12670. function DetectAvmClient
  12671. {
  12672. $propAVMA | foreach { set $_ (SlGetInfoSku $licID $_) }
  12673. CONOUT "`nAutomatic VM Activation client information:"
  12674. if (-Not [String]::IsNullOrEmpty($InheritedActivationId)) {
  12675. CONOUT " Guest IAID: $InheritedActivationId"
  12676. } else {
  12677. CONOUT " Guest IAID: Not Available"
  12678. }
  12679. if (-Not [String]::IsNullOrEmpty($InheritedActivationHostMachineName)) {
  12680. CONOUT " Host machine name: $InheritedActivationHostMachineName"
  12681. } else {
  12682. CONOUT " Host machine name: Not Available"
  12683. }
  12684. if (-Not [String]::IsNullOrEmpty($InheritedActivationHostDigitalPid2)) {
  12685. CONOUT " Host Digital PID2: $InheritedActivationHostDigitalPid2"
  12686. } else {
  12687. CONOUT " Host Digital PID2: Not Available"
  12688. }
  12689. if ($InheritedActivationActivationTime) {
  12690. $IAAT = [DateTime]::FromFileTime($InheritedActivationActivationTime).ToString('yyyy-MM-dd hh:mm:ss tt')
  12691. CONOUT " Activation time: $IAAT"
  12692. } else {
  12693. CONOUT " Activation time: Not Available"
  12694. }
  12695. }
  12696. ​
  12697. function DetectKmsHost
  12698. {
  12699. $IsKeyManagementService = SlGetInfoSvcApp $strApp 'IsKeyManagementService'
  12700. if (-Not $IsKeyManagementService) {
  12701. return
  12702. }
  12703. ​
  12704. if ($Vista -Or $NT5) {
  12705. $regk = $SLKeyPath
  12706. } elseif ($strSLP -EQ $oslp) {
  12707. $regk = $OPKeyPath
  12708. } else {
  12709. $regk = $SPKeyPath
  12710. }
  12711. $KMSListening = strGetRegistry $regk "KeyManagementServiceListeningPort"
  12712. $KMSPublishing = strGetRegistry $regk "DisableDnsPublishing"
  12713. $KMSPriority = strGetRegistry $regk "EnableKmsLowPriority"
  12714. ​
  12715. if (-Not $KMSListening) {$KMSListening = 1688}
  12716. if (-Not $KMSPublishing) {$KMSPublishing = "TRUE"} else {$KMSPublishing = BoolToWStr (!$KMSPublishing)}
  12717. if (-Not $KMSPriority) {$KMSPriority = "FALSE"} else {$KMSPriority = BoolToWStr $KMSPriority}
  12718. ​
  12719. if ($KMSPublishing -EQ "TRUE") {$KMSPublishing = "Enabled"} else {$KMSPublishing = "Disabled"}
  12720. if ($KMSPriority -EQ "TRUE") {$KMSPriority = "Low"} else {$KMSPriority = "Normal"}
  12721. ​
  12722. if ($SLApp)
  12723. {
  12724. $propKMSServer | foreach { set $_ (SlGetInfoApp $strApp $_) }
  12725. }
  12726. else
  12727. {
  12728. $propKMSServer | foreach { set $_ (SlGetInfoService $_) }
  12729. }
  12730. ​
  12731. $KMSRequests = $KeyManagementServiceTotalRequests
  12732. $NoRequests = ($null -EQ $KMSRequests) -Or ($KMSRequests -EQ -1) -Or ($KMSRequests -EQ 4294967295)
  12733. ​
  12734. CONOUT "`nKey Management Service host information:"
  12735. CONOUT " Current count: $KeyManagementServiceCurrentCount"
  12736. CONOUT " Listening on Port: $KMSListening"
  12737. CONOUT " DNS publishing: $KMSPublishing"
  12738. CONOUT " KMS priority: $KMSPriority"
  12739. if ($NoRequests) {
  12740. return
  12741. }
  12742. CONOUT "`nKey Management Service cumulative requests received from clients:"
  12743. CONOUT " Total: $KeyManagementServiceTotalRequests"
  12744. CONOUT " Failed: $KeyManagementServiceFailedRequests"
  12745. CONOUT " Unlicensed: $KeyManagementServiceUnlicensedRequests"
  12746. CONOUT " Licensed: $KeyManagementServiceLicensedRequests"
  12747. CONOUT " Initial grace period: $KeyManagementServiceOOBGraceRequests"
  12748. CONOUT " Expired or Hardware out of tolerance: $KeyManagementServiceOOTGraceRequests"
  12749. CONOUT " Non-genuine grace period: $KeyManagementServiceNonGenuineGraceRequests"
  12750. if ($null -NE $KeyManagementServiceNotificationRequests) {CONOUT " Notification: $KeyManagementServiceNotificationRequests"}
  12751. }
  12752. ​
  12753. function DetectActType
  12754. {
  12755. $VLType = strGetRegistry ($SPKeyPath + '\' + $strApp + '\' + $licID) "VLActivationType"
  12756. if ($null -EQ $VLType) {$VLType = strGetRegistry ($SPKeyPath + '\' + $strApp) "VLActivationType"}
  12757. if ($null -EQ $VLType) {$VLType = strGetRegistry ($SPKeyPath) "VLActivationType"}
  12758. if ($null -EQ $VLType -Or $VLType -GT 3) {$VLType = 0}
  12759. if ($null -NE $VLType) {CONOUT "Configured Activation Type: $($VLActTypes[$VLType])"}
  12760. }
  12761. ​
  12762. function DetectKmsClient
  12763. {
  12764. if ($win8) {DetectActType}
  12765. CONOUT "`r"
  12766. if ($LicenseStatus -NE 1) {
  12767. CONOUT "Please activate the product in order to update KMS client information values."
  12768. return
  12769. }
  12770. ​
  12771. if ($NT7 -Or $strSLP -EQ $oslp) {
  12772. $propKMSClient | foreach { set $_ (SlGetInfoSku $licID $_) }
  12773. if ($strSLP -EQ $oslp) {$regk = $OPKeyPath} else {$regk = $SPKeyPath}
  12774. $KMSCaching = strGetRegistry $regk "DisableKeyManagementServiceHostCaching"
  12775. if (-Not $KMSCaching) {$KMSCaching = "TRUE"} else {$KMSCaching = BoolToWStr (!$KMSCaching)}
  12776. }
  12777. ​
  12778. "ClientMachineID" | foreach { set $_ (SlGetInfoService $_) }
  12779. ​
  12780. if ($Vista) {
  12781. $propKMSVista | foreach { set $_ (SlGetInfoService $_) }
  12782. $KeyManagementServicePort = strGetRegistry $SLKeyPath "KeyManagementServicePort"
  12783. $DiscoveredKeyManagementServiceName = strGetRegistry $NSKeyPath "DiscoveredKeyManagementServiceName"
  12784. $DiscoveredKeyManagementServicePort = strGetRegistry $NSKeyPath "DiscoveredKeyManagementServicePort"
  12785. }
  12786. ​
  12787. if ([String]::IsNullOrEmpty($KeyManagementServiceName)) {
  12788. $KmsReg = $null
  12789. } else {
  12790. if (-Not $KeyManagementServicePort) {$KeyManagementServicePort = 1688}
  12791. $KmsReg = "Registered KMS machine name: ${KeyManagementServiceName}:${KeyManagementServicePort}"
  12792. }
  12793. ​
  12794. if ([String]::IsNullOrEmpty($DiscoveredKeyManagementServiceName)) {
  12795. $KmsDns = "DNS auto-discovery: KMS name not available"
  12796. if ($Vista -And -Not $Admin) {$KmsDns = "DNS auto-discovery: Run the script as administrator to retrieve info"}
  12797. } else {
  12798. if (-Not $DiscoveredKeyManagementServicePort) {$DiscoveredKeyManagementServicePort = 1688}
  12799. $KmsDns = "KMS machine name from DNS: ${DiscoveredKeyManagementServiceName}:${DiscoveredKeyManagementServicePort}"
  12800. }
  12801. ​
  12802. if ($null -NE $KMSCaching) {
  12803. if ($KMSCaching -EQ "TRUE") {$KMSCaching = "Enabled"} else {$KMSCaching = "Disabled"}
  12804. }
  12805. ​
  12806. if ($strSLP -EQ $wslp -And $NT9) {
  12807. if ([String]::IsNullOrEmpty($DiscoveredKeyManagementServiceIpAddress)) {
  12808. $DiscoveredKeyManagementServiceIpAddress = "not available"
  12809. }
  12810. }
  12811. ​
  12812. CONOUT "Key Management Service client information:"
  12813. CONOUT " Client Machine ID (CMID): $ClientMachineID"
  12814. if ($null -EQ $KmsReg) {
  12815. CONOUT " $KmsDns"
  12816. CONOUT " Registered KMS machine name: KMS name not available"
  12817. } else {
  12818. CONOUT " $KmsReg"
  12819. }
  12820. if ($null -NE $DiscoveredKeyManagementServiceIpAddress) {CONOUT " KMS machine IP address: $DiscoveredKeyManagementServiceIpAddress"}
  12821. CONOUT " KMS machine extended PID: $CustomerPID"
  12822. CONOUT " Activation interval: $VLActivationInterval minutes"
  12823. CONOUT " Renewal interval: $VLRenewalInterval minutes"
  12824. if ($null -NE $KMSCaching) {CONOUT " KMS host caching: $KMSCaching"}
  12825. if (-Not [String]::IsNullOrEmpty($KeyManagementServiceLookupDomain)) {CONOUT " KMS SRV record lookup domain: $KeyManagementServiceLookupDomain"}
  12826. }
  12827. ​
  12828. function GetResult($strSLP, $strApp, $entry)
  12829. {
  12830. $licID = $entry.id
  12831. $propPrd | foreach { set $_ (SlGetInfoSku $licID $_) }
  12832. . SlGetInfoLicensing $strApp $licID
  12833. $LicenseStatus = $dwStatus
  12834. $LicReason = $hrReason
  12835. $EvaluationEndDate = $qwValidity
  12836. $gprMnt = $dwGrace
  12837. ​
  12838. $pkid = $entry.pk
  12839. $isPPK = $null -NE $pkid
  12840. ​
  12841. $add_on = $Name.IndexOf("add-on for", 5)
  12842. if ($add_on -NE -1) {
  12843. $Name = $Name.Substring(0, $add_on + 7)
  12844. }
  12845. ​
  12846. $licPHN = "empty"
  12847. if ($Dlv -Or $All.IsPresent) {
  12848. $licPHN = SlGetInfoSku $licID "msft:sl/EUL/PHONE/PUBLIC"
  12849. }
  12850. ​
  12851. if ($LicenseStatus -EQ 0 -And !$isPPK) {
  12852. & $isAll
  12853. CONOUT "Name: $Name"
  12854. CONOUT "Description: $Description"
  12855. CONOUT "Activation ID: $licID"
  12856. CONOUT "License Status: Unlicensed"
  12857. if ($licPHN -NE "empty") {
  12858. $gPHN = [String]::IsNullOrEmpty($licPHN) -NE $true
  12859. CONOUT "Phone activatable: $($gPHN.ToString())"
  12860. }
  12861. return
  12862. }
  12863. ​
  12864. $winID = ($strApp -EQ $winApp)
  12865. $winPR = ($winID -And -Not $entry.ex)
  12866. $Vista = ($winID -And $NT6 -And -Not $NT7)
  12867. $NT5 = ($strSLP -EQ $wslp -And $winbuild -LT 6001)
  12868. $win8 = ($strSLP -EQ $wslp -And $NT8)
  12869. $reapp = ("Windows", "App")[!$winID]
  12870. $prmnt = ("machine", "product")[!$winPR]
  12871. ​
  12872. if ($Description.Contains("VOLUME_KMSCLIENT")) {$cKmsClient = 1; $actTag = "Volume"}
  12873. if ($Description.Contains("TIMEBASED_")) {$cTblClient = 1; $actTag = "Timebased"}
  12874. if ($Description.Contains("VIRTUAL_MACHINE_ACTIVATION")) {$cAvmClient = 1; $actTag = "Automatic VM"}
  12875. if ($null -EQ $cKmsClient -And $Description.Contains("VOLUME_KMS")) {$cKmsServer = 1}
  12876. ​
  12877. $gprDay = [Math]::Round($gprMnt/1440)
  12878. $_xpr = ""
  12879. $inGrace = $false
  12880. if ($gprMnt -GT 0) {
  12881. $_xpr = [DateTime]::Now.AddMinutes($gprMnt).ToString('yyyy-MM-dd hh:mm:ss tt')
  12882. $inGrace = $true
  12883. }
  12884. ​
  12885. $LicenseMsg = "Time remaining: $gprMnt minute(s) ($gprDay day(s))"
  12886. if ($LicenseStatus -EQ 0) {
  12887. $LicenseInf = "Unlicensed"
  12888. $LicenseMsg = $null
  12889. }
  12890. if ($LicenseStatus -EQ 1) {
  12891. $LicenseInf = "Licensed"
  12892. if ($gprMnt -EQ 0) {
  12893. $LicenseMsg = $null
  12894. $ExpireMsg = "The $prmnt is permanently activated."
  12895. } else {
  12896. $LicenseMsg = "$actTag activation expiration: $gprMnt minute(s) ($gprDay day(s))"
  12897. if ($inGrace) {$ExpireMsg = "$actTag activation will expire $_xpr"}
  12898. }
  12899. }
  12900. if ($LicenseStatus -EQ 2) {
  12901. $LicenseInf = "Initial grace period"
  12902. if ($inGrace) {$ExpireMsg = "$LicenseInf ends $_xpr"}
  12903. }
  12904. if ($LicenseStatus -EQ 3) {
  12905. $LicenseInf = "Additional grace period (KMS license expired or hardware out of tolerance)"
  12906. if ($inGrace) {$ExpireMsg = "Additional grace period ends $_xpr"}
  12907. }
  12908. if ($LicenseStatus -EQ 4) {
  12909. $LicenseInf = "Non-genuine grace period"
  12910. if ($inGrace) {$ExpireMsg = "$LicenseInf ends $_xpr"}
  12911. }
  12912. if ($LicenseStatus -EQ 5 -And -Not $NT5) {
  12913. $LicenseReason = '0x{0:X}' -f $LicReason
  12914. $LicenseInf = "Notification"
  12915. $LicenseMsg = "Notification Reason: $LicenseReason"
  12916. if ($LicenseReason -EQ "0xC004F00F") {if ($null -NE $cKmsClient) {$LicenseMsg = $LicenseMsg + " (KMS license expired)."} else {$LicenseMsg = $LicenseMsg + " (hardware out of tolerance)."}}
  12917. if ($LicenseReason -EQ "0xC004F200") {$LicenseMsg = $LicenseMsg + " (non-genuine)."}
  12918. if ($LicenseReason -EQ "0xC004F009" -Or $LicenseReason -EQ "0xC004F064") {$LicenseMsg = $LicenseMsg + " (grace time expired)."}
  12919. }
  12920. if ($LicenseStatus -GT 5 -Or ($LicenseStatus -GT 4 -And $NT5)) {
  12921. $LicenseInf = "Unknown"
  12922. $LicenseMsg = $null
  12923. }
  12924. if ($LicenseStatus -EQ 6 -And -Not $Vista -And -Not $NT5) {
  12925. $LicenseInf = "Extended grace period"
  12926. if ($inGrace) {$ExpireMsg = "$LicenseInf ends $_xpr"}
  12927. }
  12928. ​
  12929. if ($isPPK) {
  12930. $propPkey | foreach { set $_ (SlGetInfoPKey $pkid $_) }
  12931. }
  12932. ​
  12933. if ($winPR -And $isPPK -And -Not $NT8) {
  12934. $uxd = SlGetInfoSku $licID 'UXDifferentiator'
  12935. $script:primary += @{
  12936. aid = $licID;
  12937. ppk = $PartialProductKey;
  12938. chn = $Channel;
  12939. lst = $LicenseStatus;
  12940. lcr = $LicReason;
  12941. ged = $gprMnt;
  12942. evl = $EvaluationEndDate;
  12943. dff = $uxd
  12944. }
  12945. }
  12946. ​
  12947. if ($IID -And $isPPK) {
  12948. $OfflineInstallationId = SlGetInfoIID $licID
  12949. }
  12950. ​
  12951. if ($Dlv) {
  12952. if ($win8)
  12953. {
  12954. $RemainingSkuReArmCount = SlGetInfoSku $licID 'RemainingRearmCount'
  12955. $RemainingAppReArmCount = SlGetInfoApp $strApp 'RemainingRearmCount'
  12956. }
  12957. else
  12958. {
  12959. if (($winID -And $NT7) -Or $strSLP -EQ $oslp)
  12960. {
  12961. $RemainingSLReArmCount = SlGetInfoApp $strApp 'RemainingRearmCount'
  12962. }
  12963. else
  12964. {
  12965. $RemainingSLReArmCount = SlGetInfoService 'RearmCount'
  12966. }
  12967. }
  12968. if ($null -EQ $TrustedTime)
  12969. {
  12970. $TrustedTime = SlGetInfoSvcApp $strApp 'TrustedTime'
  12971. }
  12972. }
  12973. ​
  12974. & $isAll
  12975. CONOUT "Name: $Name"
  12976. CONOUT "Description: $Description"
  12977. CONOUT "Activation ID: $licID"
  12978. if ($null -NE $DigitalPID) {CONOUT "Extended PID: $DigitalPID"}
  12979. if ($null -NE $DigitalPID2 -And $Dlv) {CONOUT "Product ID: $DigitalPID2"}
  12980. if ($null -NE $OfflineInstallationId -And $IID) {CONOUT "Installation ID: $OfflineInstallationId"}
  12981. if ($null -NE $Channel) {CONOUT "Product Key Channel: $Channel"}
  12982. if ($null -NE $PartialProductKey) {CONOUT "Partial Product Key: $PartialProductKey"}
  12983. CONOUT "License Status: $LicenseInf"
  12984. if ($null -NE $LicenseMsg) {CONOUT "$LicenseMsg"}
  12985. if ($LicenseStatus -NE 0 -And $EvaluationEndDate) {
  12986. $EED = [DateTime]::FromFileTimeUtc($EvaluationEndDate).ToString('yyyy-MM-dd hh:mm:ss tt')
  12987. CONOUT "Evaluation End Date: $EED UTC"
  12988. }
  12989. if ($LicenseStatus -NE 1 -And $licPHN -NE "empty") {
  12990. $gPHN = [String]::IsNullOrEmpty($licPHN) -NE $true
  12991. CONOUT "Phone activatable: $($gPHN.ToString())"
  12992. }
  12993. if ($Dlv) {
  12994. if ($null -NE $RemainingSLReArmCount) {
  12995. CONOUT "Remaining $reapp rearm count: $RemainingSLReArmCount"
  12996. }
  12997. if ($null -NE $RemainingSkuReArmCount) {
  12998. CONOUT "Remaining $reapp rearm count: $RemainingAppReArmCount"
  12999. CONOUT "Remaining SKU rearm count: $RemainingSkuReArmCount"
  13000. }
  13001. if ($LicenseStatus -NE 0 -And $TrustedTime) {
  13002. $TTD = [DateTime]::FromFileTime($TrustedTime).ToString('yyyy-MM-dd hh:mm:ss tt')
  13003. CONOUT "Trusted time: $TTD"
  13004. }
  13005. }
  13006. if (!$isPPK) {
  13007. return
  13008. }
  13009. ​
  13010. if ($win8 -And $VLActivationType -EQ 1) {
  13011. DetectAdbaClient
  13012. $cKmsClient = $null
  13013. }
  13014. ​
  13015. if ($winID -And $null -NE $cAvmClient) {
  13016. DetectAvmClient
  13017. }
  13018. ​
  13019. $chkSub = ($winPR -And $isSub)
  13020. ​
  13021. $chkSLS = ($null -NE $cKmsClient -Or $null -NE $cKmsServer -Or $chkSub)
  13022. ​
  13023. if (!$chkSLS) {
  13024. if ($null -NE $ExpireMsg) {CONOUT "`n $ExpireMsg"}
  13025. return
  13026. }
  13027. ​
  13028. if ($null -NE $cKmsClient) {
  13029. DetectKmsClient
  13030. }
  13031. ​
  13032. if ($null -NE $cKmsServer) {
  13033. if ($null -NE $ExpireMsg) {CONOUT "`n $ExpireMsg"}
  13034. DetectKmsHost
  13035. } else {
  13036. if ($null -NE $ExpireMsg) {CONOUT "`n $ExpireMsg"}
  13037. }
  13038. ​
  13039. if ($chkSub) {
  13040. DetectSubscription
  13041. }
  13042. ​
  13043. }
  13044. ​
  13045. function ParseList($strSLP, $strApp, $arrList)
  13046. {
  13047. foreach ($entry in $arrList)
  13048. {
  13049. GetResult $strSLP $strApp $entry
  13050. CONOUT "$line3"
  13051. & $noAll
  13052. }
  13053. }
  13054. #endregion
  13055. ​
  13056. #region vNextDiag
  13057. if ($PSVersionTable.PSVersion.Major -Lt 3)
  13058. {
  13059. function ConvertFrom-Json
  13060. {
  13061. [CmdletBinding()]
  13062. Param(
  13063. [Parameter(ValueFromPipeline=$true)][Object]$item
  13064. )
  13065. [void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
  13066. $psjs = New-Object System.Web.Script.Serialization.JavaScriptSerializer
  13067. Return ,$psjs.DeserializeObject($item)
  13068. }
  13069. function ConvertTo-Json
  13070. {
  13071. [CmdletBinding()]
  13072. Param(
  13073. [Parameter(ValueFromPipeline=$true)][Object]$item
  13074. )
  13075. [void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
  13076. $psjs = New-Object System.Web.Script.Serialization.JavaScriptSerializer
  13077. Return $psjs.Serialize($item)
  13078. }
  13079. }
  13080. ​
  13081. function PrintModePerPridFromRegistry
  13082. {
  13083. $vNextRegkey = "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Licensing\LicensingNext"
  13084. $vNextPrids = Get-Item -Path $vNextRegkey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty 'property' -ErrorAction SilentlyContinue | Where-Object -FilterScript {$_.ToLower() -like "*retail" -or $_.ToLower() -like "*volume"}
  13085. If ($null -Eq $vNextPrids)
  13086. {
  13087. CONOUT "`nNo registry keys found."
  13088. Return
  13089. }
  13090. CONOUT "`r"
  13091. $vNextPrids | ForEach `
  13092. {
  13093. $mode = (Get-ItemProperty -Path $vNextRegkey -Name $_).$_
  13094. Switch ($mode)
  13095. {
  13096. 2 { $mode = "vNext"; Break }
  13097. 3 { $mode = "Device"; Break }
  13098. Default { $mode = "Legacy"; Break }
  13099. }
  13100. CONOUT "$_ = $mode"
  13101. }
  13102. }
  13103. ​
  13104. function PrintSharedComputerLicensing
  13105. {
  13106. $scaRegKey = "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration"
  13107. $scaValue = Get-ItemProperty -Path $scaRegKey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty "SharedComputerLicensing" -ErrorAction SilentlyContinue
  13108. $scaRegKey2 = "HKLM:\SOFTWARE\Microsoft\Office\16.0\Common\Licensing"
  13109. $scaValue2 = Get-ItemProperty -Path $scaRegKey2 -ErrorAction SilentlyContinue | Select-Object -ExpandProperty "SharedComputerLicensing" -ErrorAction SilentlyContinue
  13110. $scaPolicyKey = "HKLM:\SOFTWARE\Policies\Microsoft\Office\16.0\Common\Licensing"
  13111. $scaPolicyValue = Get-ItemProperty -Path $scaPolicyKey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty "SharedComputerLicensing" -ErrorAction SilentlyContinue
  13112. If ($null -Eq $scaValue -And $null -Eq $scaValue2 -And $null -Eq $scaPolicyValue)
  13113. {
  13114. CONOUT "`nNo registry keys found."
  13115. Return
  13116. }
  13117. $scaModeValue = $scaValue -Or $scaValue2 -Or $scaPolicyValue
  13118. If ($scaModeValue -Eq 0)
  13119. {
  13120. $scaMode = "Disabled"
  13121. }
  13122. If ($scaModeValue -Eq 1)
  13123. {
  13124. $scaMode = "Enabled"
  13125. }
  13126. CONOUT "`nStatus: $scaMode"
  13127. CONOUT "`r"
  13128. $tokenFiles = $null
  13129. $tokenPath = "${env:LOCALAPPDATA}\Microsoft\Office\16.0\Licensing"
  13130. If (Test-Path $tokenPath)
  13131. {
  13132. $tokenFiles = Get-ChildItem -Path $tokenPath -Filter "*authString*" -Recurse | Where-Object { !$_.PSIsContainer }
  13133. }
  13134. If ($null -Eq $tokenFiles -Or $tokenFiles.Length -Eq 0)
  13135. {
  13136. CONOUT "No tokens found."
  13137. Return
  13138. }
  13139. $tokenFiles | ForEach `
  13140. {
  13141. $tokenParts = (Get-Content -Encoding Unicode -Path $_.FullName).Split('_')
  13142. $output = New-Object PSObject
  13143. $output | Add-Member 8 'ACID' $tokenParts[0];
  13144. $output | Add-Member 8 'User' $tokenParts[3];
  13145. $output | Add-Member 8 'NotBefore' $tokenParts[4];
  13146. $output | Add-Member 8 'NotAfter' $tokenParts[5];
  13147. Write-Output $output
  13148. }
  13149. }
  13150. ​
  13151. function PrintLicensesInformation
  13152. {
  13153. Param(
  13154. [ValidateSet("NUL", "Device")]
  13155. [String]$mode
  13156. )
  13157. If ($mode -Eq "NUL")
  13158. {
  13159. $licensePath = "${env:LOCALAPPDATA}\Microsoft\Office\Licenses"
  13160. }
  13161. ElseIf ($mode -Eq "Device")
  13162. {
  13163. $licensePath = "${env:PROGRAMDATA}\Microsoft\Office\Licenses"
  13164. }
  13165. $licenseFiles = $null
  13166. If (Test-Path $licensePath)
  13167. {
  13168. $licenseFiles = Get-ChildItem -Path $licensePath -Recurse | Where-Object { !$_.PSIsContainer }
  13169. }
  13170. If ($null -Eq $licenseFiles -Or $licenseFiles.Length -Eq 0)
  13171. {
  13172. CONOUT "`nNo licenses found."
  13173. Return
  13174. }
  13175. $licenseFiles | ForEach `
  13176. {
  13177. $license = (Get-Content -Encoding Unicode $_.FullName | ConvertFrom-Json).License
  13178. $decodedLicense = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($license)) | ConvertFrom-Json
  13179. $licenseType = $decodedLicense.LicenseType
  13180. If ($null -Ne $decodedLicense.ExpiresOn)
  13181. {
  13182. $expiry = [System.DateTime]::Parse($decodedLicense.ExpiresOn, $null, 'AdjustToUniversal')
  13183. }
  13184. Else
  13185. {
  13186. $expiry = New-Object System.DateTime
  13187. }
  13188. $licenseState = "Grace"
  13189. If ((Get-Date) -Gt (Get-Date $decodedLicense.Metadata.NotAfter))
  13190. {
  13191. $licenseState = "RFM"
  13192. }
  13193. ElseIf ((Get-Date) -Lt (Get-Date $expiry))
  13194. {
  13195. $licenseState = "Licensed"
  13196. }
  13197. $output = New-Object PSObject
  13198. $output | Add-Member 8 'File' $_.PSChildName;
  13199. $output | Add-Member 8 'Version' $_.Directory.Name;
  13200. $output | Add-Member 8 'Type' "User|${licenseType}";
  13201. $output | Add-Member 8 'Product' $decodedLicense.ProductReleaseId;
  13202. $output | Add-Member 8 'Acid' $decodedLicense.Acid;
  13203. If ($mode -Eq "Device") { $output | Add-Member 8 'DeviceId' $decodedLicense.Metadata.DeviceId; }
  13204. $output | Add-Member 8 'LicenseState' $licenseState;
  13205. $output | Add-Member 8 'EntitlementStatus' $decodedLicense.Status;
  13206. $output | Add-Member 8 'EntitlementExpiration' ("N/A", $decodedLicense.ExpiresOn)[!($null -eq $decodedLicense.ExpiresOn)];
  13207. $output | Add-Member 8 'ReasonCode' ("N/A", $decodedLicense.ReasonCode)[!($null -eq $decodedLicense.ReasonCode)];
  13208. $output | Add-Member 8 'NotBefore' $decodedLicense.Metadata.NotBefore;
  13209. $output | Add-Member 8 'NotAfter' $decodedLicense.Metadata.NotAfter;
  13210. $output | Add-Member 8 'NextRenewal' $decodedLicense.Metadata.RenewAfter;
  13211. $output | Add-Member 8 'TenantId' ("N/A", $decodedLicense.Metadata.TenantId)[!($null -eq $decodedLicense.Metadata.TenantId)];
  13212. #$output.PSObject.Properties | foreach { $ht = @{} } { $ht[$_.Name] = $_.Value } { $output = $ht | ConvertTo-Json }
  13213. Write-Output $output
  13214. }
  13215. }
  13216. ​
  13217. function vNextDiagRun
  13218. {
  13219. $fNUL = ([IO.Directory]::Exists("${env:LOCALAPPDATA}\Microsoft\Office\Licenses")) -and ([IO.Directory]::GetFiles("${env:LOCALAPPDATA}\Microsoft\Office\Licenses", "*", 1).Length -GT 0)
  13220. $fDev = ([IO.Directory]::Exists("${env:PROGRAMDATA}\Microsoft\Office\Licenses")) -and ([IO.Directory]::GetFiles("${env:PROGRAMDATA}\Microsoft\Office\Licenses", "*", 1).Length -GT 0)
  13221. $rPID = $null -NE (GP "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Licensing\LicensingNext" -EA 0 | select -Expand 'property' -EA 0 | where -Filter {$_.ToLower() -like "*retail" -or $_.ToLower() -like "*volume"})
  13222. $rSCA = $null -NE (GP "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration" -EA 0 | select -Expand "SharedComputerLicensing" -EA 0)
  13223. $rSCL = $null -NE (GP "HKLM:\SOFTWARE\Microsoft\Office\16.0\Common\Licensing" -EA 0 | select -Expand "SharedComputerLicensing" -EA 0)
  13224. ​
  13225. if (($fNUL -Or $fDev -Or $rPID -Or $rSCA -Or $rSCL) -EQ $false) {
  13226. Return
  13227. }
  13228. ​
  13229. & $isAll
  13230. CONOUT "$line2"
  13231. CONOUT "=== Office vNext Status ==="
  13232. CONOUT "$line2"
  13233. CONOUT "`n========== Mode per ProductReleaseId =========="
  13234. PrintModePerPridFromRegistry
  13235. CONOUT "`n========== Shared Computer Licensing =========="
  13236. PrintSharedComputerLicensing
  13237. CONOUT "`n========== vNext licenses ==========="
  13238. PrintLicensesInformation -Mode "NUL"
  13239. CONOUT "`n========== Device licenses =========="
  13240. PrintLicensesInformation -Mode "Device"
  13241. CONOUT "$line3"
  13242. CONOUT "`r"
  13243. }
  13244. #endregion
  13245. ​
  13246. #region clic
  13247. ​
  13248. <#
  13249. ;;; Source: https://github.com/asdcorp/clic
  13250. ;;; Powershell port: abbodi1406
  13251. ​
  13252. Copyright 2023 asdcorp
  13253. ​
  13254. Permission is hereby granted, free of charge, to any person obtaining a copy of
  13255. this software and associated documentation files (the "Software"), to deal in
  13256. the Software without restriction, including without limitation the rights to
  13257. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  13258. the Software, and to permit persons to whom the Software is furnished to do so,
  13259. subject to the following conditions:
  13260. ​
  13261. The above copyright notice and this permission notice shall be included in all
  13262. copies or substantial portions of the Software.
  13263. ​
  13264. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13265. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  13266. FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  13267. COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  13268. IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  13269. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  13270. #>
  13271. ​
  13272. function InitializeDigitalLicenseCheck {
  13273. $CAB = [System.Reflection.Emit.CustomAttributeBuilder]
  13274. ​
  13275. $ICom = $Module.DefineType('EUM.IEUM', 'Public, Interface, Abstract, Import')
  13276. $ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.ComImportAttribute].GetConstructor(@()), @()))
  13277. $ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.GuidAttribute].GetConstructor(@([String])), @('F2DCB80D-0670-44BC-9002-CD18688730AF')))
  13278. $ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.InterfaceTypeAttribute].GetConstructor(@([Int16])), @([Int16]1)))
  13279. ​
  13280. 1..4 | % { [void]$ICom.DefineMethod('VF'+$_, 'Public, Virtual, HideBySig, NewSlot, Abstract', 'Standard, HasThis', [Void], @()) }
  13281. [void]$ICom.DefineMethod('AcquireModernLicenseForWindows', 1478, 33, [Int32], @([Int32], [Int32].MakeByRefType()))
  13282. ​
  13283. $IEUM = $ICom.CreateType()
  13284. }
  13285. ​
  13286. function PrintStateData {
  13287. $pwszStateData = 0
  13288. $cbSize = 0
  13289. ​
  13290. if ($Win32::SLGetWindowsInformation(
  13291. "Security-SPP-Action-StateData",
  13292. [ref]$null,
  13293. [ref]$cbSize,
  13294. [ref]$pwszStateData
  13295. )) {
  13296. return $FALSE
  13297. }
  13298. ​
  13299. [string[]]$pwszStateString = $Marshal::PtrToStringUni($pwszStateData) -replace ";", "`n "
  13300. CONOUT (" $pwszStateString")
  13301. ​
  13302. $Marshal::FreeHGlobal($pwszStateData)
  13303. return $TRUE
  13304. }
  13305. ​
  13306. function PrintLastActivationHResult {
  13307. $pdwLastHResult = 0
  13308. $cbSize = 0
  13309. ​
  13310. if ($Win32::SLGetWindowsInformation(
  13311. "Security-SPP-LastWindowsActivationHResult",
  13312. [ref]$null,
  13313. [ref]$cbSize,
  13314. [ref]$pdwLastHResult
  13315. )) {
  13316. return $FALSE
  13317. }
  13318. ​
  13319. CONOUT (" LastActivationHResult=0x{0:x8}" -f $Marshal::ReadInt32($pdwLastHResult))
  13320. ​
  13321. $Marshal::FreeHGlobal($pdwLastHResult)
  13322. return $TRUE
  13323. }
  13324. ​
  13325. function PrintLastActivationTime {
  13326. $pqwLastTime = 0
  13327. $cbSize = 0
  13328. ​
  13329. if ($Win32::SLGetWindowsInformation(
  13330. "Security-SPP-LastWindowsActivationTime",
  13331. [ref]$null,
  13332. [ref]$cbSize,
  13333. [ref]$pqwLastTime
  13334. )) {
  13335. return $FALSE
  13336. }
  13337. ​
  13338. $actTime = $Marshal::ReadInt64($pqwLastTime)
  13339. if ($actTime -ne 0) {
  13340. CONOUT (" LastActivationTime={0}" -f [DateTime]::FromFileTimeUtc($actTime).ToString("yyyy/MM/dd:HH:mm:ss"))
  13341. }
  13342. ​
  13343. $Marshal::FreeHGlobal($pqwLastTime)
  13344. return $TRUE
  13345. }
  13346. ​
  13347. function PrintIsWindowsGenuine {
  13348. $dwGenuine = 0
  13349. ​
  13350. if ($Win32::SLIsWindowsGenuineLocal([ref]$dwGenuine)) {
  13351. return $FALSE
  13352. }
  13353. ​
  13354. if ($dwGenuine -lt 5) {
  13355. CONOUT (" IsWindowsGenuine={0}" -f $ppwszGenuineStates[$dwGenuine])
  13356. } else {
  13357. CONOUT (" IsWindowsGenuine={0}" -f $dwGenuine)
  13358. }
  13359. ​
  13360. return $TRUE
  13361. }
  13362. ​
  13363. function PrintDigitalLicenseStatus {
  13364. try {
  13365. . InitializeDigitalLicenseCheck
  13366. $ComObj = New-Object -Com EditionUpgradeManagerObj.EditionUpgradeManager
  13367. } catch {
  13368. return $FALSE
  13369. }
  13370. ​
  13371. $parameters = 1, $null
  13372. ​
  13373. if ([EUM.IEUM].GetMethod("AcquireModernLicenseForWindows").Invoke($ComObj, $parameters)) {
  13374. return $FALSE
  13375. }
  13376. ​
  13377. $dwReturnCode = $parameters[1]
  13378. [bool]$bDigitalLicense = $FALSE
  13379. ​
  13380. $bDigitalLicense = (($dwReturnCode -ge 0) -and ($dwReturnCode -ne 1))
  13381. CONOUT (" IsDigitalLicense={0}" -f (BoolToWStr $bDigitalLicense))
  13382. ​
  13383. return $TRUE
  13384. }
  13385. ​
  13386. function PrintSubscriptionStatus {
  13387. $dwSupported = 0
  13388. ​
  13389. if ($winbuild -ge 15063) {
  13390. $pwszPolicy = "ConsumeAddonPolicySet"
  13391. } else {
  13392. $pwszPolicy = "Allow-WindowsSubscription"
  13393. }
  13394. ​
  13395. if ($Win32::SLGetWindowsInformationDWORD($pwszPolicy, [ref]$dwSupported)) {
  13396. return $FALSE
  13397. }
  13398. ​
  13399. CONOUT (" SubscriptionSupportedEdition={0}" -f (BoolToWStr $dwSupported))
  13400. ​
  13401. $pStatus = $Marshal::AllocHGlobal($Marshal::SizeOf([Type]$SubStatus))
  13402. if ($Win32::ClipGetSubscriptionStatus([ref]$pStatus)) {
  13403. return $FALSE
  13404. }
  13405. ​
  13406. $sStatus = [Activator]::CreateInstance($SubStatus)
  13407. $sStatus = $Marshal::PtrToStructure($pStatus, [Type]$SubStatus)
  13408. $Marshal::FreeHGlobal($pStatus)
  13409. ​
  13410. CONOUT (" SubscriptionEnabled={0}" -f (BoolToWStr $sStatus.dwEnabled))
  13411. ​
  13412. if ($sStatus.dwEnabled -eq 0) {
  13413. return $TRUE
  13414. }
  13415. ​
  13416. CONOUT (" SubscriptionSku={0}" -f $sStatus.dwSku)
  13417. CONOUT (" SubscriptionState={0}" -f $sStatus.dwState)
  13418. ​
  13419. return $TRUE
  13420. }
  13421. ​
  13422. function ClicRun
  13423. {
  13424. & $isAll
  13425. CONOUT "Client Licensing Check information:"
  13426. ​
  13427. $null = PrintStateData
  13428. $null = PrintLastActivationHResult
  13429. $null = PrintLastActivationTime
  13430. $null = PrintIsWindowsGenuine
  13431. ​
  13432. if ($DllDigital) {
  13433. $null = PrintDigitalLicenseStatus
  13434. }
  13435. ​
  13436. if ($DllSubscription) {
  13437. $null = PrintSubscriptionStatus
  13438. }
  13439. ​
  13440. CONOUT "$line3"
  13441. & $noAll
  13442. }
  13443. #endregion
  13444. ​
  13445. #region clc
  13446. function clcGetExpireKrn
  13447. {
  13448. $tData = 0
  13449. $cData = 0
  13450. $bData = 0
  13451. ​
  13452. $hrRet = $Win32::SLGetWindowsInformation(
  13453. "Kernel-ExpirationDate",
  13454. [ref]$tData,
  13455. [ref]$cData,
  13456. [ref]$bData
  13457. )
  13458. ​
  13459. if ($hrRet -Or !$cData -Or $tData -NE 3)
  13460. {
  13461. return $null
  13462. }
  13463. ​
  13464. $year = $Marshal::ReadInt16($bData, 0)
  13465. if ($year -EQ 0 -Or $year -EQ 1601)
  13466. {
  13467. $rData = $null
  13468. }
  13469. else
  13470. {
  13471. $rData = '{0}/{1}/{2}:{3}:{4}:{5}' -f $year, $Marshal::ReadInt16($bData, 2), $Marshal::ReadInt16($bData, 4), $Marshal::ReadInt16($bData, 6), $Marshal::ReadInt16($bData, 8), $Marshal::ReadInt16($bData, 10)
  13472. }
  13473. ​
  13474. #$Marshal::FreeHGlobal($bData)
  13475. return $rData
  13476. }
  13477. ​
  13478. function clcGetExpireSys
  13479. {
  13480. $kuser = $Marshal::ReadInt64((New-Object IntPtr(0x7FFE02C8)))
  13481. ​
  13482. if ($kuser -EQ 0)
  13483. {
  13484. return $null
  13485. }
  13486. ​
  13487. $rData = [DateTime]::FromFileTimeUtc($kuser).ToString('yyyy/MM/dd:HH:mm:ss')
  13488. return $rData
  13489. }
  13490. ​
  13491. function clcGetLicensingState($dwState)
  13492. {
  13493. if ($dwState -EQ 5) {
  13494. $dwState = 3
  13495. } elseif ($dwState -EQ 3 -Or $dwState -EQ 4 -Or $dwState -EQ 6) {
  13496. $dwState = 2
  13497. } elseif ($dwState -GT 6) {
  13498. $dwState = 4
  13499. }
  13500. ​
  13501. $rData = '{0}' -f $ppwszLicensingStates[$dwState]
  13502. return $rData
  13503. }
  13504. ​
  13505. function clcGetGenuineState($AppId)
  13506. {
  13507. $dwGenuine = 0
  13508. ​
  13509. if ($NT7) {
  13510. $hrRet = $Win32::SLIsWindowsGenuineLocal([ref]$dwGenuine)
  13511. } else {
  13512. $hrRet = $Win32::SLIsGenuineLocal([ref][Guid]$AppId, [ref]$dwGenuine, 0)
  13513. }
  13514. ​
  13515. if ($hrRet)
  13516. {
  13517. $dwGenuine = 4
  13518. }
  13519. ​
  13520. if ($dwGenuine -LT 5) {
  13521. $rData = '{0}' -f $ppwszGenuineStates[$dwGenuine]
  13522. } else {
  13523. $rData = $dwGenuine
  13524. }
  13525. return $rData
  13526. }
  13527. ​
  13528. function ClcRun
  13529. {
  13530. $prs = $script:primary[0]
  13531. if ($null -EQ $prs) {
  13532. return
  13533. }
  13534. ​
  13535. $lState = clcGetLicensingState $prs.lst
  13536. $uState = clcGetGenuineState $winApp
  13537. $TbbKrn = clcGetExpireKrn
  13538. $TbbSys = clcGetExpireSys
  13539. if ($null -NE $TbbKrn) {
  13540. $ked = $TbbKrn
  13541. } elseif ($null -NE $TbbSys) {
  13542. $ked = $TbbSys
  13543. }
  13544. ​
  13545. & $isAll
  13546. CONOUT "Client Licensing Check information:"
  13547. ​
  13548. CONOUT (" AppId={0}" -f $winApp)
  13549. if ($prs.ged) { CONOUT (" GraceEndDate={0}" -f ([DateTime]::UtcNow.AddMinutes($prs.ged).ToString('yyyy/MM/dd:HH:mm:ss'))) }
  13550. if ($null -NE $ked) { CONOUT (" KernelTimebombDate={0}" -f $ked) }
  13551. CONOUT (" LastConsumptionReason=0x{0:x8}" -f $prs.lcr)
  13552. if ($prs.evl) { CONOUT (" LicenseExpirationDate={0}" -f ([DateTime]::FromFileTimeUtc($prs.evl).ToString('yyyy/MM/dd:HH:mm:ss'))) }
  13553. CONOUT (" LicenseState={0}" -f $lState)
  13554. CONOUT (" PartialProductKey={0}" -f $prs.ppk)
  13555. CONOUT (" ProductKeyType={0}" -f $prs.chn)
  13556. CONOUT (" SkuId={0}" -f $prs.aid)
  13557. CONOUT (" uxDifferentiator={0}" -f $prs.dff)
  13558. CONOUT (" IsWindowsGenuine={0}" -f $uState)
  13559. ​
  13560. CONOUT "$line3"
  13561. & $noAll
  13562. }
  13563. #endregion
  13564. ​
  13565. $Host.UI.RawUI.WindowTitle = "Check Activation Status"
  13566. if ($All.IsPresent) {
  13567. $B=$Host.UI.RawUI.BufferSize;$B.Height=3000;$Host.UI.RawUI.BufferSize=$B;
  13568. if (!$Pass.IsPresent) {clear;}
  13569. }
  13570. ​
  13571. $SysPath = "$env:SystemRoot\System32"
  13572. if (Test-Path "$env:SystemRoot\Sysnative\reg.exe") {
  13573. $SysPath = "$env:SystemRoot\Sysnative"
  13574. }
  13575. ​
  13576. $wslp = "SoftwareLicensingProduct"
  13577. $wsls = "SoftwareLicensingService"
  13578. $oslp = "OfficeSoftwareProtectionProduct"
  13579. $osls = "OfficeSoftwareProtectionService"
  13580. $winApp = "55c92734-d682-4d71-983e-d6ec3f16059f"
  13581. $o14App = "59a52881-a989-479d-af46-f275c6370663"
  13582. $o15App = "0ff1ce15-a989-479d-af46-f275c6370663"
  13583. $isSub = ($winbuild -GE 26000) -And (Select-String -Path "$SysPath\wbem\sppwmi.mof" -Encoding unicode -Pattern "SubscriptionType")
  13584. $DllDigital = ($winbuild -GE 14393) -And (Test-Path "$SysPath\EditionUpgradeManagerObj.dll")
  13585. $DllSubscription = ($winbuild -GE 14393) -And (Test-Path "$SysPath\Clipc.dll")
  13586. $VLActTypes = @("All", "AD", "KMS", "Token")
  13587. $OPKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform"
  13588. $SPKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform"
  13589. $SLKeyPath = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SL"
  13590. $NSKeyPath = "HKEY_USERS\S-1-5-20\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SL"
  13591. $propPrd = 'Name', 'Description', 'TrustedTime', 'VLActivationType'
  13592. $propPkey = 'PartialProductKey', 'Channel', 'DigitalPID', 'DigitalPID2'
  13593. $propKMSServer = 'KeyManagementServiceCurrentCount', 'KeyManagementServiceTotalRequests', 'KeyManagementServiceFailedRequests', 'KeyManagementServiceUnlicensedRequests', 'KeyManagementServiceLicensedRequests', 'KeyManagementServiceOOBGraceRequests', 'KeyManagementServiceOOTGraceRequests', 'KeyManagementServiceNonGenuineGraceRequests', 'KeyManagementServiceNotificationRequests'
  13594. $propKMSClient = 'CustomerPID', 'KeyManagementServiceName', 'KeyManagementServicePort', 'DiscoveredKeyManagementServiceName', 'DiscoveredKeyManagementServicePort', 'DiscoveredKeyManagementServiceIpAddress', 'VLActivationInterval', 'VLRenewalInterval', 'KeyManagementServiceLookupDomain'
  13595. $propKMSVista = 'CustomerPID', 'KeyManagementServiceName', 'VLActivationInterval', 'VLRenewalInterval'
  13596. $propADBA = 'ADActivationObjectName', 'ADActivationObjectDN', 'ADActivationCsvlkPID', 'ADActivationCsvlkSkuID'
  13597. $propAVMA = 'InheritedActivationId', 'InheritedActivationHostMachineName', 'InheritedActivationHostDigitalPid2', 'InheritedActivationActivationTime'
  13598. $primary = @()
  13599. $ppwszGenuineStates = @(
  13600. "SL_GEN_STATE_IS_GENUINE",
  13601. "SL_GEN_STATE_INVALID_LICENSE",
  13602. "SL_GEN_STATE_TAMPERED",
  13603. "SL_GEN_STATE_OFFLINE",
  13604. "SL_GEN_STATE_LAST"
  13605. )
  13606. $ppwszLicensingStates = @(
  13607. "SL_LICENSING_STATUS_UNLICENSED",
  13608. "SL_LICENSING_STATUS_LICENSED",
  13609. "SL_LICENSING_STATUS_IN_GRACE_PERIOD",
  13610. "SL_LICENSING_STATUS_NOTIFICATION",
  13611. "SL_LICENSING_STATUS_LAST"
  13612. )
  13613. ​
  13614. 'cW1nd0ws', 'c0ff1ce15', 'c0ff1ce14', 'ospp14', 'ospp15' | foreach {set $_ @()}
  13615. ​
  13616. $offsvc = "osppsvc"
  13617. if ($NT7 -Or -Not $NT6) {$winsvc = "sppsvc"} else {$winsvc = "slsvc"}
  13618. ​
  13619. try {gsv $winsvc -EA 1 | Out-Null; $WsppHook = 1} catch {$WsppHook = 0}
  13620. try {gsv $offsvc -EA 1 | Out-Null; $OsppHook = 1} catch {$OsppHook = 0}
  13621. ​
  13622. if (Test-Path "$SysPath\sppc.dll") {
  13623. $SLdll = 'sppc.dll'
  13624. } elseif (Test-Path "$SysPath\slc.dll") {
  13625. $SLdll = 'slc.dll'
  13626. } else {
  13627. $WsppHook = 0
  13628. }
  13629. ​
  13630. if ($OsppHook -NE 0) {
  13631. $OLdll = (strGetRegistry $OPKeyPath "Path") + 'osppc.dll'
  13632. if (!(Test-Path "$OLdll")) {$OsppHook = 0}
  13633. }
  13634. ​
  13635. if ($WsppHook -NE 0) {
  13636. if ($NT6 -And -Not $NT7 -And -Not $Admin) {
  13637. if ($null -EQ [Diagnostics.Process]::GetProcessesByName("$winsvc")[0].ProcessName) {$WsppHook = 0; CONOUT "`nError: failed to start $winsvc Service.`n"}
  13638. } else {
  13639. try {sasv $winsvc -EA 1} catch {$WsppHook = 0; CONOUT "`nError: failed to start $winsvc Service.`n"}
  13640. }
  13641. }
  13642. ​
  13643. if ($WsppHook -NE 0) {
  13644. . InitializePInvoke $SLdll $false
  13645. $hSLC = 0
  13646. [void]$Win32::SLOpen([ref]$hSLC)
  13647. ​
  13648. $cW1nd0ws = SlGetInfoSLID $winApp
  13649. $c0ff1ce15 = SlGetInfoSLID $o15App
  13650. $c0ff1ce14 = SlGetInfoSLID $o14App
  13651. }
  13652. ​
  13653. if ($cW1nd0ws.Count -GT 0)
  13654. {
  13655. echoWindows
  13656. ParseList $wslp $winApp $cW1nd0ws
  13657. }
  13658. elseif ($NT6)
  13659. {
  13660. echoWindows
  13661. CONOUT "Error: product key not found.`n"
  13662. }
  13663. ​
  13664. if ($NT6 -And -Not $NT8) {
  13665. ClcRun
  13666. }
  13667. ​
  13668. if ($NT8) {
  13669. ClicRun
  13670. }
  13671. ​
  13672. $doMSG = 1
  13673. ​
  13674. if ($c0ff1ce15.Count -GT 0)
  13675. {
  13676. CheckOhook
  13677. echoOffice
  13678. ParseList $wslp $o15App $c0ff1ce15
  13679. }
  13680. ​
  13681. if ($c0ff1ce14.Count -GT 0)
  13682. {
  13683. echoOffice
  13684. ParseList $wslp $o14App $c0ff1ce14
  13685. }
  13686. ​
  13687. if ($hSLC) {
  13688. [void]$Win32::SLClose($hSLC)
  13689. }
  13690. ​
  13691. if ($OsppHook -NE 0) {
  13692. try {sasv $offsvc -EA 1} catch {$OsppHook = 0; CONOUT "`nError: failed to start $offsvc Service.`n"}
  13693. }
  13694. ​
  13695. if ($OsppHook -NE 0) {
  13696. . InitializePInvoke "$OLdll" $true
  13697. $hSLC = 0
  13698. [void]$Win32::SLOpen([ref]$hSLC)
  13699. ​
  13700. $ospp15 = SlGetInfoSLID $o15App
  13701. $ospp14 = SlGetInfoSLID $o14App
  13702. }
  13703. ​
  13704. if ($ospp15.Count -GT 0)
  13705. {
  13706. echoOffice
  13707. ParseList $oslp $o15App $ospp15
  13708. }
  13709. ​
  13710. if ($ospp14.Count -GT 0)
  13711. {
  13712. echoOffice
  13713. ParseList $oslp $o14App $ospp14
  13714. }
  13715. ​
  13716. if ($hSLC) {
  13717. [void]$Win32::SLClose($hSLC)
  13718. }
  13719. ​
  13720. if ($NT7) {
  13721. vNextDiagRun
  13722. }
  13723. ​
  13724. ExitScript 0
  13725. :sppmgr:
  13726. ​
  13727. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  13728. ​
  13729. :troubleshoot
  13730. ​
  13731. set "line=_________________________________________________________________________________________________"
  13732. ​
  13733. :at_menu
  13734. ​
  13735. cls
  13736. title Troubleshoot %masver%
  13737. if not defined terminal mode 77, 30
  13738. ​
  13739. echo:
  13740. echo:
  13741. echo:
  13742. echo:
  13743. echo: _______________________________________________________________
  13744. echo:
  13745. echo: ___________________________________________________
  13746. echo:
  13747. echo: [2] Dism RestoreHealth
  13748. echo: [3] SFC Scannow
  13749. echo:
  13750. echo: [4] Fix WMI
  13751. echo: [5] Fix Licensing
  13752. echo: ___________________________________________________
  13753. echo:
  13754. echo: [0] %_exitmsg%
  13755. echo: _______________________________________________________________
  13756. echo:
  13757. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard :"
  13758. choice /C:23450 /N
  13759. set _erl=%errorlevel%
  13760. ​
  13761. if %_erl%==5 exit /b
  13762. if %_erl%==4 goto:retokens
  13763. if %_erl%==3 goto:fixwmi
  13764. if %_erl%==2 goto:sfcscan
  13765. if %_erl%==1 goto:dism_rest
  13766. goto :at_menu
  13767. ​
  13768. ::========================================================================================================================================
  13769. ​
  13770. :dism_rest
  13771. ​
  13772. cls
  13773. if not defined terminal mode 98, 30
  13774. title Dism /English /Online /Cleanup-Image /RestoreHealth
  13775. ​
  13776. if %winbuild% LSS 9200 (
  13777. %eline%
  13778. echo Unsupported OS version detected.
  13779. echo This command only works on Windows 8/8.1/10/11 and their Server equivalents.
  13780. goto :at_back
  13781. )
  13782. ​
  13783. set _int=
  13784. for %%a in (download.windowsupdate.com) do if not defined _int (
  13785. for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do (if not "%%#"=="" set _int=1)
  13786. )
  13787. ​
  13788. echo:
  13789. if defined _int (
  13790. echo Checking Internet Connection [Connected]
  13791. ) else (
  13792. call :dk_color2 %_White% " " %Red% "Checking Internet Connection [Not connected]"
  13793. )
  13794. ​
  13795. echo %line%
  13796. echo:
  13797. echo DISM uses Windows Update to provide replacement files required to fix corruption.
  13798. echo This will take 5-15 minutes or more..
  13799. echo %line%
  13800. echo:
  13801. echo Notes:
  13802. echo:
  13803. call :dk_color2 %_White% " - " %Gray% "Make sure the internet is connected."
  13804. call :dk_color2 %_White% " - " %Gray% "Make sure that Windows update is properly working."
  13805. echo:
  13806. echo %line%
  13807. echo:
  13808. choice /C:09 /N /M "> [9] Continue [0] Go back : "
  13809. if %errorlevel%==1 goto at_menu
  13810. ​
  13811. cls
  13812. if not defined terminal mode 110, 30
  13813. ​
  13814. for /f %%a in ('%psc% "(Get-Date).ToString('yyyyMMdd-HHmmssfff')"') do set _time=%%a
  13815. ​
  13816. %psc% Stop-Service TrustedInstaller -force %nul%
  13817. ​
  13818. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\backup_cbs_%_time%.log" %nul%
  13819. copy /y /b "%SystemRoot%\logs\DISM\dism.log" "%SystemRoot%\logs\DISM\backup_dism_%_time%.log" %nul%
  13820. del /f /q "%SystemRoot%\logs\cbs\cbs.log" %nul%
  13821. del /f /q "%SystemRoot%\logs\DISM\dism.log" %nul%
  13822. ​
  13823. echo:
  13824. echo Applying the command...
  13825. echo dism /english /online /cleanup-image /restorehealth
  13826. dism /english /online /cleanup-image /restorehealth
  13827. ​
  13828. timeout /t 5 %nul1%
  13829. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\cbs_%_time%.log" %nul%
  13830. copy /y /b "%SystemRoot%\logs\DISM\dism.log" "%SystemRoot%\logs\DISM\dism_%_time%.log" %nul%
  13831. ​
  13832. if not exist "!desktop!\AT_Logs\" md "!desktop!\AT_Logs\" %nul%
  13833. call :compresslog cbs\cbs_%_time%.log AT_Logs\RHealth_CBS %nul%
  13834. call :compresslog DISM\dism_%_time%.log AT_Logs\RHealth_DISM %nul%
  13835. ​
  13836. if not exist "!desktop!\AT_Logs\RHealth_CBS_%_time%.cab" (
  13837. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "!desktop!\AT_Logs\RHealth_CBS_%_time%.log" %nul%
  13838. )
  13839. ​
  13840. if not exist "!desktop!\AT_Logs\RHealth_DISM_%_time%.cab" (
  13841. copy /y /b "%SystemRoot%\logs\DISM\dism.log" "!desktop!\AT_Logs\RHealth_DISM_%_time%.log" %nul%
  13842. )
  13843. ​
  13844. echo:
  13845. call :dk_color %Gray% "CBS and DISM logs are copied to the AT_Logs folder on your desktop."
  13846. goto :at_back
  13847. ​
  13848. ::========================================================================================================================================
  13849. ​
  13850. :sfcscan
  13851. ​
  13852. cls
  13853. if not defined terminal mode 98, 30
  13854. title sfc /scannow
  13855. ​
  13856. echo:
  13857. echo %line%
  13858. echo:
  13859. echo SFC will repair missing or corrupted system files.
  13860. echo It is recommended you run the DISM option first before this one.
  13861. echo This will take 10-15 minutes or more..
  13862. echo:
  13863. echo If SFC could not fix something, then run the command again to see if it may be able
  13864. echo to the next time. Sometimes it may take running the sfc /scannow command 3 times
  13865. echo restarting the PC after each time to completely fix everything that it's able to.
  13866. echo:
  13867. echo %line%
  13868. echo:
  13869. choice /C:09 /N /M "> [9] Continue [0] Go back : "
  13870. if %errorlevel%==1 goto at_menu
  13871. ​
  13872. cls
  13873. for /f %%a in ('%psc% "(Get-Date).ToString('yyyyMMdd-HHmmssfff')"') do set _time=%%a
  13874. ​
  13875. %psc% Stop-Service TrustedInstaller -force %nul%
  13876. ​
  13877. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\backup_cbs_%_time%.log" %nul%
  13878. del /f /q "%SystemRoot%\logs\cbs\cbs.log" %nul%
  13879. ​
  13880. echo:
  13881. echo Applying the command...
  13882. echo sfc /scannow
  13883. sfc /scannow
  13884. ​
  13885. timeout /t 5 %nul1%
  13886. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\cbs_%_time%.log" %nul%
  13887. ​
  13888. if not exist "!desktop!\AT_Logs\" md "!desktop!\AT_Logs\" %nul%
  13889. call :compresslog cbs\cbs_%_time%.log AT_Logs\SFC_CBS %nul%
  13890. ​
  13891. if not exist "!desktop!\AT_Logs\SFC_CBS_%_time%.cab" (
  13892. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "!desktop!\AT_Logs\SFC_CBS_%_time%.log" %nul%
  13893. )
  13894. ​
  13895. echo:
  13896. call :dk_color %Gray% "The CBS log was copied to the AT_Logs folder on your Desktop."
  13897. goto :at_back
  13898. ​
  13899. ::========================================================================================================================================
  13900. ​
  13901. :retokens
  13902. ​
  13903. cls
  13904. if not defined terminal (
  13905. mode 125, 32
  13906. %psc% "&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=31;$B.Height=200;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}" %nul%
  13907. )
  13908. title Fix Licensing ^(ClipSVC ^+ SPP ^+ OSPP^)
  13909. ​
  13910. if %winbuild% EQU 6001 (
  13911. %eline%
  13912. echo This option is not supported on Windows Vista SP1.
  13913. echo Upgrade to Windows Vista SP2.
  13914. goto :at_back
  13915. )
  13916. ​
  13917. echo:
  13918. echo %line%
  13919. echo:
  13920. echo Notes:
  13921. echo:
  13922. echo - This option helps in troubleshooting activation issues.
  13923. echo:
  13924. echo - This option will:
  13925. echo - Deactivate Windows and Office, you may need to reactivate.
  13926. echo If Windows is activated with motherboard / OEM / Digital license
  13927. echo then Windows will activate itself again.
  13928. echo:
  13929. echo - Clear ClipSVC, SPP and OSPP licenses.
  13930. echo - Fix permissions of SPP tokens folder and registries.
  13931. echo - Trigger the repair option for Office.
  13932. echo:
  13933. call :dk_color2 %_White% " - " %Blue% "Apply this option only when it is necessary."
  13934. echo:
  13935. echo %line%
  13936. echo:
  13937. choice /C:09 /N /M "> [9] Continue [0] Go back : "
  13938. if %errorlevel%==1 goto at_menu
  13939. ​
  13940. ::========================================================================================================================================
  13941. ​
  13942. :: Rebuild ClipSVC Licences
  13943. ​
  13944. cls
  13945. :cleanlicensing
  13946. ​
  13947. echo:
  13948. echo %line%
  13949. echo:
  13950. call :dk_color %Blue% "Rebuilding ClipSVC Licenses..."
  13951. echo:
  13952. ​
  13953. if %winbuild% LSS 10240 (
  13954. echo ClipSVC license rebuilding is supported only on Windows 10/11.
  13955. echo Skipping...
  13956. goto :rebuildspptok
  13957. )
  13958. ​
  13959. %psc% "(([WMISEARCHER]'SELECT Name FROM SoftwareLicensingProduct WHERE LicenseStatus=1 AND GracePeriodRemaining=0 AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).Name" %nul2% | findstr /i "Windows" %nul1% && (
  13960. echo Windows is permanently activated.
  13961. echo Skipping...
  13962. goto :rebuildspptok
  13963. )
  13964. ​
  13965. set _partial=
  13966. set _keymatch=
  13967. for /f "tokens=2 delims==" %%# in ('%psc% "(([WMISEARCHER]'SELECT PartialProductKey FROM SoftwareLicensingProduct WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND PartialProductKey IS NOT NULL AND LicenseDependsOn is NULL').Get()).PartialProductKey | %% {echo ('PartialProductKey='+$_)}" %nul6%') do set "_partial=%%#"
  13968. for %%# in (8HV2C QPFCT 3V66T PKCKT WXCHW 8TYMD 6F4BT 8HVX7 KD72Y 7CFBY DRR8H P39PB DYJWX MDWWW 9HKR4 M7V2X 2YV77 WT2RQ MHBPB QPF8P 2YV66 VMJ2C DJ4F6 CKFFD YY74H J8JXD BHDCD T6R4W D32MH RRK69 3PJBP) do if /i "%_partial%"=="%%#" set _keymatch=1
  13969. ​
  13970. if not defined _keymatch (
  13971. echo HWID activation key is not installed.
  13972. echo Skipping...
  13973. goto :rebuildspptok
  13974. )
  13975. ​
  13976. %psc% "If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}"
  13977. if errorlevel 1 (
  13978. echo Internet is not connected.
  13979. echo Skipping...
  13980. goto :rebuildspptok
  13981. )
  13982. ​
  13983. set resfail=
  13984. for %%# in (
  13985. licensing.mp.microsoft.com/v7.0/licenses/content
  13986. login.live.com/ppsecure/deviceaddcredential.srf
  13987. purchase.mp.microsoft.com/v7.0/users/me/orders
  13988. ) do if not defined resfail (
  13989. %psc% "try { [Net.ServicePointManager]::SecurityProtocol=[Net.SecurityProtocolType]::Tls12; irm https://%%# -Method POST } catch { if ($_.Exception.Response -eq $null) { Write-Host """"[%%#] $($_.Exception.Message)"""" -ForegroundColor Red -BackgroundColor Black; exit 3 } }"
  13990. if !errorlevel!==3 set resfail=1
  13991. )
  13992. ​
  13993. if defined resfail (
  13994. echo Failed to connect to licensing servers.
  13995. echo Skipping...
  13996. goto :rebuildspptok
  13997. )
  13998. ​
  13999. echo Stopping ClipSVC service...
  14000. %psc% Stop-Service ClipSVC -force %nul%
  14001. timeout /t 2 %nul%
  14002. ​
  14003. echo:
  14004. echo Applying the command to clean ClipSVC Licenses...
  14005. echo rundll32 clipc.dll,ClipCleanUpState
  14006. ​
  14007. rundll32 clipc.dll,ClipCleanUpState
  14008. ​
  14009. if %winbuild% LEQ 10240 (
  14010. echo [Successful]
  14011. ) else (
  14012. if exist "%ProgramData%\Microsoft\Windows\ClipSVC\tokens.dat" (
  14013. call :dk_color %Red% "[Failed]"
  14014. ) else (
  14015. echo [Successful]
  14016. )
  14017. )
  14018. ​
  14019. :: Below registry key (Volatile & Protected) gets created after the ClipSVC License cleanup command, and gets automatically deleted after
  14020. :: system restart. It needs to be deleted to activate the system without restart.
  14021. ​
  14022. set "RegKey=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ClipSVC\Volatile\PersistedSystemState"
  14023. set "_ident=HKU\S-1-5-19\SOFTWARE\Microsoft\IdentityCRL"
  14024. ​
  14025. reg query "%RegKey%" %nul% && %nul% call :regownstart
  14026. reg delete "%RegKey%" /f %nul%
  14027. ​
  14028. echo:
  14029. echo Deleting a Volatile ^& Protected Registry Key...
  14030. echo [%RegKey%]
  14031. reg query "%RegKey%" %nul% && (
  14032. call :dk_color %Red% "[Failed]"
  14033. echo Reboot your machine using the restart option, that will delete this registry key automatically.
  14034. ) || (
  14035. echo [Successful]
  14036. )
  14037. ​
  14038. :: Clear HWID token related registry to fix activation incase there is any corruption
  14039. ​
  14040. echo:
  14041. echo Deleting IdentityCRL Registry Key...
  14042. echo [%_ident%]
  14043. reg delete "%_ident%" /f %nul%
  14044. reg query "%_ident%" %nul% && (
  14045. call :dk_color %Red% "[Failed]"
  14046. ) || (
  14047. echo [Successful]
  14048. )
  14049. ​
  14050. %psc% Stop-Service ClipSVC -force %nul%
  14051. ​
  14052. :: Rebuild ClipSVC folder to fix permission issues
  14053. ​
  14054. echo:
  14055. if %winbuild% GTR 10240 (
  14056. echo Deleting folder %ProgramData%\Microsoft\Windows\ClipSVC\
  14057. rmdir /s /q "C:\ProgramData\Microsoft\Windows\ClipSvc" %nul%
  14058. ​
  14059. if exist "%ProgramData%\Microsoft\Windows\ClipSVC\" (
  14060. call :dk_color %Red% "[Failed]"
  14061. ) else (
  14062. echo [Successful]
  14063. )
  14064. ​
  14065. echo:
  14066. echo Rebuilding the %ProgramData%\Microsoft\Windows\ClipSVC\ folder...
  14067. %psc% Start-Service ClipSVC %nul%
  14068. timeout /t 3 %nul%
  14069. if not exist "%ProgramData%\Microsoft\Windows\ClipSVC\" timeout /t 5 %nul%
  14070. if not exist "%ProgramData%\Microsoft\Windows\ClipSVC\" (
  14071. call :dk_color %Red% "[Failed]"
  14072. ) else (
  14073. echo [Successful]
  14074. )
  14075. )
  14076. ​
  14077. echo:
  14078. echo Restarting wlidsvc ^& LicenseManager services...
  14079. for %%# in (wlidsvc LicenseManager) do (%psc% "Start-Job { Restart-Service %%# } | Wait-Job -Timeout 20 | Out-Null")
  14080. ​
  14081. ::========================================================================================================================================
  14082. ​
  14083. :: Rebuild SPP Tokens
  14084. ​
  14085. :rebuildspptok
  14086. ​
  14087. echo:
  14088. echo %line%
  14089. echo:
  14090. call :dk_color %Blue% "Rebuilding SPP licensing tokens..."
  14091. echo:
  14092. ​
  14093. echo Clearing KMS Cache...
  14094. echo:
  14095. call :_taskclear-cache
  14096. ​
  14097. %nul% reg query "HKLM\%SPPk%\%_wApp%" && (
  14098. echo Removing KMS38 protection...
  14099. %psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':regdel\:.*';. ([scriptblock]::Create($f[1]))"
  14100. %nul% reg delete "HKLM\%SPPk%\%_wApp%" /f
  14101. %nul% reg query "HKLM\%SPPk%\%_wApp%" && (
  14102. call :dk_color %Red% "Failed to remove KMS38 protection."
  14103. ) || (
  14104. echo Successfully removed KMS38 protection.
  14105. echo Successfully cleared KMS Cache.
  14106. )
  14107. ) || (
  14108. echo Successfully cleared KMS Cache.
  14109. )
  14110. echo:
  14111. ​
  14112. call :scandat check
  14113. ​
  14114. if not defined token (
  14115. call :dk_color %Red% "tokens.dat file not found."
  14116. ) else (
  14117. echo tokens.dat file: [%token%]
  14118. )
  14119. ​
  14120. set tokenstore=
  14121. set badregistry=
  14122. for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v TokenStore %nul6%') do call set "tokenstore=%%b"
  14123. if %winbuild% GEQ 9200 if /i not "%tokenstore%"=="%SysPath%\spp\store" if /i not "%tokenstore%"=="%SysPath%\spp\store\2.0" if /i not "%tokenstore%"=="%SysPath%\spp\store_test\2.0" (
  14124. set badregistry=1
  14125. echo:
  14126. call :dk_color %Red% "Correct path not found in TokenStore Registry [%tokenstore%]"
  14127. )
  14128. ​
  14129. :: Check sppsvc permissions and apply fixes
  14130. ​
  14131. if %winbuild% GEQ 9200 if not defined badregistry (
  14132. echo:
  14133. echo Checking SPP permission related issues...
  14134. call :checkperms
  14135. if defined permerror (
  14136. call :dk_color %Red% "[!permerror!]"
  14137. %psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':fixsppperms\:.*';. ([scriptblock]::Create($f[1]))" %nul%
  14138. call :checkperms
  14139. if defined permerror (
  14140. call :dk_color %Red% "[!permerror!] [Failed To Fix]"
  14141. ) else (
  14142. call :dk_color %Green% "[Successfully Fixed]"
  14143. )
  14144. ) else (
  14145. echo [No Error Found]
  14146. )
  14147. )
  14148. ​
  14149. echo:
  14150. echo Stopping %_slser% service...
  14151. %psc% Stop-Service %_slser% -force %nul%
  14152. ​
  14153. set w=
  14154. set _sppint=
  14155. for %%# in (SppEx%w%tComObj.exe %_slexe%) do (reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ima%w%ge File Execu%w%tion Options\%%#" %nul% && (set _sppint=1))
  14156. if defined _sppint (
  14157. echo:
  14158. echo Removing SPP IFEO registry keys...
  14159. for %%# in (SppE%w%xtComObj.exe %_slexe%) do (reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ima%w%ge File Execu%w%tion Options\%%#" /f %nul%)
  14160. )
  14161. ​
  14162. if %winbuild% LSS 9200 if not defined _vis (
  14163. REM Fix issues caused by Update KB971033 in Windows 7
  14164. REM https://support.microsoft.com/en-us/help/4487266
  14165. echo:
  14166. echo Checking Update KB971033...
  14167. %psc% "if (Get-Hotfix -Id KB971033 -ErrorAction SilentlyContinue) {Exit 3}" %nul%
  14168. if !errorlevel!==3 (
  14169. echo Found, uninstalling it...
  14170. wusa /uninstall /quiet /norestart /kb:971033
  14171. ) else (
  14172. echo [Not Found]
  14173. )
  14174. %psc% Stop-Service sppuinotify -force %nul%
  14175. sc config sppuinotify start= disabled
  14176. del /f /q %SysPath%\7B296FB0-376B-497e-B012-9C450E1B7327-*.C7483456-A289-439d-8115-601632D005A0 /ah
  14177. )
  14178. ​
  14179. :: Delete registry keys that are not deleted by activation scripts
  14180. ​
  14181. if not defined _vis (
  14182. echo:
  14183. echo Cleaning some licensing-related registry keys...
  14184. %nul% reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "ServiceSessionId" /f
  14185. %nul% reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "LicStatusArray" /f
  14186. %nul% reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "PolicyValuesArray" /f
  14187. %nul% reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "actionlist" /f
  14188. %nul% reg delete "HKLM\SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform\data" /f
  14189. )
  14190. ​
  14191. echo:
  14192. call :scandat delete
  14193. call :scandat check
  14194. ​
  14195. if defined token (
  14196. echo:
  14197. call :dk_color %Red% "Failed to delete .dat files."
  14198. echo:
  14199. )
  14200. ​
  14201. if defined _vis (
  14202. %psc% Start-Service %_slser% %nul%
  14203. )
  14204. ​
  14205. echo:
  14206. echo Reinstalling system licenses...
  14207. %psc% "$sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses" %nul%
  14208. if %errorlevel% NEQ 0 %psc% "$sls = Get-WmiObject SoftwareLicensingService; $f=[System.IO.File]::ReadAllText('!_batp!') -split ':xrm\:.*';. ([scriptblock]::Create($f[1])); ReinstallLicenses" %nul%
  14209. if %errorlevel% EQU 0 (
  14210. echo [Successful]
  14211. ) else (
  14212. call :dk_color %Red% "[Failed]"
  14213. )
  14214. ​
  14215. call :scandat check
  14216. ​
  14217. echo:
  14218. if not defined token (
  14219. call :dk_color %Red% "Failed to rebuild tokens.dat file."
  14220. ) else (
  14221. echo tokens.dat file was rebuilt successfully.
  14222. )
  14223. ​
  14224. if %winbuild% LSS 9200 if not defined _vis (
  14225. sc config sppuinotify start= demand
  14226. )
  14227. ​
  14228. ::========================================================================================================================================
  14229. ​
  14230. :: Rebuild OSPP Tokens
  14231. ​
  14232. echo:
  14233. echo %line%
  14234. echo:
  14235. call :dk_color %Blue% "Rebuilding OSPP licensing tokens..."
  14236. echo:
  14237. ​
  14238. sc qc osppsvc %nul% || (
  14239. echo OSPP-based Office is not installed.
  14240. echo Skipping rebuilding OSPP tokens...
  14241. goto :repairoffice
  14242. )
  14243. ​
  14244. call :scandatospp check
  14245. ​
  14246. if not defined token (
  14247. call :dk_color %Red% "tokens.dat file not found."
  14248. ) else (
  14249. echo tokens.dat file: [%token%]
  14250. )
  14251. ​
  14252. echo:
  14253. echo Stopping osppsvc service...
  14254. %psc% Stop-Service osppsvc -force %nul%
  14255. ​
  14256. echo:
  14257. call :scandatospp delete
  14258. call :scandatospp check
  14259. ​
  14260. if defined token (
  14261. echo:
  14262. call :dk_color %Red% "Failed to delete .dat files."
  14263. echo:
  14264. )
  14265. ​
  14266. echo:
  14267. echo Starting osppsvc service to generate tokens.dat...
  14268. %psc% Start-Service osppsvc %nul%
  14269. call :scandatospp check
  14270. if not defined token (
  14271. %psc% Stop-Service osppsvc -force %nul%
  14272. %psc% Start-Service osppsvc %nul%
  14273. timeout /t 3 %nul%
  14274. )
  14275. ​
  14276. call :scandatospp check
  14277. ​
  14278. echo:
  14279. if not defined token (
  14280. call :dk_color %Red% "Failed to rebuild tokens.dat file."
  14281. ) else (
  14282. echo tokens.dat file was rebuilt successfully.
  14283. )
  14284. ​
  14285. ::========================================================================================================================================
  14286. ​
  14287. :repairoffice
  14288. ​
  14289. echo:
  14290. echo %line%
  14291. echo:
  14292. call :dk_color %Blue% "Repairing Office licenses..."
  14293. echo:
  14294. ​
  14295. for %%# in (68 86) do (
  14296. for %%A in (msi14 msi15 msi16 c2r14 c2r15 c2r16) do (set %%A_%%#=&set %%Arepair%%#=)
  14297. )
  14298. ​
  14299. set _68=HKLM\SOFTWARE\Microsoft\Office
  14300. set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office
  14301. ​
  14302. reg query %_68%\14.0\CVH /f Click2run /k %nul% && (set "c2r14_68=Office 14.0 C2R x86/x64" & set "c2r14repair68=")
  14303. reg query %_86%\14.0\CVH /f Click2run /k %nul% && (set "c2r14_86=Office 14.0 C2R x86" & set "c2r14repair86=")
  14304. ​
  14305. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set "msi14_86=Office 14.0 MSI x86" & call :getrepairsetup msi14repair86 14)
  14306. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set "msi14_68=Office 14.0 MSI x86/x64" & call :getrepairsetup msi14repair68 14)
  14307. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set "msi15_86=Office 15.0 MSI x86" & call :getrepairsetup msi15repair86 15)
  14308. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set "msi15_68=Office 15.0 MSI x86/x64" & call :getrepairsetup msi15repair68 15)
  14309. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set "msi16_86=Office 16.0 MSI x86" & call :getrepairsetup msi16repair86 16)
  14310. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\*Picker.dll" (set "msi16_68=Office 16.0 MSI x86/x64" & call :getrepairsetup msi16repair68 16)
  14311. ​
  14312. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\15.0\ClickToRun /v InstallPath" %nul6%') do if exist "%%b\root\Licenses\ProPlus*.xrm-ms" (set "c2r15_86=Office 15.0 C2R x86" & call :getc2rrepair c2r15repair86 integratedoffice.exe)
  14313. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\15.0\ClickToRun /v InstallPath" %nul6%') do if exist "%%b\root\Licenses\ProPlus*.xrm-ms" (set "c2r15_68=Office 15.0 C2R x86/x64" & call :getc2rrepair c2r15repair68 integratedoffice.exe)
  14314. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\ClickToRun /v InstallPath" %nul6%') do if exist "%%b\root\Licenses16\ProPlus*.xrm-ms" (set "c2r16_86=Office 16.0 C2R x86" & call :getc2r16repair c2r16repair86 OfficeClickToRun.exe)
  14315. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\ClickToRun /v InstallPath" %nul6%') do if exist "%%b\root\Licenses16\ProPlus*.xrm-ms" (set "c2r16_68=Office 16.0 C2R x86/x64" & call :getc2r16repair c2r16repair68 OfficeClickToRun.exe)
  14316. ​
  14317. set uwp16=
  14318. if %winbuild% GEQ 10240 (
  14319. %psc% "Get-AppxPackage -name "Microsoft.Office.Desktop"" | find /i "Office" %nul1% && set uwp16=Office 16.0 UWP
  14320. )
  14321. ​
  14322. set /a counter=0
  14323. echo Checking installed Office versions...
  14324. echo:
  14325. ​
  14326. for %%# in (
  14327. "%msi14_68%"
  14328. "%msi14_86%"
  14329. "%msi15_68%"
  14330. "%msi15_86%"
  14331. "%msi16_68%"
  14332. "%msi16_86%"
  14333. "%c2r14_68%"
  14334. "%c2r14_86%"
  14335. "%c2r15_68%"
  14336. "%c2r15_86%"
  14337. "%c2r16_68%"
  14338. "%c2r16_86%"
  14339. "%uwp16%"
  14340. ) do (
  14341. if not "%%#"=="""" (
  14342. set insoff=%%#
  14343. set insoff=!insoff:"=!
  14344. echo [!insoff!]
  14345. set /a counter+=1
  14346. )
  14347. )
  14348. ​
  14349. if %counter% GTR 1 (
  14350. %eline%
  14351. echo Multiple Office versions found.
  14352. echo It is recommended to only install one version of Office.
  14353. echo ________________________________________________________________
  14354. echo:
  14355. )
  14356. ​
  14357. echo:
  14358. if %counter% EQU 0 (
  14359. echo Office ^(2010 and later^) is not installed.
  14360. goto :repairend
  14361. ) else if not defined c2r16_68 if not defined c2r16_86 (
  14362. call :dk_color %_Yellow% "A new window will appear, in that window you need to select [Quick Repair] option."
  14363. if defined terminal (
  14364. call :dk_color %_Yellow% "Press [0] to continue..."
  14365. choice /c 0 /n
  14366. ) else (
  14367. call :dk_color %_Yellow% "Press any key to continue..."
  14368. pause %nul1%
  14369. )
  14370. )
  14371. ​
  14372. if defined uwp16 (
  14373. echo:
  14374. echo Skipping repair for Office 16.0 UWP...
  14375. echo:
  14376. )
  14377. ​
  14378. set c2r14=
  14379. if defined c2r14_68 set c2r14=1
  14380. if defined c2r14_86 set c2r14=1
  14381. ​
  14382. if defined c2r14 (
  14383. echo:
  14384. echo Skipping repair for Office 14.0 C2R...
  14385. echo:
  14386. )
  14387. ​
  14388. if defined msi14_68 if exist "%msi14repair68%" echo Running - "%msi14repair68%" & "%msi14repair68%"
  14389. if defined msi14_86 if exist "%msi14repair86%" echo Running - "%msi14repair86%" & "%msi14repair86%"
  14390. if defined msi15_68 if exist "%msi15repair68%" echo Running - "%msi15repair68%" & "%msi15repair68%"
  14391. if defined msi15_86 if exist "%msi15repair86%" echo Running - "%msi15repair86%" & "%msi15repair86%"
  14392. if defined msi16_68 if exist "%msi16repair68%" echo Running - "%msi16repair68%" & "%msi16repair68%"
  14393. if defined msi16_86 if exist "%msi16repair86%" echo Running - "%msi16repair86%" & "%msi16repair86%"
  14394. if defined c2r15_68 if exist "%c2r15repair68%" echo Running - "%c2r15repair68%" REPAIRUI RERUNMODE & "%c2r15repair68%" REPAIRUI RERUNMODE
  14395. if defined c2r15_86 if exist "%c2r15repair86%" echo Running - "%c2r15repair86%" REPAIRUI RERUNMODE & "%c2r15repair86%" REPAIRUI RERUNMODE
  14396. if defined c2r16_68 if exist "%c2r16repair68%" echo Running - "%c2r16repair68%" Scenario=Repair RepairType=QuickRepair & "%c2r16repair68%" Scenario=Repair RepairType=QuickRepair
  14397. if defined c2r16_86 if exist "%c2r16repair86%" echo Running - "%c2r16repair86%" Scenario=Repair RepairType=QuickRepair & "%c2r16repair86%" Scenario=Repair RepairType=QuickRepair
  14398. ​
  14399. :repairend
  14400. ​
  14401. echo:
  14402. echo %line%
  14403. echo:
  14404. echo:
  14405. call :dk_color %Green% "Finished"
  14406. goto :at_back
  14407. ​
  14408. :getc2rrepair
  14409. ​
  14410. for %%# in (X86 X64) do (
  14411. if exist "%systemdrive%\Program Files\Microsoft Office 15\Client%%#\%2" (
  14412. set "%1=%systemdrive%\Program Files\Microsoft Office 15\Client%%#\%2"
  14413. )
  14414. )
  14415. exit /b
  14416. ​
  14417. :getc2r16repair
  14418. ​
  14419. for %%# in (%_68% %_86%) do (
  14420. for /f "skip=2 tokens=2*" %%a in ('"reg query %%#\ClickToRun\Configuration /v ClientFolder" %nul6%') do if exist "%%b\%2" (set "%1=%%b\%2")
  14421. )
  14422. exit /b
  14423. ​
  14424. :getrepairsetup
  14425. ​
  14426. set "_common86=%systemdrive%\Program Files (x86)\Common Files\Microsoft Shared\OFFICE%2\Office Setup Controller\setup.exe"
  14427. set "_common68=%systemdrive%\Program Files\Common Files\Microsoft Shared\OFFICE%2\Office Setup Controller\setup.exe"
  14428. ​
  14429. if exist "%_common86%" set "%1=%_common86%"
  14430. if exist "%_common68%" set "%1=%_common68%"
  14431. exit /b
  14432. ​
  14433. ::========================================================================================================================================
  14434. ​
  14435. :fixwmi
  14436. ​
  14437. cls
  14438. if not defined terminal mode 98, 34
  14439. title Fix WMI
  14440. ​
  14441. :: https://techcommunity.microsoft.com/t5/ask-the-performance-team/wmi-repository-corruption-or-not/ba-p/375484
  14442. ​
  14443. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" (
  14444. %eline%
  14445. echo Rebuilding WMI is not recommended on Windows Server, aborting...
  14446. goto :at_back
  14447. )
  14448. ​
  14449. echo:
  14450. echo Checking WMI
  14451. call :checkwmi
  14452. ​
  14453. :: Apply basic fix first and check
  14454. ​
  14455. if defined error (
  14456. %psc% Stop-Service Winmgmt -force %nul%
  14457. winmgmt /salvagerepository %nul%
  14458. call :checkwmi
  14459. )
  14460. ​
  14461. if not defined error (
  14462. echo [Working]
  14463. echo No need to apply this option, aborting...
  14464. goto :at_back
  14465. )
  14466. ​
  14467. call :dk_color %Red% "[Not Responding]"
  14468. ​
  14469. set _corrupt=
  14470. sc start Winmgmt %nul%
  14471. if %errorlevel% EQU 1060 set _corrupt=1
  14472. sc query Winmgmt %nul% || set _corrupt=1
  14473. for %%G in (DependOnService Description DisplayName ErrorControl ImagePath ObjectName Start Type) do if not defined _corrupt (reg query HKLM\SYSTEM\CurrentControlSet\Services\Winmgmt /v %%G %nul% || set _corrupt=1)
  14474. ​
  14475. echo:
  14476. if defined _corrupt (
  14477. %eline%
  14478. echo Winmgmt service is corrupted, aborting...
  14479. goto :at_back
  14480. )
  14481. ​
  14482. echo Disabling Winmgmt service
  14483. sc config Winmgmt start= disabled %nul%
  14484. if %errorlevel% EQU 0 (
  14485. echo [Successful]
  14486. ) else (
  14487. call :dk_color %Red% "[Failed] Aborting..."
  14488. sc config Winmgmt start= auto %nul%
  14489. goto :at_back
  14490. )
  14491. ​
  14492. echo:
  14493. echo Stopping Winmgmt service
  14494. %psc% Stop-Service Winmgmt -force %nul%
  14495. %psc% Stop-Service Winmgmt -force %nul%
  14496. %psc% Stop-Service Winmgmt -force %nul%
  14497. sc query Winmgmt | find /i "STOPPED" %nul% && (
  14498. echo [Successful]
  14499. ) || (
  14500. call :dk_color %Red% "[Failed]"
  14501. call :dk_color %Blue% "Its recommended to select [Restart] option and then apply Fix WMI option again."
  14502. echo %line%
  14503. echo:
  14504. choice /C:21 /N /M "> [1] Restart [2] Revert Back Changes :"
  14505. if !errorlevel!==1 (sc config Winmgmt start= auto %nul%&goto :at_back)
  14506. echo:
  14507. echo Restarting...
  14508. shutdown -t 5 -r
  14509. exit
  14510. )
  14511. ​
  14512. echo:
  14513. echo Deleting WMI repository
  14514. rmdir /s /q "%SysPath%\wbem\repository\" %nul%
  14515. if exist "%SysPath%\wbem\repository\" (
  14516. call :dk_color %Red% "[Failed]"
  14517. ) else (
  14518. echo [Successful]
  14519. )
  14520. ​
  14521. echo:
  14522. echo Enabling Winmgmt service
  14523. sc config Winmgmt start= auto %nul%
  14524. if %errorlevel% EQU 0 (
  14525. echo [Successful]
  14526. ) else (
  14527. call :dk_color %Red% "[Failed]"
  14528. )
  14529. ​
  14530. call :checkwmi
  14531. if not defined error (
  14532. echo:
  14533. echo Checking WMI
  14534. call :dk_color %Green% "[Working]"
  14535. goto :at_back
  14536. )
  14537. ​
  14538. echo:
  14539. echo Registering .dll's and Compiling .mof's, .mfl's
  14540. call :registerobj %nul%
  14541. ​
  14542. echo:
  14543. echo Checking WMI
  14544. call :checkwmi
  14545. if defined error (
  14546. call :dk_color %Red% "[Not Responding]"
  14547. echo:
  14548. echo Run [Dism RestoreHealth] and [SFC Scannow] options and make sure there are no errors.
  14549. ) else (
  14550. call :dk_color %Green% "[Working]"
  14551. )
  14552. ​
  14553. goto :at_back
  14554. ​
  14555. :registerobj
  14556. ​
  14557. :: https://eskonr.com/2012/01/how-to-fix-wmi-issues-automatically/
  14558. ​
  14559. %psc% Stop-Service Winmgmt -force %nul%
  14560. cd /d %SysPath%\wbem\
  14561. regsvr32 /s %SysPath%\scecli.dll
  14562. regsvr32 /s %SysPath%\userenv.dll
  14563. mofcomp cimwin32.mof
  14564. mofcomp cimwin32.mfl
  14565. mofcomp rsop.mof
  14566. mofcomp rsop.mfl
  14567. for /f %%s in ('dir /b /s *.dll') do regsvr32 /s %%s
  14568. for /f %%s in ('dir /b *.mof') do mofcomp %%s
  14569. for /f %%s in ('dir /b *.mfl') do mofcomp %%s
  14570. ​
  14571. winmgmt /salvagerepository
  14572. winmgmt /resetrepository
  14573. exit /b
  14574. ​
  14575. :checkwmi
  14576. ​
  14577. :: https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants
  14578. ​
  14579. set error=
  14580. %psc% "Get-WmiObject -Class Win32_ComputerSystem | Select-Object -Property CreationClassName" %nul2% | find /i "computersystem" %nul1%
  14581. if %errorlevel% NEQ 0 (set error=1& exit /b)
  14582. winmgmt /verifyrepository %nul%
  14583. if %errorlevel% NEQ 0 (set error=1& exit /b)
  14584. ​
  14585. %psc% "try { $null=([WMISEARCHER]'SELECT * FROM SoftwareLicensingService').Get().Version; exit 0 } catch { exit $_.Exception.InnerException.HResult }" %nul%
  14586. cmd /c exit /b %errorlevel%
  14587. echo "0x%=ExitCode%" | findstr /i "0x800410 0x800440 0x80131501" %nul1%
  14588. if %errorlevel% EQU 0 set error=1
  14589. exit /b
  14590. ​
  14591. ::========================================================================================================================================
  14592. ​
  14593. :at_back
  14594. ​
  14595. echo:
  14596. echo %line%
  14597. echo:
  14598. if defined terminal (
  14599. call :dk_color %_Yellow% "Press [0] key to %_exitmsg%..."
  14600. choice /c 0 /n
  14601. ) else (
  14602. call :dk_color %_Yellow% "Press any key to %_exitmsg%..."
  14603. pause %nul1%
  14604. )
  14605. goto :at_menu
  14606. ​
  14607. ::========================================================================================================================================
  14608. ​
  14609. :compresslog
  14610. ​
  14611. :: https://stackoverflow.com/a/46268232
  14612. ​
  14613. set "ddf="%SystemRoot%\Temp\%Random%%Random%%Random%%Random%""
  14614. %nul% del /q /f %ddf%
  14615. echo/.New Cabinet>%ddf%
  14616. echo/.set Cabinet=ON>>%ddf%
  14617. echo/.set CabinetFileCountThreshold=0;>>%ddf%
  14618. echo/.set Compress=ON>>%ddf%
  14619. echo/.set CompressionType=LZX>>%ddf%
  14620. echo/.set CompressionLevel=7;>>%ddf%
  14621. echo/.set CompressionMemory=21;>>%ddf%
  14622. echo/.set FolderFileCountThreshold=0;>>%ddf%
  14623. echo/.set FolderSizeThreshold=0;>>%ddf%
  14624. echo/.set GenerateInf=OFF>>%ddf%
  14625. echo/.set InfFileName=nul>>%ddf%
  14626. echo/.set MaxCabinetSize=0;>>%ddf%
  14627. echo/.set MaxDiskFileCount=0;>>%ddf%
  14628. echo/.set MaxDiskSize=0;>>%ddf%
  14629. echo/.set MaxErrors=1;>>%ddf%
  14630. echo/.set RptFileName=nul>>%ddf%
  14631. echo/.set UniqueFiles=ON>>%ddf%
  14632. for /f "tokens=* delims=" %%D in ('dir /a:-D/b/s "%SystemRoot%\logs\%1"') do (
  14633. echo/"%%~fD" /inf=no;>>%ddf%
  14634. )
  14635. makecab /F %ddf% /D DiskDirectory1="" /D CabinetNameTemplate="!desktop!\%2_%_time%.cab"
  14636. del /q /f %ddf%
  14637. exit /b
  14638. ​
  14639. ::========================================================================================================================================
  14640. ​
  14641. :checkperms
  14642. ​
  14643. :: This code checks if SPP has permission access to tokens folder and required registry keys. Incorrect permissions are often set by gaming spoofers.
  14644. ​
  14645. set permerror=
  14646. if not exist "%tokenstore%\" set "permerror=Error Found In Token Folder"
  14647. ​
  14648. if defined ps32onArm exit /b
  14649. ​
  14650. for %%# in (
  14651. "%tokenstore%+FullControl"
  14652. "HKLM:\SYSTEM\WPA+QueryValues, EnumerateSubKeys, WriteKey"
  14653. "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform+SetValue"
  14654. ) do for /f "tokens=1,2 delims=+" %%A in (%%#) do if not defined permerror (
  14655. %psc% "$acl = (Get-Acl '%%A' | fl | Out-String); if (-not ($acl -match 'NT SERVICE\\sppsvc Allow %%B') -or ($acl -match 'NT SERVICE\\sppsvc Deny')) {Exit 2}" %nul%
  14656. if !errorlevel!==2 (
  14657. if "%%A"=="%tokenstore%" (
  14658. set "permerror=Error Found In Token Folder"
  14659. ) else (
  14660. set "permerror=Error Found In SPP Registries"
  14661. )
  14662. )
  14663. )
  14664. ​
  14665. REM https://learn.microsoft.com/en-us/office/troubleshoot/activation/license-issue-when-start-office-application
  14666. ​
  14667. if not defined permerror (
  14668. reg query "HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion" %nul% && (
  14669. set "pol=HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Policies"
  14670. reg query "!pol!" %nul% || reg add "!pol!" %nul%
  14671. %psc% "$netServ = (New-Object Security.Principal.SecurityIdentifier('S-1-5-20')).Translate([Security.Principal.NTAccount]).Value; $aclString = Get-Acl 'Registry::!pol!' | Format-List | Out-String; if (-not ($aclString.Contains($netServ + ' Allow FullControl') -or $aclString.Contains('NT SERVICE\sppsvc Allow FullControl')) -or ($aclString.Contains('Deny'))) {Exit 3}" %nul%
  14672. if !errorlevel!==3 set "permerror=Error Found In S-1-5-20 SPP"
  14673. )
  14674. )
  14675. exit /b
  14676. ​
  14677. ::========================================================================================================================================
  14678. ​
  14679. :: Fix SPP related registry and folder permissions
  14680. ​
  14681. :fixsppperms:
  14682. # Fix perms for Token Folder
  14683. ​
  14684. if ($env:permerror -eq 'Error Found In Token Folder') {
  14685. New-Item -Path $env:tokenstore -ItemType Directory -Force
  14686. $sddl = 'O:BAG:BAD:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;OICIIO;GR;;;BU)(A;;FR;;;BU)(A;OICI;FA;;;S-1-5-80-123231216-2592883651-3715271367-3753151631-4175906628)'
  14687. $AclObject = New-Object System.Security.AccessControl.DirectorySecurity
  14688. $AclObject.SetSecurityDescriptorSddlForm($sddl)
  14689. Set-Acl -Path $env:tokenstore -AclObject $AclObject
  14690. exit
  14691. }
  14692. ​
  14693. # Fix perms for SPP registries
  14694. ​
  14695. if ($env:permerror -eq 'Error Found In SPP Registries') {
  14696. $acl = Get-Acl 'HKLM:\SYSTEM\WPA'
  14697. $rule = New-Object System.Security.AccessControl.RegistryAccessRule ('NT Service\sppsvc', 'QueryValues, EnumerateSubKeys, WriteKey', 'ContainerInherit, ObjectInherit', 'None', 'Allow')
  14698. $acl.ResetAccessRule($rule)
  14699. $acl.SetAccessRule($rule)
  14700. Set-Acl -Path 'HKLM:\SYSTEM\WPA' -AclObject $acl
  14701. $acl = Get-Acl 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform'
  14702. $rule = New-Object System.Security.AccessControl.RegistryAccessRule ('NT Service\sppsvc', 'SetValue', 'ContainerInherit, ObjectInherit', 'None', 'Allow')
  14703. $acl.ResetAccessRule($rule)
  14704. $acl.SetAccessRule($rule)
  14705. Set-Acl -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform' -AclObject $acl
  14706. exit
  14707. }
  14708. ​
  14709. # Fix perms for SPP in HKU\S-1-5-20
  14710. # https://learn.microsoft.com/en-us/office/troubleshoot/activation/license-issue-when-start-office-application
  14711. ​
  14712. if ($env:permerror -ne 'Error Found In S-1-5-20 SPP') {
  14713. exit
  14714. }
  14715. if (-not (Test-Path 'Registry::HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform')) {
  14716. exit
  14717. }
  14718. ​
  14719. # https://stackoverflow.com/a/35843420
  14720. ​
  14721. function Take-Permissions {
  14722. param($rootKey, $key, [System.Security.Principal.SecurityIdentifier]$sid = 'S-1-5-32-545', $recurse = $true)
  14723. switch -regex ($rootKey) {
  14724. 'HKCU|HKEY_CURRENT_USER' { $rootKey = 'CurrentUser' }
  14725. 'HKLM|HKEY_LOCAL_MACHINE' { $rootKey = 'LocalMachine' }
  14726. 'HKCR|HKEY_CLASSES_ROOT' { $rootKey = 'ClassesRoot' }
  14727. 'HKCC|HKEY_CURRENT_CONFIG' { $rootKey = 'CurrentConfig' }
  14728. 'HKU|HKEY_USERS' { $rootKey = 'Users' }
  14729. }
  14730. ​
  14731. ### Step 1 - escalate current process's privilege
  14732. # get SeTakeOwnership, SeBackup and SeRestore privileges before executes next lines, script needs Admin privilege
  14733. $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)
  14734. $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)
  14735. $TypeBuilder = $ModuleBuilder.DefineType(0)
  14736. $TypeBuilder.DefinePInvokeMethod('RtlAdjustPrivilege', 'ntdll.dll', 'Public, Static', 1, [int], @([int], [bool], [bool], [bool].MakeByRefType()), 1, 3) | Out-Null
  14737. 9, 17, 18 | ForEach-Object { $TypeBuilder.CreateType()::RtlAdjustPrivilege($_, $true, $false, [ref]$false) | Out-Null }
  14738. ​
  14739. function Take-KeyPermissions {
  14740. param($rootKey, $key, $sid, $recurse, $recurseLevel = 0)
  14741. ​
  14742. ### Step 2 - get ownerships of key - it works only for current key
  14743. $regKey = [Microsoft.Win32.Registry]::$rootKey.OpenSubKey($key, 'ReadWriteSubTree', 'TakeOwnership')
  14744. $acl = New-Object System.Security.AccessControl.RegistrySecurity
  14745. $acl.SetOwner($sid)
  14746. $regKey.SetAccessControl($acl)
  14747. ​
  14748. ### Step 3 - enable inheritance of permissions (not ownership) for current key from parent
  14749. $acl.SetAccessRuleProtection($false, $false)
  14750. $regKey.SetAccessControl($acl)
  14751. ​
  14752. ### Step 4 - only for top-level key, change permissions for current key and propagate it for subkeys
  14753. # to enable propagations for subkeys, it needs to execute Steps 2-3 for each subkey (Step 5)
  14754. if ($recurseLevel -eq 0) {
  14755. $regKey = $regKey.OpenSubKey('', 'ReadWriteSubTree', 'ChangePermissions')
  14756. $rule = New-Object System.Security.AccessControl.RegistryAccessRule($sid, 'FullControl', 'ContainerInherit', 'None', 'Allow')
  14757. $acl.ResetAccessRule($rule)
  14758. $regKey.SetAccessControl($acl)
  14759. }
  14760. ​
  14761. ### Step 5 - recursively repeat steps 2-5 for subkeys
  14762. if ($recurse) {
  14763. foreach ($subKey in $regKey.OpenSubKey('').GetSubKeyNames()) {
  14764. Take-KeyPermissions $rootKey ($key + '\' + $subKey) $sid $recurse ($recurseLevel + 1)
  14765. }
  14766. }
  14767. }
  14768. ​
  14769. Take-KeyPermissions $rootKey $key $sid $recurse
  14770. }
  14771. ​
  14772. Take-Permissions "Users" "S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" "S-1-5-20"
  14773. :fixsppperms:
  14774. ​
  14775. ::========================================================================================================================================
  14776. ​
  14777. :scandat
  14778. ​
  14779. set token=
  14780. for %%# in (
  14781. %SysPath%\spp\store_test\2.0\
  14782. %SysPath%\spp\store\
  14783. %SysPath%\spp\store\2.0\
  14784. %Systemdrive%\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\
  14785. %Systemdrive%\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareLicensing\
  14786. ) do (
  14787. ​
  14788. if %1==check (
  14789. if exist %%#tokens.dat set token=%%#tokens.dat
  14790. )
  14791. ​
  14792. if %1==delete (
  14793. if exist %%# (
  14794. %nul% dir /a-d /s "%%#*.dat" && (
  14795. attrib -r -s -h "%%#*.dat" /S
  14796. del /S /F /Q "%%#*.dat"
  14797. )
  14798. )
  14799. )
  14800. )
  14801. exit /b
  14802. ​
  14803. :scandatospp
  14804. ​
  14805. set token=
  14806. for %%# in (
  14807. %ProgramData%\Microsoft\OfficeSoftwareProtectionPlatform\
  14808. ) do (
  14809. ​
  14810. if %1==check (
  14811. if exist %%#tokens.dat set token=%%#tokens.dat
  14812. )
  14813. ​
  14814. if %1==delete (
  14815. if exist %%# (
  14816. %nul% dir /a-d /s "%%#*.dat" && (
  14817. attrib -r -s -h "%%#*.dat" /S
  14818. del /S /F /Q "%%#*.dat"
  14819. )
  14820. )
  14821. )
  14822. )
  14823. exit /b
  14824. ​
  14825. ::========================================================================================================================================
  14826. ​
  14827. :regownstart
  14828. ​
  14829. %psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':regown\:.*';. ([scriptblock]::Create($f[1]));"
  14830. exit /b
  14831. ​
  14832. :: Below code takes ownership of a volatile registry key and deletes it
  14833. :: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ClipSVC\Volatile\PersistedSystemState
  14834. ​
  14835. :regown:
  14836. $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)
  14837. $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)
  14838. $TypeBuilder = $ModuleBuilder.DefineType(0)
  14839. ​
  14840. $TypeBuilder.DefinePInvokeMethod('RtlAdjustPrivilege', 'ntdll.dll', 'Public, Static', 1, [int], @([int], [bool], [bool], [bool].MakeByRefType()), 1, 3) | Out-Null
  14841. $TypeBuilder.CreateType()::RtlAdjustPrivilege(9, $true, $false, [ref]$false) | Out-Null
  14842. ​
  14843. $SID = New-Object System.Security.Principal.SecurityIdentifier('S-1-5-32-544')
  14844. $IDN = ($SID.Translate([System.Security.Principal.NTAccount])).Value
  14845. $Admin = New-Object System.Security.Principal.NTAccount($IDN)
  14846. ​
  14847. $path = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\ClipSVC\Volatile\PersistedSystemState'
  14848. $key = [Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine', 'Registry64').OpenSubKey($path, 'ReadWriteSubTree', 'takeownership')
  14849. ​
  14850. $acl = $key.GetAccessControl()
  14851. $acl.SetOwner($Admin)
  14852. $key.SetAccessControl($acl)
  14853. ​
  14854. $rule = New-Object System.Security.AccessControl.RegistryAccessRule($Admin,"FullControl","Allow")
  14855. $acl.SetAccessRule($rule)
  14856. $key.SetAccessControl($acl)
  14857. :regown:
  14858. ​
  14859. ::========================================================================================================================================
  14860. ​
  14861. :: This code runs to undo below registry key KMS38 protection
  14862. :: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\55c92734-d682-4d71-983e-d6ec3f16059f
  14863. ​
  14864. :: This option is not used in KMS38 anymore, it's here only to remove previous versions protection.
  14865. ​
  14866. :regdel:
  14867. param (
  14868. [switch]$protect
  14869. )
  14870. ​
  14871. $SID = New-Object System.Security.Principal.SecurityIdentifier('S-1-5-32-544')
  14872. $Admin = ($SID.Translate([System.Security.Principal.NTAccount])).Value
  14873. ​
  14874. if($protect) {
  14875. $ruleArgs = @("$Admin", "Delete, SetValue", "ContainerInherit", "None", "Deny")
  14876. } else {
  14877. $ruleArgs = @("$Admin", "FullControl", "Allow")
  14878. }
  14879. ​
  14880. $path = 'SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\55c92734-d682-4d71-983e-d6ec3f16059f'
  14881. $key = [Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine', 'Registry64').OpenSubKey($path, 'ReadWriteSubTree', 'ChangePermissions')
  14882. $acl = $key.GetAccessControl()
  14883. ​
  14884. $rule = [System.Security.AccessControl.RegistryAccessRule]::new.Invoke($ruleArgs)
  14885. $acl.ResetAccessRule($rule)
  14886. $key.SetAccessControl($acl)
  14887. :regdel:
  14888. ​
  14889. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  14890. ​
  14891. :change_winedition
  14892. ​
  14893. :: To stage current edition while changing edition with CBS Upgrade Method, change 0 to 1 in below line
  14894. set _stg=0
  14895. ​
  14896. set "line=echo ___________________________________________________________________________________________"
  14897. ​
  14898. cls
  14899. if not defined terminal mode 98, 30
  14900. title Change Windows Edition %masver%
  14901. ​
  14902. if %winbuild% LSS 7600 (
  14903. %eline%
  14904. echo Unsupported OS version detected [%winbuild%].
  14905. echo This option is supported only for Windows 7/8/8.1/10/11 and their Server equivalents.
  14906. goto dk_done
  14907. )
  14908. ​
  14909. echo:
  14910. echo Initializing...
  14911. echo:
  14912. ​
  14913. for %%# in (
  14914. sppsvc.exe
  14915. dism.exe
  14916. ) do (
  14917. if not exist %SysPath%\%%# (
  14918. %eline%
  14919. echo [%SysPath%\%%#] file is missing, aborting...
  14920. call :dk_color %Blue% "Go back to Main Menu, select Troubleshoot and run DISM Restore and SFC Scan options."
  14921. call :dk_color %Blue% "After that, restart system and try activation again."
  14922. set fixes=%fixes% %mas%in-place_repair_upgrade
  14923. call :dk_color2 %Blue% "If it still shows the same error, do this - " %_Yellow% " %mas%in-place_repair_upgrade"
  14924. goto dk_done
  14925. )
  14926. )
  14927. ​
  14928. ::========================================================================================================================================
  14929. ​
  14930. set spp=SoftwareLicensingProduct
  14931. set sps=SoftwareLicensingService
  14932. ​
  14933. call :dk_reflection
  14934. call :dk_ckeckwmic
  14935. call :dk_sppissue
  14936. ​
  14937. for /f "tokens=6-7 delims=[]. " %%i in ('ver') do if not "%%j"=="" (
  14938. set fullbuild=%%i.%%j
  14939. ) else (
  14940. for /f "tokens=3" %%G in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v UBR" %nul6%') do if not errorlevel 1 set /a "UBR=%%G"
  14941. for /f "skip=2 tokens=3,4 delims=. " %%G in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v BuildLabEx') do (
  14942. if defined UBR (set "fullbuild=%%G.!UBR!") else (set "fullbuild=%%G.%%H")
  14943. )
  14944. )
  14945. ​
  14946. ::========================================================================================================================================
  14947. ​
  14948. :: Check Activation IDs
  14949. ​
  14950. call :dk_actids 55c92734-d682-4d71-983e-d6ec3f16059f
  14951. if not defined allapps (
  14952. %eline%
  14953. echo Failed to find activation IDs. Aborting...
  14954. call :dk_color %Blue% "To fix this issue, activate Windows from the main menu."
  14955. goto dk_done
  14956. )
  14957. ​
  14958. ::========================================================================================================================================
  14959. ​
  14960. :: Check Windows Edition and branch
  14961. ​
  14962. set osedition=
  14963. set dismnotworking=
  14964. ​
  14965. for /f "tokens=3 delims=: " %%a in ('DISM /English /Online /Get-CurrentEdition %nul6% ^| find /i "Current Edition :"') do set "osedition=%%a"
  14966. if not defined osedition set dismnotworking=1
  14967. ​
  14968. if %_wmic% EQU 1 set "chkedi=for /f "tokens=2 delims==" %%a in ('"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL) get LicenseFamily /VALUE" %nul6%')"
  14969. if %_wmic% EQU 0 set "chkedi=for /f "tokens=2 delims==" %%a in ('%psc% "(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}" %nul6%')"
  14970. if not defined osedition %chkedi% do if not errorlevel 1 (call set "osedition=%%a")
  14971. ​
  14972. if not defined osedition (
  14973. %eline%
  14974. echo Failed to detect OS edition, aborting...
  14975. call :dk_color %Blue% "To fix this issue, activate Windows from the main menu."
  14976. goto dk_done
  14977. )
  14978. ​
  14979. for /f "skip=2 tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v EditionID %nul6%') do set "regedition=%%a"
  14980. if /i not "%osedition%"=="%regedition%" (
  14981. set "showeditionerror=call :dk_color %_Yellow% "[%osedition%] [Reg-%regedition%].""
  14982. )
  14983. ​
  14984. set branch=
  14985. for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v BuildBranch %nul6%') do set "branch=%%b"
  14986. ​
  14987. ::========================================================================================================================================
  14988. ​
  14989. :: Get target editions list
  14990. ​
  14991. set _target=
  14992. set _dtarget=
  14993. set _ptarget=
  14994. set _ntarget=
  14995. set _wtarget=
  14996. ​
  14997. if %winbuild% GEQ 10240 for /f "tokens=4" %%a in ('dism /online /english /Get-TargetEditions ^| findstr /i /c:"Target Edition : "') do (if defined _dtarget (set "_dtarget= !_dtarget! %%a ") else (set "_dtarget= %%a "))
  14998. if %winbuild% LSS 10240 for /f "tokens=4" %%a in ('%psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':cbsxml\:.*';. ([scriptblock]::Create($f[1])) -GetTargetEditions;" ^| findstr /i /c:"Target Edition : "') do (if defined _ptarget (set "_ptarget= !_ptarget! %%a ") else (set "_ptarget= %%a "))
  14999. ​
  15000. if %winbuild% GEQ 10240 if not exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" (
  15001. if %winbuild% GEQ 17063 call :ced_edilist
  15002. if /i "%osedition:~0,4%"=="Core" set _pro=Professional
  15003. if /i "%osedition%"=="CoreN" set _pro=ProfessionalN
  15004. set "_dtarget= %_dtarget% !_wtarget! !_pro! "
  15005. )
  15006. ​
  15007. ::========================================================================================================================================
  15008. ​
  15009. for %%# in (CloudEdition CloudEditionN ServerRdsh) do if /i %osedition%==%%# (
  15010. cls
  15011. echo:
  15012. call :dk_color %Red% "==== Note ===="
  15013. echo:
  15014. echo [EditionID:%osedition% ^| %fullbuild%]
  15015. echo:
  15016. echo Changing this edition may not remove "%osedition%"-specific features.
  15017. echo:
  15018. call :dk_color %_Yellow% "Press [7] to continue anyway..."
  15019. choice /c 7 /n
  15020. cls
  15021. )
  15022. ​
  15023. for %%# in ( %_dtarget% %_ptarget% ) do if /i not "%%#"=="%osedition%" (
  15024. echo "!_target!" | find /i " %%# " %nul1% || set "_target= !_target! %%# "
  15025. )
  15026. ​
  15027. if defined _target (
  15028. for %%# in (%_target%) do (
  15029. echo %%# | findstr /i "CountrySpecific CloudEdition" %nul% || (set "_ntarget=!_ntarget! %%#")
  15030. )
  15031. )
  15032. ​
  15033. if not defined _ntarget (
  15034. %line%
  15035. echo:
  15036. if defined dismnotworking call :dk_color %Red% "DISM.exe is not working."
  15037. call :dk_color %Gray% "Target editions not found."
  15038. echo Current Edition [%osedition% ^| %winbuild%] can not be changed to any other Edition.
  15039. %line%
  15040. goto dk_done
  15041. )
  15042. ​
  15043. ::========================================================================================================================================
  15044. ​
  15045. :cedmenu2
  15046. ​
  15047. cls
  15048. if not defined terminal mode 98, 30
  15049. set inpt=
  15050. set counter=0
  15051. set verified=0
  15052. set targetedition=
  15053. ​
  15054. %line%
  15055. echo:
  15056. call :dk_color %Gray% "You can change the edition [%osedition%] [%fullbuild%] to one of the following."
  15057. %showeditionerror%
  15058. if defined dismnotworking (
  15059. call :dk_color %_Yellow% "Note - DISM.exe is not working."
  15060. if /i "%osedition:~0,4%"=="Core" call :dk_color %_Yellow% " - You will see more edition options to choose once its changed to Pro."
  15061. )
  15062. %line%
  15063. echo:
  15064. ​
  15065. for %%A in (%_ntarget%) do (
  15066. set /a counter+=1
  15067. if /i %%A==IoTEnterprise (
  15068. echo [!counter!] %%A [GAC, not LTSC]
  15069. ) else (
  15070. echo [!counter!] %%A
  15071. )
  15072. set targetedition!counter!=%%A
  15073. )
  15074. ​
  15075. %line%
  15076. echo:
  15077. echo [0] %_exitmsg%
  15078. echo:
  15079. call :dk_color %_Green% "Enter an option number using your keyboard and press Enter to confirm:"
  15080. set /p inpt=
  15081. if "%inpt%"=="" goto cedmenu2
  15082. if "%inpt%"=="0" exit /b
  15083. for /l %%i in (1,1,%counter%) do (if "%inpt%"=="%%i" set verified=1)
  15084. set targetedition=!targetedition%inpt%!
  15085. if %verified%==0 goto cedmenu2
  15086. ​
  15087. ::========================================================================================================================================
  15088. ​
  15089. if %winbuild% LSS 10240 goto :cbsmethod
  15090. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" goto :ced_change_server
  15091. ​
  15092. cls
  15093. if not defined terminal mode con cols=105 lines=32
  15094. ​
  15095. if /i "%targetedition%"=="ServerRdsh" (
  15096. echo:
  15097. call :dk_color %Red% "==== Note ===="
  15098. echo:
  15099. echo Once the edition is changed to "%targetedition%",
  15100. echo the system may not be able to properly change edition later.
  15101. echo:
  15102. echo [1] Continue Anyway
  15103. echo [0] Go Back
  15104. echo:
  15105. call :dk_color %_Green% "Choose a menu option using your keyboard [1,0] :"
  15106. choice /C:10 /N
  15107. if !errorlevel!==2 goto cedmenu2
  15108. if !errorlevel!==1 rem
  15109. )
  15110. ​
  15111. cls
  15112. set key=
  15113. set _chan=
  15114. set _dismapi=0
  15115. ​
  15116. :: Check if DISM API or slmgr.vbs is required for edition upgrade
  15117. ​
  15118. if not exist "%SysPath%\spp\tokens\skus\%targetedition%\%targetedition%*.xrm-ms" (
  15119. echo %_wtarget% | find /i " %targetedition% " || (
  15120. set _dismapi=1
  15121. )
  15122. )
  15123. ​
  15124. set "keyflow=Retail OEM:NONSLP OEM:DM Volume:MAK Volume:GVLK PGS:TB Retail:TB:Eval"
  15125. ​
  15126. call :ced_targetSKU %targetedition%
  15127. if defined targetSKU call :ced_windowskey
  15128. if defined key if defined pkeychannel set _chan=%pkeychannel%
  15129. if not defined key call :changeeditiondata
  15130. if not defined key if %_dismapi%==1 if /i "%targetedition%"=="Professional" (
  15131. set key=VK7JG-NPHTM-C97JM-9MPGT-3V66T
  15132. set _chan=Retail
  15133. )
  15134. ​
  15135. if not defined key (
  15136. %eline%
  15137. echo [%targetedition% ^| %winbuild%]
  15138. echo Failed to get product key from pkeyhelper.dll.
  15139. set fixes=%fixes% %mas%troubleshoot
  15140. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  15141. goto dk_done
  15142. )
  15143. ​
  15144. ::========================================================================================================================================
  15145. ​
  15146. :: Changing from Core to Non-Core & Changing editions in Windows build older than 17134 requires "changepk /productkey" or DISM Api method and restart
  15147. :: In other cases, editions can be changed instantly with "slmgr /ipk"
  15148. ​
  15149. if %_dismapi%==1 (
  15150. if not defined terminal mode con cols=105 lines=40
  15151. call :ced_rebootflag
  15152. if defined rebootreq goto dk_done
  15153. )
  15154. ​
  15155. cls
  15156. %line%
  15157. echo:
  15158. %showeditionerror%
  15159. if defined dismnotworking call :dk_color %_Yellow% "DISM.exe is not working."
  15160. echo Changing the current edition [%osedition%] %fullbuild% to [%targetedition%]...
  15161. echo:
  15162. ​
  15163. if %_dismapi%==1 (
  15164. call :dk_color %Green% "Notes -"
  15165. echo:
  15166. echo - Save your work before continuing, the system will auto-restart.
  15167. echo:
  15168. echo - You will need to activate with HWID option once the edition is changed.
  15169. %line%
  15170. echo:
  15171. choice /C:21 /N /M "[1] Continue [2] %_exitmsg% : "
  15172. if !errorlevel!==1 exit /b
  15173. )
  15174. ​
  15175. ::========================================================================================================================================
  15176. ​
  15177. if %_dismapi%==0 (
  15178. echo Installing %_chan% key [%key%]
  15179. echo:
  15180. if %_wmic% EQU 1 wmic path %sps% where __CLASS='%sps%' call InstallProductKey ProductKey="%key%" %nul%
  15181. if %_wmic% EQU 0 %psc% "try { $null=(([WMISEARCHER]'SELECT Version FROM %sps%').Get()).InstallProductKey('%key%'); exit 0 } catch { exit $_.Exception.InnerException.HResult }" %nul%
  15182. set keyerror=!errorlevel!
  15183. cmd /c exit /b !keyerror!
  15184. if !keyerror! NEQ 0 set "keyerror=[0x!=ExitCode!]"
  15185. ​
  15186. if !keyerror! EQU 0 (
  15187. call :dk_refresh
  15188. call :dk_color %Green% "[Successful]"
  15189. echo:
  15190. call :dk_color %Gray% "Reboot is required to fully change the edition."
  15191. ) else (
  15192. call :dk_color %Red% "[Unsuccessful] [Error Code: !keyerror!]"
  15193. set fixes=%fixes% %mas%troubleshoot
  15194. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  15195. )
  15196. )
  15197. ​
  15198. if %_dismapi%==1 (
  15199. echo:
  15200. echo Applying the DISM API method with %_chan% key %key%. Please wait...
  15201. echo:
  15202. ​
  15203. call :ced_prep
  15204. if defined preperror goto dk_done
  15205. ​
  15206. %psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':dismapi\:.*';. ([scriptblock]::Create($f[1])) %targetedition% %key%"
  15207. call :ced_postprep
  15208. )
  15209. %line%
  15210. ​
  15211. goto dk_done
  15212. ​
  15213. ::========================================================================================================================================
  15214. ​
  15215. :cbsmethod
  15216. ​
  15217. cls
  15218. if not defined terminal (
  15219. mode con cols=105 lines=32
  15220. %psc% "&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=31;$B.Height=200;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}" %nul%
  15221. )
  15222. ​
  15223. call :ced_rebootflag
  15224. if defined rebootreq goto dk_done
  15225. ​
  15226. echo:
  15227. %showeditionerror%
  15228. if defined dismnotworking call :dk_color %_Yellow% "Note - DISM.exe is not working."
  15229. echo Changing the current edition [%osedition%] %fullbuild% to [%targetedition%]...
  15230. echo:
  15231. call :dk_color %Blue% "Important - Save your work before continuing, the system will auto-restart."
  15232. echo:
  15233. choice /C:01 /N /M "[1] Continue [0] %_exitmsg% : "
  15234. if %errorlevel%==1 exit /b
  15235. ​
  15236. echo:
  15237. echo Initializing...
  15238. echo:
  15239. ​
  15240. call :ced_prep
  15241. if defined preperror goto dk_done
  15242. ​
  15243. if %_stg%==0 (set stage=) else (set stage=-StageCurrent)
  15244. %psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':cbsxml\:.*';. ([scriptblock]::Create($f[1])) -SetEdition %targetedition% %stage%"
  15245. call :ced_postprep
  15246. %line%
  15247. ​
  15248. goto dk_done
  15249. ​
  15250. ::========================================================================================================================================
  15251. ​
  15252. :ced_change_server
  15253. ​
  15254. cls
  15255. if not defined terminal (
  15256. mode con cols=105 lines=32
  15257. %psc% "&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=31;$B.Height=200;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}" %nul%
  15258. )
  15259. ​
  15260. set key=
  15261. set _chan=
  15262. set "keyflow=Volume:GVLK Retail Volume:MAK OEM:NONSLP OEM:DM PGS:TB Retail:TB:Eval"
  15263. ​
  15264. call :ced_targetSKU %targetedition%
  15265. if defined targetSKU call :ced_windowskey
  15266. if defined key if defined pkeychannel set _chan=%pkeychannel%
  15267. if not defined key call :changeeditiondata
  15268. ​
  15269. if not defined key (
  15270. %eline%
  15271. echo [%targetedition% ^| %winbuild%]
  15272. echo Failed to get product key from pkeyhelper.dll.
  15273. set fixes=%fixes% %mas%troubleshoot
  15274. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  15275. goto dk_done
  15276. )
  15277. ​
  15278. call :ced_rebootflag
  15279. if defined rebootreq goto dk_done
  15280. ​
  15281. cls
  15282. echo:
  15283. %showeditionerror%
  15284. if defined dismnotworking call :dk_color %_Yellow% "Note - DISM.exe is not working."
  15285. echo Changing the current edition [%osedition%] %fullbuild% to [%targetedition%]...
  15286. echo:
  15287. ​
  15288. call :ced_prep
  15289. if defined preperror goto dk_done
  15290. ​
  15291. echo Applying the command with %_chan% key...
  15292. echo DISM /online /Set-Edition:%targetedition% /ProductKey:%key% /AcceptEula
  15293. DISM /online /Set-Edition:%targetedition% /ProductKey:%key% /AcceptEula
  15294. ​
  15295. call :ced_postprep
  15296. %line%
  15297. ​
  15298. goto dk_done
  15299. ​
  15300. ::========================================================================================================================================
  15301. ​
  15302. :ced_prep
  15303. ​
  15304. set _time=
  15305. set preperror=
  15306. ​
  15307. for /f %%a in ('%psc% "(Get-Date).ToString('yyyyMMdd-HHmmssfff')"') do set _time=%%a
  15308. ​
  15309. %psc% Stop-Service TrustedInstaller -force %nul%
  15310. ​
  15311. sc query TrustedInstaller | find /i "RUNNING" %nul% && (
  15312. %eline%
  15313. echo Failed to stop the TrustedInstaller service.
  15314. echo Reboot your machine using the restart option and try again.
  15315. set preperror=1
  15316. exit /b
  15317. )
  15318. ​
  15319. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\backup_cbs_%_time%.log" %nul%
  15320. copy /y /b "%SystemRoot%\logs\DISM\dism.log" "%SystemRoot%\logs\DISM\backup_dism_%_time%.log" %nul%
  15321. ​
  15322. del /f /q "%SystemRoot%\logs\cbs\cbs.log" %nul%
  15323. del /f /q "%SystemRoot%\logs\DISM\dism.log" %nul%
  15324. ​
  15325. :: Initiate this to appear in fresh logs
  15326. ​
  15327. dism /online /english /Get-CurrentEdition %nul%
  15328. dism /online /english /Get-TargetEditions %nul%
  15329. exit /b
  15330. ​
  15331. ::========================================================================================================================================
  15332. ​
  15333. :ced_postprep
  15334. ​
  15335. timeout /t 5 %nul1%
  15336. copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\cbs_%_time%.log" %nul%
  15337. copy /y /b "%SystemRoot%\logs\DISM\dism.log" "%SystemRoot%\logs\DISM\dism_%_time%.log" %nul%
  15338. ​
  15339. if not exist "!desktop!\ChangeEdition_Logs\" md "!desktop!\ChangeEdition_Logs\" %nul%
  15340. call :compresslog cbs\cbs_%_time%.log ChangeEdition_Logs\CBS %nul%
  15341. call :compresslog DISM\dism_%_time%.log ChangeEdition_Logs\DISM %nul%
  15342. ​
  15343. echo:
  15344. if %winbuild% GEQ 9200 %psc% "if ((Get-WindowsOptionalFeature -Online -FeatureName NetFx3).State -eq 'Enabled') {Write-Host 'Checking .NET Framework 3.5 Status - Enabled'}"
  15345. echo Log files are copied to the ChangeEdition_Logs folder on your desktop.
  15346. echo:
  15347. call :dk_color %Blue% "In case there are errors, you should restart the system before trying again."
  15348. echo:
  15349. set fixes=%fixes% %mas%change_edition_issues
  15350. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%change_edition_issues"
  15351. exit /b
  15352. ​
  15353. ::========================================================================================================================================
  15354. ​
  15355. :: Get Edition list
  15356. ​
  15357. :ced_edilist
  15358. ​
  15359. if %_wmic% EQU 1 set "chkedi=for /f "tokens=2 delims==" %%a in ('"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL) get LicenseFamily /VALUE" %nul6%')"
  15360. if %_wmic% EQU 0 set "chkedi=for /f "tokens=2 delims==" %%a in ('%psc% "(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}" %nul6%')"
  15361. %chkedi% do call set "_wtarget= !_wtarget! %%a "
  15362. exit /b
  15363. ​
  15364. ::========================================================================================================================================
  15365. ​
  15366. :: Check pending reboot flags
  15367. ​
  15368. :ced_rebootflag
  15369. ​
  15370. set rebootreq=
  15371. reg query "HKLM\Software\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending" %nul% && set rebootreq=1
  15372. reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" %nul% && set rebootreq=1
  15373. ​
  15374. if defined rebootreq (
  15375. %eline%
  15376. echo Pending reboot flags found.
  15377. echo:
  15378. echo Make sure Windows is fully updated, restart the system and try again.
  15379. )
  15380. exit /b
  15381. ​
  15382. ::========================================================================================================================================
  15383. ​
  15384. :ced_windowskey
  15385. ​
  15386. for %%# in (pkeyhelper.dll) do @if "%%~$PATH:#"=="" exit /b
  15387. for %%# in (%keyflow%) do (
  15388. call :k_pkey %targetSKU% '%%#'
  15389. if defined pkey call :k_pkeychannel !pkey!
  15390. if /i "!pkeychannel!"=="%%#" (
  15391. set key=!pkey!
  15392. exit /b
  15393. )
  15394. )
  15395. exit /b
  15396. ​
  15397. ::========================================================================================================================================
  15398. ​
  15399. :ced_targetSKU
  15400. ​
  15401. set k=%1
  15402. set targetSKU=
  15403. for %%# in (pkeyhelper.dll) do @if "%%~$PATH:#"=="" exit /b
  15404. ​
  15405. call :dk_reflection
  15406. ​
  15407. set d1=%ref% [void]$TypeBuilder.DefinePInvokeMethod('GetEditionIdFromName', 'pkeyhelper.dll', 'Public, Static', 1, [int], @([String], [int].MakeByRefType()), 1, 3);
  15408. set d1=%d1% $out = 0; [void]$TypeBuilder.CreateType()::GetEditionIdFromName('%k%', [ref]$out); $out
  15409. ​
  15410. for /f %%a in ('%psc% "%d1%"') do if not errorlevel 1 (set targetSKU=%%a)
  15411. if "%targetSKU%"=="0" set targetSKU=
  15412. exit /b
  15413. ​
  15414. ::========================================================================================================================================
  15415. ​
  15416. :: https://github.com/asdcorp/Set-WindowsCbsEdition
  15417. ​
  15418. :cbsxml:[
  15419. param (
  15420. [Parameter()]
  15421. [String]$SetEdition,
  15422. ​
  15423. [Parameter()]
  15424. [Switch]$GetTargetEditions,
  15425. ​
  15426. [Parameter()]
  15427. [Switch]$StageCurrent
  15428. )
  15429. ​
  15430. function Get-AssemblyIdentity {
  15431. param (
  15432. [String]$PackageName
  15433. )
  15434. ​
  15435. $PackageName = [String]$PackageName
  15436. $packageData = ($PackageName -split '~')
  15437. ​
  15438. if($packageData[3] -eq '') {
  15439. $packageData[3] = 'neutral'
  15440. }
  15441. ​
  15442. return "<assemblyIdentity name=`"$($packageData[0])`" version=`"$($packageData[4])`" processorArchitecture=`"$($packageData[2])`" publicKeyToken=`"$($packageData[1])`" language=`"$($packageData[3])`" />"
  15443. }
  15444. ​
  15445. function Get-SxsName {
  15446. param (
  15447. [String]$PackageName
  15448. )
  15449. ​
  15450. $name = ($PackageName -replace '[^A-z0-9\-\._]', '')
  15451. ​
  15452. if($name.Length -gt 40) {
  15453. $name = ($name[0..18] -join '') + '\.\.' + ($name[-19..-1] -join '')
  15454. }
  15455. ​
  15456. return $name.ToLower()
  15457. }
  15458. ​
  15459. function Find-EditionXmlInSxs {
  15460. param (
  15461. [String]$Edition
  15462. )
  15463. ​
  15464. $candidates = @($Edition, 'Client', 'Server')
  15465. $winSxs = $Env:SystemRoot + '\WinSxS'
  15466. $allInSxs = Get-ChildItem -Path $winSxs | select Name
  15467. ​
  15468. foreach($candidate in $candidates) {
  15469. $name = Get-SxsName -PackageName "Microsoft-Windows-Editions-$candidate"
  15470. $packages = $allInSxs | where name -Match ('^.*_'+$name+'_31bf3856ad364e35')
  15471. ​
  15472. if($packages.Length -eq 0) {
  15473. continue
  15474. }
  15475. ​
  15476. $package = $packages[-1].Name
  15477. $testPath = $winSxs + "\$package\" + $Edition + 'Edition.xml'
  15478. ​
  15479. if(Test-Path -Path $testPath -PathType Leaf) {
  15480. return $testPath
  15481. }
  15482. }
  15483. ​
  15484. return $null
  15485. }
  15486. ​
  15487. function Find-EditionXml {
  15488. param (
  15489. [String]$Edition
  15490. )
  15491. ​
  15492. $servicingEditions = $Env:SystemRoot + '\servicing\Editions'
  15493. $editionXml = $Edition + 'Edition.xml'
  15494. ​
  15495. $editionXmlInServicing = $servicingEditions + '\' + $editionXml
  15496. ​
  15497. if(Test-Path -Path $editionXmlInServicing -PathType Leaf) {
  15498. return $editionXmlInServicing
  15499. }
  15500. ​
  15501. return Find-EditionXmlInSxs -Edition $Edition
  15502. }
  15503. ​
  15504. function Write-UpgradeCandidates {
  15505. param (
  15506. [HashTable]$InstallCandidates
  15507. )
  15508. ​
  15509. $editionCount = 0
  15510. Write-Host 'Editions that can be upgraded to:'
  15511. foreach($candidate in $InstallCandidates.Keys) {
  15512. Write-Host "Target Edition : $candidate"
  15513. $editionCount++
  15514. }
  15515. ​
  15516. if($editionCount -eq 0) {
  15517. Write-Host '(no editions are available)'
  15518. }
  15519. }
  15520. ​
  15521. function Write-UpgradeXml {
  15522. param (
  15523. [Array]$RemovalCandidates,
  15524. [Array]$InstallCandidates,
  15525. [Boolean]$Stage
  15526. )
  15527. ​
  15528. $removeAction = 'remove'
  15529. if($Stage) {
  15530. $removeAction = 'stage'
  15531. }
  15532. ​
  15533. Write-Output '<?xml version="1.0"?>'
  15534. Write-Output '<unattend xmlns="urn:schemas-microsoft-com:unattend">'
  15535. Write-Output '<servicing>'
  15536. ​
  15537. foreach($package in $InstallCandidates) {
  15538. Write-Output '<package action="install">'
  15539. Write-Output (Get-AssemblyIdentity -PackageName $package)
  15540. Write-Output '</package>'
  15541. }
  15542. ​
  15543. foreach($package in $RemovalCandidates) {
  15544. Write-Output "<package action=`"$removeAction`">"
  15545. Write-Output (Get-AssemblyIdentity -PackageName $package)
  15546. Write-Output '</package>'
  15547. }
  15548. ​
  15549. Write-Output '</servicing>'
  15550. Write-Output '</unattend>'
  15551. }
  15552. ​
  15553. function Write-Usage {
  15554. Get-Help $script:MyInvocation.MyCommand.Path -detailed
  15555. }
  15556. ​
  15557. $version = '1.0'
  15558. $getTargetsParam = $GetTargetEditions.IsPresent
  15559. $stageCurrentParam = $StageCurrent.IsPresent
  15560. ​
  15561. if($SetEdition -eq '' -and ($false -eq $getTargetsParam)) {
  15562. Write-Usage
  15563. Exit 1
  15564. }
  15565. ​
  15566. $removalCandidates = @();
  15567. $installCandidates = @{};
  15568. ​
  15569. $packages = Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages' | select Name | where { $_.name -match '^.*\\Microsoft-Windows-.*Edition~' }
  15570. foreach($package in $packages) {
  15571. $state = (Get-ItemProperty -Path "Registry::$($package.Name)").CurrentState
  15572. $packageName = ($package.Name -split '\\')[-1]
  15573. $packageEdition = (($packageName -split 'Edition~')[0] -split 'Microsoft-Windows-')[-1]
  15574. ​
  15575. if($state -eq 0x40) {
  15576. if($null -eq $installCandidates[$packageEdition]) {
  15577. $installCandidates[$packageEdition] = @()
  15578. }
  15579. ​
  15580. if($false -eq ($installCandidates[$packageEdition] -contains $packageName)) {
  15581. $installCandidates[$packageEdition] = $installCandidates[$packageEdition] + @($packageName)
  15582. }
  15583. }
  15584. ​
  15585. if((($state -eq 0x50) -or ($state -eq 0x70)) -and ($false -eq ($removalCandidates -contains $packageName))) {
  15586. $removalCandidates = $removalCandidates + @($packageName)
  15587. }
  15588. }
  15589. ​
  15590. if($getTargetsParam) {
  15591. Write-UpgradeCandidates -InstallCandidates $installCandidates
  15592. Exit
  15593. }
  15594. ​
  15595. if($false -eq ($installCandidates.Keys -contains $SetEdition)) {
  15596. Write-Error "The system cannot be upgraded to `"$SetEdition`""
  15597. Exit 1
  15598. }
  15599. ​
  15600. $xmlPath = $Env:SystemRoot + '\Temp' + '\CbsUpgrade.xml'
  15601. ​
  15602. Write-UpgradeXml -RemovalCandidates $removalCandidates `
  15603. -InstallCandidates $installCandidates[$SetEdition] `
  15604. -Stage $stageCurrentParam >$xmlPath
  15605. ​
  15606. $editionXml = Find-EditionXml -Edition $SetEdition
  15607. if($null -eq $editionXml) {
  15608. Write-Warning 'Unable to find edition specific settings XML. Proceeding without it...'
  15609. }
  15610. ​
  15611. Write-Host 'Starting the upgrade process. This may take a while...'
  15612. ​
  15613. DISM.EXE /English /NoRestart /Online /Apply-Unattend:$xmlPath
  15614. $dismError = $LASTEXITCODE
  15615. ​
  15616. Remove-Item -Path $xmlPath -Force
  15617. ​
  15618. if(($dismError -ne 0) -and ($dismError -ne 3010)) {
  15619. Write-Error 'Failed to upgrade to the target edition'
  15620. Exit $dismError
  15621. }
  15622. ​
  15623. if($null -ne $editionXml) {
  15624. $destination = $Env:SystemRoot + '\' + $SetEdition + '.xml'
  15625. Copy-Item -Path $editionXml -Destination $destination
  15626. ​
  15627. DISM.EXE /English /NoRestart /Online /Apply-Unattend:$editionXml
  15628. $dismError = $LASTEXITCODE
  15629. ​
  15630. if(($dismError -ne 0) -and ($dismError -ne 3010)) {
  15631. Write-Error 'Failed to apply edition specific settings'
  15632. Exit $dismError
  15633. }
  15634. }
  15635. ​
  15636. Restart-Computer
  15637. :cbsxml:]
  15638. ​
  15639. ::========================================================================================================================================
  15640. ​
  15641. :: Change edition using DISM API
  15642. :: Thanks to Alex (aka may, ave9858)
  15643. ​
  15644. :dismapi:[
  15645. param (
  15646. [Parameter()]
  15647. [String]$TargetEdition,
  15648. ​
  15649. [Parameter()]
  15650. [String]$Key
  15651. )
  15652. ​
  15653. $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)
  15654. $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)
  15655. $TB = $ModuleBuilder.DefineType(0)
  15656. ​
  15657. [void]$TB.DefinePInvokeMethod('DismInitialize', 'DismApi.dll', 22, 1, [int], @([int], [IntPtr], [IntPtr]), 1, 3)
  15658. [void]$TB.DefinePInvokeMethod('DismOpenSession', 'DismApi.dll', 22, 1, [int], @([String], [IntPtr], [IntPtr], [UInt32].MakeByRefType()), 1, 3)
  15659. [void]$TB.DefinePInvokeMethod('_DismSetEdition', 'DismApi.dll', 22, 1, [int], @([UInt32], [String], [String], [IntPtr], [IntPtr], [IntPtr]), 1, 3)
  15660. $Dism = $TB.CreateType()
  15661. ​
  15662. [void]$Dism::DismInitialize(2, 0, 0)
  15663. $Session = 0
  15664. [void]$Dism::DismOpenSession('DISM_{53BFAE52-B167-4E2F-A258-0A37B57FF845}', 0, 0, [ref]$Session)
  15665. if (!$Dism::_DismSetEdition($Session, "$TargetEdition", "$Key", 0, 0, 0)) {
  15666. Restart-Computer
  15667. }
  15668. :dismapi:]
  15669. ​
  15670. ::========================================================================================================================================
  15671. ​
  15672. :: 1st column = Generic Retail/OEM/MAK/GVLK Key
  15673. :: 2nd column = Key Type
  15674. :: 3rd column = WMI Edition ID
  15675. :: 4th column = Version name incase same Edition ID is used in different OS versions with different key
  15676. :: Separator = _
  15677. ​
  15678. :: For Windows 10/11 editions, HWID key is listed where ever possible, in Server versions, KMS key is listed where ever possible.
  15679. :: For Windows, generic keys are mentioned till 22000 and for Server, generic keys are mentioned till 17763, later ones are extracted from the pkeyhelper.dll
  15680. ​
  15681. :changeeditiondata
  15682. ​
  15683. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" (
  15684. if %winbuild% GTR 17763 exit /b
  15685. ) else (
  15686. if %winbuild% GEQ 22000 exit /b
  15687. )
  15688. if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*CorEdition~*.mum" (set Cor=Cor) else (set Cor=)
  15689. ​
  15690. set w=
  15691. for %%# in (
  15692. XGVPP-NMH47-7TTHJ-W3FW7-8HV%w%2C__OEM:NONSLP_Enterprise
  15693. D6RD9-D4N8T-RT9QX-YW6YT-FCW%w%WJ______Retail_Starter
  15694. 3V6Q6-NQXCX-V8YXR-9QCYV-QPF%w%CT__Volume:MAK_EnterpriseN
  15695. 3NFXW-2T27M-2BDW6-4GHRV-68X%w%RX______Retail_StarterN
  15696. VK7JG-NPHTM-C97JM-9MPGT-3V6%w%6T______Retail_Professional
  15697. 2B87N-8KFHP-DKV6R-Y2C8J-PKC%w%KT______Retail_ProfessionalN
  15698. 4CPRK-NM3K3-X6XXQ-RXX86-WXC%w%HW______Retail_CoreN
  15699. N2434-X9D7W-8PF6X-8DV9T-8TY%w%MD______Retail_CoreCountrySpecific
  15700. BT79Q-G7N6G-PGBYW-4YWX6-6F4%w%BT______Retail_CoreSingleLanguage
  15701. YTMG3-N6DKC-DKB77-7M9GH-8HV%w%X7______Retail_Core
  15702. XKCNC-J26Q9-KFHD2-FKTHY-KD7%w%2Y__OEM:NONSLP_PPIPro
  15703. YNMGQ-8RYV3-4PGQ3-C8XTP-7CF%w%BY______Retail_Education
  15704. 84NGF-MHBT6-FXBX8-QWJK7-DRR%w%8H______Retail_EducationN
  15705. KCNVH-YKWX8-GJJB9-H9FDT-6F7%w%W2__Volume:MAK_EnterpriseS_VB
  15706. 43TBQ-NH92J-XKTM7-KT3KK-P39%w%PB__OEM:NONSLP_EnterpriseS_RS5
  15707. NK96Y-D9CD8-W44CQ-R8YTK-DYJ%w%WX__OEM:NONSLP_EnterpriseS_RS1
  15708. FWN7H-PF93Q-4GGP8-M8RF3-MDW%w%WW__OEM:NONSLP_EnterpriseS_TH
  15709. RQFNW-9TPM3-JQ73T-QV4VQ-DV9%w%PT__Volume:MAK_EnterpriseSN_VB
  15710. M33WV-NHY3C-R7FPM-BQGPT-239%w%PG__Volume:MAK_EnterpriseSN_RS5
  15711. 2DBW3-N2PJG-MVHW3-G7TDK-9HK%w%R4__Volume:MAK_EnterpriseSN_RS1
  15712. NTX6B-BRYC2-K6786-F6MVQ-M7V%w%2X__Volume:MAK_EnterpriseSN_TH
  15713. G3KNM-CHG6T-R36X3-9QDG6-8M8%w%K9______Retail_ProfessionalSingleLanguage
  15714. HNGCC-Y38KG-QVK8D-WMWRK-X86%w%VK______Retail_ProfessionalCountrySpecific
  15715. DXG7C-N36C4-C4HTG-X4T3X-2YV%w%77______Retail_ProfessionalWorkstation
  15716. WYPNQ-8C467-V2W6J-TX4WX-WT2%w%RQ______Retail_ProfessionalWorkstationN
  15717. 8PTT6-RNW4C-6V7J2-C2D3X-MHB%w%PB______Retail_ProfessionalEducation
  15718. GJTYN-HDMQY-FRR76-HVGC7-QPF%w%8P______Retail_ProfessionalEducationN
  15719. C4NTJ-CX6Q2-VXDMR-XVKGM-F9D%w%JC__Volume:MAK_EnterpriseG
  15720. 46PN6-R9BK9-CVHKB-HWQ9V-MBJ%w%Y8__Volume:MAK_EnterpriseGN
  15721. NJCF7-PW8QT-3324D-688JX-2YV%w%66______Retail_ServerRdsh
  15722. XQQYW-NFFMW-XJPBH-K8732-CKF%w%FD______OEM:DM_IoTEnterprise
  15723. QPM6N-7J2WJ-P88HH-P3YRH-YY7%w%4H__OEM:NONSLP_IoTEnterpriseS
  15724. K9VKN-3BGWV-Y624W-MCRMQ-BHD%w%CD______Retail_CloudEditionN
  15725. KY7PN-VR6RX-83W6Y-6DDYQ-T6R%w%4W______Retail_CloudEdition
  15726. V3WVW-N2PV2-CGWC3-34QGF-VMJ%w%2C______Retail_Cloud
  15727. NH9J3-68WK7-6FB93-4K3DF-DJ4%w%F6______Retail_CloudN
  15728. 2HN6V-HGTM8-6C97C-RK67V-JQP%w%FD______Retail_CloudE
  15729. WC2BQ-8NRM3-FDDYY-2BFGV-KHK%w%QY_Volume:GVLK_ServerStandard%Cor%_RS1
  15730. CB7KF-BWN84-R7R2Y-793K2-8XD%w%DG_Volume:GVLK_ServerDatacenter%Cor%_RS1
  15731. JCKRF-N37P4-C2D82-9YXRT-4M6%w%3B_Volume:GVLK_ServerSolution_RS1
  15732. QN4C6-GBJD2-FB422-GHWJK-GJG%w%2R_Volume:GVLK_ServerCloudStorage_RS1
  15733. VP34G-4NPPG-79JTQ-864T4-R3M%w%QX_Volume:GVLK_ServerAzureCor_RS1
  15734. 9JQNQ-V8HQ6-PKB8H-GGHRY-R62%w%H6______Retail_ServerAzureNano_RS1
  15735. VN8D3-PR82H-DB6BJ-J9P4M-92F%w%6J______Retail_ServerStorageStandard_RS1
  15736. 48TQX-NVK3R-D8QR3-GTHHM-8FH%w%XC______Retail_ServerStorageWorkgroup_RS1
  15737. 2HXDN-KRXHB-GPYC7-YCKFJ-7FV%w%DG_Volume:GVLK_ServerDatacenterACor_RS3
  15738. PTXN8-JFHJM-4WC78-MPCBR-9W4%w%KR_Volume:GVLK_ServerStandardACor_RS3
  15739. ) do (
  15740. for /f "tokens=1-4 delims=_" %%A in ("%%#") do if /i %targetedition%==%%C (
  15741. ​
  15742. if not defined key (
  15743. set 4th=%%D
  15744. if not defined 4th (
  15745. set "key=%%A" & set "_chan=%%B"
  15746. ) else (
  15747. echo "%branch%" | find /i "%%D" %nul1% && (set "key=%%A" & set "_chan=%%B")
  15748. )
  15749. )
  15750. )
  15751. )
  15752. exit /b
  15753. ​
  15754. :+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  15755. ​
  15756. :change_offedition
  15757. ​
  15758. set "line=echo ___________________________________________________________________________________________"
  15759. ​
  15760. cls
  15761. if not defined terminal mode 98, 30
  15762. title Change Office Edition %masver%
  15763. ​
  15764. if %winbuild% LSS 7600 (
  15765. %eline%
  15766. echo Unsupported OS version detected [%winbuild%].
  15767. echo This option is supported only for Windows 7/8/8.1/10/11 and their Server equivalents.
  15768. goto dk_done
  15769. )
  15770. ​
  15771. echo:
  15772. echo Initializing...
  15773. echo:
  15774. ​
  15775. ::========================================================================================================================================
  15776. ​
  15777. set spp=SoftwareLicensingProduct
  15778. set sps=SoftwareLicensingService
  15779. ​
  15780. call :dk_reflection
  15781. call :dk_ckeckwmic
  15782. call :dk_sppissue
  15783. ​
  15784. for /f "tokens=6-7 delims=[]. " %%i in ('ver') do if not "%%j"=="" (
  15785. set fullbuild=%%i.%%j
  15786. ) else (
  15787. for /f "tokens=3" %%G in ('"reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v UBR" %nul6%') do if not errorlevel 1 set /a "UBR=%%G"
  15788. for /f "skip=2 tokens=3,4 delims=. " %%G in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v BuildLabEx') do (
  15789. if defined UBR (set "fullbuild=%%G.!UBR!") else (set "fullbuild=%%G.%%H")
  15790. )
  15791. )
  15792. ​
  15793. ::========================================================================================================================================
  15794. ​
  15795. :: Check Windows Edition
  15796. :: This is just to ensure that SPP/WMI are functional
  15797. ​
  15798. cls
  15799. set osedition=0
  15800. if %_wmic% EQU 1 set "chkedi=for /f "tokens=2 delims==" %%a in ('"wmic path %spp% where (ApplicationID='55c92734-d682-4d71-983e-d6ec3f16059f' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL) get LicenseFamily /VALUE" %nul6%')"
  15801. if %_wmic% EQU 0 set "chkedi=for /f "tokens=2 delims==" %%a in ('%psc% "(([WMISEARCHER]'SELECT LicenseFamily FROM %spp% WHERE ApplicationID=''55c92734-d682-4d71-983e-d6ec3f16059f'' AND LicenseDependsOn is NULL AND PartialProductKey IS NOT NULL').Get()).LicenseFamily ^| %% {echo ('LicenseFamily='+$_)}" %nul6%')"
  15802. %chkedi% do if not errorlevel 1 (call set "osedition=%%a")
  15803. ​
  15804. if %osedition%==0 (
  15805. %eline%
  15806. echo Failed to detect OS Edition. Aborting...
  15807. call :dk_color %Blue% "To fix this issue, activate Windows from the main menu."
  15808. goto dk_done
  15809. )
  15810. ​
  15811. ::========================================================================================================================================
  15812. ​
  15813. :: Check installed Office 16.0 C2R
  15814. ​
  15815. set o16c2r=
  15816. set _68=HKLM\SOFTWARE\Microsoft\Office
  15817. set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office
  15818. ​
  15819. for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\ClickToRun /v InstallPath" %nul6%') do if exist "%%b\root\Licenses16\ProPlus*.xrm-ms" (set o16c2r=1&set o16c2r_reg=%_86%\ClickToRun)
  15820. for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\ClickToRun /v InstallPath" %nul6%') do if exist "%%b\root\Licenses16\ProPlus*.xrm-ms" (set o16c2r=1&set o16c2r_reg=%_68%\ClickToRun)
  15821. ​
  15822. if not defined o16c2r_reg (
  15823. %eline%
  15824. echo Office C2R 2016 or later is not installed, which is required for this script.
  15825. echo Download and install Office from below URL and try again.
  15826. set fixes=%fixes% %mas%genuine-installation-media
  15827. call :dk_color %_Yellow% "%mas%genuine-installation-media"
  15828. goto dk_done
  15829. )
  15830. ​
  15831. call :ch_getinfo
  15832. ​
  15833. ::========================================================================================================================================
  15834. ​
  15835. :: Check minimum required details
  15836. ​
  15837. if %verchk% LSS 9029 (
  15838. %eline%
  15839. echo Installed Office version is %_version%.
  15840. echo Minimum required version is 16.0.9029.2167
  15841. echo Aborting...
  15842. call :dk_color %Blue% "Download and install latest Office from below URL and try again."
  15843. set fixes=%fixes% %mas%genuine-installation-media
  15844. call :dk_color %_Yellow% "%mas%genuine-installation-media"
  15845. goto dk_done
  15846. )
  15847. ​
  15848. for %%A in (
  15849. _oArch
  15850. _updch
  15851. _lang
  15852. _clversion
  15853. _version
  15854. _AudienceData
  15855. _oIds
  15856. _c2rXml
  15857. _c2rExe
  15858. _c2rCexe
  15859. _masterxml
  15860. ) do (
  15861. if not defined %%A (
  15862. %eline%
  15863. echo Failed to find %%A. Aborting...
  15864. call :dk_color %Blue% "Download and install Office from below URL and try again."
  15865. set fixes=%fixes% %mas%genuine-installation-media
  15866. call :dk_color %_Yellow% "%mas%genuine-installation-media"
  15867. goto dk_done
  15868. )
  15869. )
  15870. ​
  15871. if %winbuild% LSS 10240 if defined ltscfound (
  15872. %eline%
  15873. echo Installed Office appears to be from the Volume channel %ltsc19%%ltsc21%%ltsc24%,
  15874. echo which is not officially supported on your Windows build version %winbuild%.
  15875. echo Aborting...
  15876. set fixes=%fixes% %mas%troubleshoot
  15877. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  15878. goto dk_done
  15879. )
  15880. ​
  15881. set unsupbuild=
  15882. if %winbuild% LSS 10240 if %winbuild% GEQ 9200 if %verchk% GTR 16026 set unsupbuild=1
  15883. if %winbuild% LSS 9200 if %verchk% GTR 12527 set unsupbuild=1
  15884. ​
  15885. if defined unsupbuild (
  15886. %eline%
  15887. echo Unsupported Office %verchk% is installed on your Windows build version %winbuild%.
  15888. echo Aborting...
  15889. set fixes=%fixes% %mas%troubleshoot
  15890. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  15891. goto dk_done
  15892. )
  15893. ​
  15894. ::========================================================================================================================================
  15895. ​
  15896. :oemenu
  15897. ​
  15898. cls
  15899. set fixes=
  15900. if not defined terminal mode 76, 25
  15901. title Change Office Edition %masver%
  15902. echo:
  15903. echo:
  15904. echo:
  15905. echo:
  15906. echo ____________________________________________________________
  15907. echo:
  15908. echo [1] Change all editions
  15909. echo [2] Add edition
  15910. echo [3] Remove edition
  15911. echo:
  15912. echo [4] Add/Remove apps
  15913. echo ____________________________________________
  15914. echo:
  15915. echo [5] Change Office Update Channel
  15916. echo [0] %_exitmsg%
  15917. echo ____________________________________________________________
  15918. echo:
  15919. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard [1,2,3,4,5,0]"
  15920. choice /C:123450 /N
  15921. set _el=!errorlevel!
  15922. if !_el!==6 exit /b
  15923. if !_el!==5 goto :oe_changeupdchnl
  15924. if !_el!==4 goto :oe_editedition
  15925. if !_el!==3 goto :oe_removeedition
  15926. if !_el!==2 set change=0& goto :oe_edition
  15927. if !_el!==1 set change=1& goto :oe_edition
  15928. goto :oemenu
  15929. ​
  15930. ::========================================================================================================================================
  15931. ​
  15932. :oe_edition
  15933. ​
  15934. cls
  15935. call :oe_chkinternet
  15936. if not defined _int (
  15937. goto :oe_goback
  15938. )
  15939. ​
  15940. cls
  15941. if not defined terminal mode 76, 25
  15942. if %change%==1 (
  15943. title Change all editions %masver%
  15944. ) else (
  15945. title Add edition %masver%
  15946. )
  15947. ​
  15948. echo:
  15949. echo:
  15950. echo:
  15951. echo:
  15952. echo O365/Mondo editions have the latest features.
  15953. echo ____________________________________________________________
  15954. echo:
  15955. echo [1] Office Suites - Retail
  15956. echo [2] Office Suites - Volume
  15957. echo [3] Office SingleApps - Retail
  15958. echo [4] Office SingleApps - Volume
  15959. echo ____________________________________________
  15960. echo:
  15961. echo [0] Go Back
  15962. echo ____________________________________________________________
  15963. echo:
  15964. call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard [1,2,3,4,0]"
  15965. choice /C:12340 /N
  15966. set _el=!errorlevel!
  15967. if !_el!==5 goto :oemenu
  15968. if !_el!==4 set list=SingleApps_Volume&goto :oe_editionchangepre
  15969. if !_el!==3 set list=SingleApps_Retail&goto :oe_editionchangepre
  15970. if !_el!==2 set list=Suites_Volume&goto :oe_editionchangepre
  15971. if !_el!==1 set list=Suites_Retail&goto :oe_editionchangepre
  15972. goto :oe_edition
  15973. ​
  15974. ::========================================================================================================================================
  15975. ​
  15976. :oe_editionchangepre
  15977. ​
  15978. cls
  15979. set editedition=
  15980. call :ch_getinfo
  15981. call :oe_tempcleanup
  15982. %psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':getlist\:.*';. ([scriptblock]::Create($f[1]))"
  15983. ​
  15984. :oe_editionchange
  15985. ​
  15986. cls
  15987. if not defined terminal (
  15988. mode 98, 45
  15989. %psc% "&{$W=$Host.UI.RawUI.WindowSize;$B=$Host.UI.RawUI.BufferSize;$W.Height=44;$B.Height=100;$Host.UI.RawUI.WindowSize=$W;$Host.UI.RawUI.BufferSize=$B;}" %nul%
  15990. )
  15991. ​
  15992. if not exist %SystemRoot%\Temp\%list%.txt (
  15993. %eline%
  15994. echo Failed to generate available editions list.
  15995. set fixes=%fixes% %mas%troubleshoot
  15996. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  15997. goto :oe_goback
  15998. )
  15999. ​
  16000. set inpt=
  16001. set counter=0
  16002. set verified=0
  16003. set _notfound=
  16004. set targetedition=
  16005. ​
  16006. %line%
  16007. echo:
  16008. call :dk_color %Gray% "Installed Office editions: %_oIds%"
  16009. call :dk_color %Gray% "You can select one of the following Office Editions."
  16010. if %winbuild% LSS 10240 (
  16011. echo Unsupported products such as 2019/2021/2024 are excluded from this list.
  16012. ) else (
  16013. for %%# in (2019 2021 2024) do (
  16014. find /i "%%#" "%SystemRoot%\Temp\%list%.txt" %nul1% || (
  16015. if defined _notfound (set _notfound=%%#, !_notfound!) else (set _notfound=%%#)
  16016. )
  16017. )
  16018. if defined _notfound call :dk_color %Gray% "Office !_notfound! is not in this list because old version [%_version%] of Office is installed."
  16019. )
  16020. %line%
  16021. echo:
  16022. ​
  16023. for /f "usebackq delims=" %%A in (%SystemRoot%\Temp\%list%.txt) do (
  16024. set /a counter+=1
  16025. if !counter! LSS 10 (
  16026. echo [!counter!] %%A
  16027. ) else (
  16028. echo [!counter!] %%A
  16029. )
  16030. set targetedition!counter!=%%A
  16031. )
  16032. ​
  16033. %line%
  16034. echo:
  16035. echo [0] Go Back
  16036. echo:
  16037. call :dk_color %_Green% "Enter an option number using your keyboard and press Enter to confirm:"
  16038. set /p inpt=
  16039. if "%inpt%"=="" goto :oe_editionchange
  16040. if "%inpt%"=="0" (call :oe_tempcleanup & goto :oe_edition)
  16041. for /l %%i in (1,1,%counter%) do (if "%inpt%"=="%%i" set verified=1)
  16042. set targetedition=!targetedition%inpt%!
  16043. if %verified%==0 goto :oe_editionchange
  16044. ​
  16045. ::========================================================================================================================================
  16046. ​
  16047. :: Set app exclusions
  16048. ​
  16049. :oe_excludeappspre
  16050. ​
  16051. cls
  16052. set suites=
  16053. echo %list% | find /i "Suites" %nul1% && (
  16054. set suites=1
  16055. %psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':getappnames\:.*';. ([scriptblock]::Create($f[1]))"
  16056. if not exist %SystemRoot%\Temp\getAppIds.txt (
  16057. %eline%
  16058. echo Failed to generate available apps list.
  16059. set fixes=%fixes% %mas%troubleshoot
  16060. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  16061. goto :oe_goback
  16062. )
  16063. )
  16064. ​
  16065. for %%# in (
  16066. Access
  16067. Excel
  16068. Lync
  16069. OneNote
  16070. Outlook
  16071. PowerPoint
  16072. Project
  16073. Publisher
  16074. Visio
  16075. Word
  16076. ) do (
  16077. if defined suites (
  16078. find /i "%%#" "%SystemRoot%\Temp\getAppIds.txt" %nul1% && (set %%#_st=On) || (set %%#_st=)
  16079. ) else (
  16080. set %%#_st=
  16081. )
  16082. )
  16083. ​
  16084. if defined Lync_st set Lync_st=Off
  16085. set OneDrive_st=Off
  16086. if defined suites (set Teams_st=Off) else (set Teams_st=)
  16087. ​
  16088. :oe_excludeapps
  16089. ​
  16090. cls
  16091. if not defined terminal mode 98, 32
  16092. ​
  16093. %line%
  16094. echo:
  16095. call :dk_color %Gray% "Target edition: %targetedition%"
  16096. call :dk_color %Gray% "To exclude the apps listed below from installation, toggle them from On to Off."
  16097. if defined editedition call :dk_color %Gray% "Note: The On/Off status below does not reflect the current status of the installed apps."
  16098. %line%
  16099. if defined suites echo:
  16100. if defined Access_st echo [A] Access : %Access_st%
  16101. if defined Excel_st echo [E] Excel : %Excel_st%
  16102. if defined OneNote_st echo [N] OneNote : %OneNote_st%
  16103. if defined Outlook_st echo [O] Outlook : %Outlook_st%
  16104. if defined PowerPoint_st echo [P] PowerPoint : %PowerPoint_st%
  16105. if defined Project_st echo [J] Project : %Project_st%
  16106. if defined Publisher_st echo [R] Publisher : %Publisher_st%
  16107. if defined Visio_st echo [V] Visio : %Visio_st%
  16108. if defined Word_st echo [W] Word : %Word_st%
  16109. echo:
  16110. if defined Lync_st echo [L] SkypeForBusiness : %Lync_st%
  16111. if defined OneDrive_st echo [D] OneDrive : %OneDrive_st%
  16112. if defined Teams_st echo [T] Teams : %Teams_st%
  16113. %line%
  16114. echo:
  16115. echo [1] Continue
  16116. echo [0] Go Back
  16117. %line%
  16118. echo:
  16119. call :dk_color %_Green% "Choose a menu option using your keyboard:"
  16120. choice /C:AENOPJRVWLDT10 /N
  16121. set _el=!errorlevel!
  16122. if !_el!==14 goto :oemenu
  16123. if !_el!==13 call :excludelist & goto :oe_editionchangefinal
  16124. if !_el!==12 if defined Teams_st (if "%Teams_st%"=="Off" (set Teams_st=ON) else (set Teams_st=Off))
  16125. if !_el!==11 if defined OneDrive_st (if "%OneDrive_st%"=="Off" (set OneDrive_st=ON) else (set OneDrive_st=Off))
  16126. if !_el!==10 if defined Lync_st (if "%Lync_st%"=="Off" (set Lync_st=ON) else (set Lync_st=Off))
  16127. if !_el!==9 if defined Word_st (if "%Word_st%"=="Off" (set Word_st=ON) else (set Word_st=Off))
  16128. if !_el!==8 if defined Visio_st (if "%Visio_st%"=="Off" (set Visio_st=ON) else (set Visio_st=Off))
  16129. if !_el!==7 if defined Publisher_st (if "%Publisher_st%"=="Off" (set Publisher_st=ON) else (set Publisher_st=Off))
  16130. if !_el!==6 if defined Project_st (if "%Project_st%"=="Off" (set Project_st=ON) else (set Project_st=Off))
  16131. if !_el!==5 if defined PowerPoint_st (if "%PowerPoint_st%"=="Off" (set PowerPoint_st=ON) else (set PowerPoint_st=Off))
  16132. if !_el!==4 if defined Outlook_st (if "%Outlook_st%"=="Off" (set Outlook_st=ON) else (set Outlook_st=Off))
  16133. if !_el!==3 if defined OneNote_st (if "%OneNote_st%"=="Off" (set OneNote_st=ON) else (set OneNote_st=Off))
  16134. if !_el!==2 if defined Excel_st (if "%Excel_st%"=="Off" (set Excel_st=ON) else (set Excel_st=Off))
  16135. if !_el!==1 if defined Access_st (if "%Access_st%"=="Off" (set Access_st=ON) else (set Access_st=Off))
  16136. goto :oe_excludeapps
  16137. ​
  16138. :excludelist
  16139. ​
  16140. set excludelist=
  16141. for %%# in (
  16142. access
  16143. excel
  16144. onenote
  16145. outlook
  16146. powerpoint
  16147. project
  16148. publisher
  16149. visio
  16150. word
  16151. lync
  16152. onedrive
  16153. teams
  16154. ) do (
  16155. if /i "!%%#_st!"=="Off" if defined excludelist (set excludelist=!excludelist!,%%#) else (set excludelist=,%%#)
  16156. )
  16157. exit /b
  16158. ​
  16159. ::========================================================================================================================================
  16160. ​
  16161. :: Final command to change/add edition
  16162. ​
  16163. :oe_editionchangefinal
  16164. ​
  16165. cls
  16166. if not defined terminal mode 105, 32
  16167. ​
  16168. :: Check for Project and Visio with unsupported language
  16169. ​
  16170. set projvis=
  16171. set langmatched=
  16172. echo: %Project_st% %Visio_st% | find /i "ON" %nul% && set projvis=1
  16173. echo: %targetedition% | findstr /i "Project Visio" %nul% && set projvis=1
  16174. ​
  16175. if defined projvis (
  16176. for %%# in (
  16177. ar-sa
  16178. cs-cz
  16179. da-dk
  16180. de-de
  16181. el-gr
  16182. en-us
  16183. es-es
  16184. fi-fi
  16185. fr-fr
  16186. he-il
  16187. hu-hu
  16188. it-it
  16189. ja-jp
  16190. ko-kr
  16191. nb-no
  16192. nl-nl
  16193. pl-pl
  16194. pt-br
  16195. pt-pt
  16196. ro-ro
  16197. ru-ru
  16198. sk-sk
  16199. sl-si
  16200. sv-se
  16201. tr-tr
  16202. uk-ua
  16203. zh-cn
  16204. zh-tw
  16205. ) do (
  16206. if /i "%_lang%"=="%%#" set langmatched=1
  16207. )
  16208. if not defined langmatched (
  16209. %eline%
  16210. echo %_lang% language is not available for Project/Visio apps.
  16211. call :dk_color %Blue% "Install Office in the supported language for Project/Visio from the below URL."
  16212. set fixes=%fixes% %mas%genuine-installation-media
  16213. call :dk_color %_Yellow% "%mas%genuine-installation-media"
  16214. goto :oe_goback
  16215. )
  16216. )
  16217. ​
  16218. :: Thanks to @abbodi1406 for first discovering OfficeClickToRun.exe uses
  16219. :: Thanks to @may for the suggestion to use it to change edition with CDN as a source
  16220. :: OfficeClickToRun.exe with productstoadd method is used here to add editions
  16221. :: It uses delta updates, meaning that since it's using same installed build, it will consume very less Internet
  16222. ​
  16223. call :oe_getlangs
  16224. ​
  16225. set "c2rcommand="%_c2rExe%" platform=%_oArch% culture=%_lang% productstoadd=%targetedition%.16_%_allLangs% cdnbaseurl.16=http://officecdn.microsoft.com/pr/%_updch% baseurl.16=http://officecdn.microsoft.com/pr/%_updch% version.16=%_version% mediatype.16=CDN sourcetype.16=CDN deliverymechanism=%_updch% %targetedition%.excludedapps.16=groove%excludelist% flt.useteamsaddon=disabled flt.usebingaddononinstall=disabled flt.usebingaddononupdate=disabled"
  16226. ​
  16227. if %change%==1 (
  16228. set "c2rcommand=!c2rcommand! productstoremove=AllProducts"
  16229. )
  16230. ​
  16231. echo:
  16232. echo Running the below command, please wait...
  16233. echo:
  16234. echo %c2rcommand%
  16235. %c2rcommand%
  16236. set errorcode=%errorlevel%
  16237. timeout /t 10 %nul%
  16238. ​
  16239. echo:
  16240. set suggestchannel=
  16241. ​
  16242. if %errorcode% EQU 0 (
  16243. if %change%==1 (
  16244. echo %targetedition% | find /i "2019Volume" %nul% && (
  16245. if not defined ltsc19 set suggestchannel=Production::LTSC
  16246. if /i not %_AudienceData%==Production::LTSC set suggestchannel=Production::LTSC
  16247. if /i not %_updch%==F2E724C1-748F-4B47-8FB8-8E0D210E9208 set suggestchannel=Production::LTSC
  16248. )
  16249. ​
  16250. echo %targetedition% | find /i "2021Volume" %nul% && (
  16251. if not defined ltsc21 set suggestchannel=Production::LTSC2021
  16252. if /i not %_AudienceData%==Production::LTSC2021 set suggestchannel=Production::LTSC2021
  16253. if /i not %_updch%==5030841D-C919-4594-8D2D-84AE4F96E58E set suggestchannel=Production::LTSC2021
  16254. )
  16255. ​
  16256. echo %targetedition% | find /i "2024Volume" %nul% && (
  16257. if not defined ltsc24 set suggestchannel=Production::LTSC2024
  16258. if /i not %_AudienceData%==Production::LTSC2024 set suggestchannel=Production::LTSC2024
  16259. if /i not %_updch%==7983BAC0-E531-40CF-BE00-FD24FE66619C set suggestchannel=Production::LTSC2024
  16260. )
  16261. ​
  16262. echo %targetedition% | findstr /R "20.*Volume" %nul% || (
  16263. if defined ltscfound set suggestchannel=Production::CC
  16264. echo %_AudienceData% | find /i "LTSC" %nul% && set suggestchannel=Production::CC
  16265. )
  16266. ​
  16267. if defined suggestchannel (
  16268. call :dk_color %Gray% "Mismatch found in update channel and installed product."
  16269. call :dk_color %Blue% "It is recommended to change the update channel to [!suggestchannel!] from the previous menu."
  16270. )
  16271. echo:
  16272. )
  16273. call :dk_color %Gray% "To activate Office, run the activation option from the main menu."
  16274. ) else (
  16275. set fixes=%fixes% %mas%troubleshoot
  16276. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  16277. )
  16278. ​
  16279. call :oe_tempcleanup
  16280. goto :oe_goback
  16281. ​
  16282. ::========================================================================================================================================
  16283. ​
  16284. :: Edit Office edition
  16285. ​
  16286. :oe_editedition
  16287. ​
  16288. cls
  16289. title Add/Remove Apps %masver%
  16290. ​
  16291. call :oe_chkinternet
  16292. if not defined _int (
  16293. goto :oe_goback
  16294. )
  16295. ​
  16296. set change=0
  16297. set editedition=1
  16298. call :ch_getinfo
  16299. cls
  16300. ​
  16301. if not defined terminal (
  16302. mode 98, 35
  16303. )
  16304. ​
  16305. set inpt=
  16306. set counter=0
  16307. set verified=0
  16308. set targetedition=
  16309. ​
  16310. %line%
  16311. echo:
  16312. call :dk_color %Gray% "You can edit [add/remove apps] one of the following Office editions."
  16313. %line%
  16314. echo:
  16315. ​
  16316. for %%A in (%_oIds%) do (
  16317. set /a counter+=1
  16318. echo [!counter!] %%A
  16319. set targetedition!counter!=%%A
  16320. )
  16321. ​
  16322. %line%
  16323. echo:
  16324. echo [0] Go Back
  16325. echo:
  16326. call :dk_color %_Green% "Enter an option number using your keyboard and press Enter to confirm:"
  16327. set /p inpt=
  16328. if "%inpt%"=="" goto :oe_editedition
  16329. if "%inpt%"=="0" goto :oemenu
  16330. for /l %%i in (1,1,%counter%) do (if "%inpt%"=="%%i" set verified=1)
  16331. set targetedition=!targetedition%inpt%!
  16332. if %verified%==0 goto :oe_editedition
  16333. ​
  16334. ::===============
  16335. ​
  16336. cls
  16337. if not defined terminal mode 98, 32
  16338. ​
  16339. echo %targetedition% | findstr /i "Access Excel OneNote Outlook PowerPoint Project Publisher Skype Visio Word" %nul% && (set list=SingleApps) || (set list=Suites)
  16340. goto :oe_excludeappspre
  16341. ​
  16342. ::========================================================================================================================================
  16343. ​
  16344. :: Remove Office editions
  16345. ​
  16346. :oe_removeedition
  16347. ​
  16348. title Remove Office editions %masver%
  16349. ​
  16350. call :ch_getinfo
  16351. ​
  16352. cls
  16353. if not defined terminal (
  16354. mode 98, 35
  16355. )
  16356. ​
  16357. set counter=0
  16358. for %%A in (%_oIds%) do (set /a counter+=1)
  16359. ​
  16360. if !counter! LEQ 1 (
  16361. echo:
  16362. echo Only "%_oIds%" product is installed.
  16363. echo This option is available only when multiple products are installed.
  16364. goto :oe_goback
  16365. )
  16366. ​
  16367. ::===============
  16368. ​
  16369. set inpt=
  16370. set counter=0
  16371. set verified=0
  16372. set targetedition=
  16373. ​
  16374. %line%
  16375. echo:
  16376. call :dk_color %Gray% "You can uninstall one of the following Office editions."
  16377. %line%
  16378. echo:
  16379. ​
  16380. for %%A in (%_oIds%) do (
  16381. set /a counter+=1
  16382. echo [!counter!] %%A
  16383. set targetedition!counter!=%%A
  16384. )
  16385. ​
  16386. %line%
  16387. echo:
  16388. echo [0] Go Back
  16389. echo:
  16390. call :dk_color %_Green% "Enter an option number using your keyboard and press Enter to confirm:"
  16391. set /p inpt=
  16392. if "%inpt%"=="" goto :oe_removeedition
  16393. if "%inpt%"=="0" goto :oemenu
  16394. for /l %%i in (1,1,%counter%) do (if "%inpt%"=="%%i" set verified=1)
  16395. set targetedition=!targetedition%inpt%!
  16396. if %verified%==0 goto :oe_removeedition
  16397. ​
  16398. ::===============
  16399. ​
  16400. cls
  16401. if not defined terminal mode 105, 32
  16402. ​
  16403. call :oe_getlangs %targetedition%
  16404. set "c2rcommand="%_c2rExe%" platform=%_oArch% productstoremove=%targetedition%.16_%_allLangs%"
  16405. ​
  16406. echo:
  16407. echo Running the below command, please wait...
  16408. echo:
  16409. echo %c2rcommand%
  16410. %c2rcommand%
  16411. ​
  16412. if %errorlevel% NEQ 0 (
  16413. echo:
  16414. set fixes=%fixes% %mas%troubleshoot
  16415. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  16416. )
  16417. ​
  16418. goto :oe_goback
  16419. ​
  16420. ::========================================================================================================================================
  16421. ​
  16422. :: Change Office update channel
  16423. ​
  16424. :oe_changeupdchnl
  16425. ​
  16426. title Change Office update channel %masver%
  16427. call :ch_getinfo
  16428. ​
  16429. cls
  16430. if not defined terminal (
  16431. mode 98, 33
  16432. )
  16433. ​
  16434. call :oe_chkinternet
  16435. if not defined _int (
  16436. goto :oe_goback
  16437. )
  16438. ​
  16439. if %winbuild% LSS 10240 (
  16440. echo %_oIds% | findstr "2019 2021 2024" %nul% && (
  16441. %eline%
  16442. echo Installed Office editions: %_oIds%
  16443. echo Unsupported Office edition is installed on your Windows build version %winbuild%.
  16444. goto :oe_goback
  16445. )
  16446. if defined ltscfound (
  16447. %eline%
  16448. echo Installed Office update channel: %ltsc19%%ltsc21%%ltsc24%
  16449. echo Unsupported Office update channel is installed on your Windows build version %winbuild%.
  16450. goto :oe_goback
  16451. )
  16452. )
  16453. ​
  16454. ::===============
  16455. ​
  16456. set inpt=
  16457. set counter=0
  16458. set verified=0
  16459. set targetFFN=
  16460. set bypassFFN=
  16461. set targetchannel=
  16462. ​
  16463. %line%
  16464. echo:
  16465. call :dk_color %Gray% "Installed update channel: %_AudienceData%, %_version%, Client: %_clversion%"
  16466. call :dk_color %Gray% "Installed Office editions: %_oIds%"
  16467. %line%
  16468. echo:
  16469. ​
  16470. for %%# in (
  16471. "5440fd1f-7ecb-4221-8110-145efaa6372f_Beta / Insider Fast - Insiders::DevMain -"
  16472. "64256afe-f5d9-4f86-8936-8840a6a4f5be_Current / Monthly Preview - Insiders::CC -"
  16473. "492350f6-3a01-4f97-b9c0-c7c6ddf67d60_Current / Monthly - Production::CC -"
  16474. "55336b82-a18d-4dd6-b5f6-9e5095c314a6_Monthly Enterprise - Production::MEC -"
  16475. "7ffbc6bf-bc32-4f92-8982-f9dd17fd3114_Semi Annual Enterprise - Production::DC -"
  16476. "ea4a4090-de26-49d7-93c1-91bff9e53fc3_DevMain Channel - Dogfood::DevMain -"
  16477. "b61285dd-d9f7-41f2-9757-8f61cba4e9c8_Microsoft Elite - Microsoft::DevMain -"
  16478. "f2e724c1-748f-4b47-8fb8-8e0d210e9208_Perpetual2019 VL - Production::LTSC -"
  16479. "1d2d2ea6-1680-4c56-ac58-a441c8c24ff9_Microsoft2019 VL - Microsoft::LTSC -"
  16480. "5030841d-c919-4594-8d2d-84ae4f96e58e_Perpetual2021 VL - Production::LTSC2021 -"
  16481. "86752282-5841-4120-ac80-db03ae6b5fdb_Microsoft2021 VL - Microsoft::LTSC2021 -"
  16482. "7983bac0-e531-40cf-be00-fd24fe66619c_Perpetual2024 VL - Production::LTSC2024 -"
  16483. "c02d8fe6-5242-4da8-972f-82ee55e00671_Microsoft2024 VL - Microsoft::LTSC2024 -"
  16484. ) do (
  16485. for /f "tokens=1-2 delims=_" %%A in ("%%~#") do (
  16486. set bypass=
  16487. set supported=
  16488. if %winbuild% LSS 10240 (echo %%B | findstr /i "LTSC DevMain" %nul% || set supported=1) else (set supported=1)
  16489. if %winbuild% GEQ 10240 (
  16490. if defined ltsc19 echo %%B | find /i "2019 VL" %nul% || set bypass=1
  16491. if defined ltsc21 echo %%B | find /i "2021 VL" %nul% || set bypass=1
  16492. if defined ltsc24 echo %%B | find /i "2024 VL" %nul% || set bypass=1
  16493. if not defined ltscfound echo %%B | find /i "LTSC" %nul% && set bypass=1
  16494. )
  16495. if defined supported (
  16496. set /a counter+=1
  16497. if !counter! LSS 10 (
  16498. if defined bypass (echo [!counter!] %%B Unofficial change method will be used) else (echo [!counter!] %%B)
  16499. ) else (
  16500. if defined bypass (echo [!counter!] %%B Unofficial change method will be used) else (echo [!counter!] %%B)
  16501. )
  16502. set targetFFN!counter!=%%A
  16503. set targetchannel!counter!=%%B
  16504. if defined bypass set bypassFFN=!bypassFFN!%%A
  16505. )
  16506. )
  16507. )
  16508. ​
  16509. %line%
  16510. echo:
  16511. echo [R] Learn about update channels
  16512. echo [0] Go back
  16513. echo:
  16514. call :dk_color %_Green% "Enter an option number using your keyboard and press Enter to confirm:"
  16515. set /p inpt=
  16516. if "%inpt%"=="" goto :oe_changeupdchnl
  16517. if "%inpt%"=="0" goto :oemenu
  16518. if /i "%inpt%"=="R" start https://learn.microsoft.com/en-us/microsoft-365-apps/updates/overview-update-channels & goto :oe_changeupdchnl
  16519. for /l %%i in (1,1,%counter%) do (if "%inpt%"=="%%i" set verified=1)
  16520. set targetFFN=!targetFFN%inpt%!
  16521. set targetchannel=!targetchannel%inpt%!
  16522. if %verified%==0 goto :oe_changeupdchnl
  16523. ​
  16524. ::=======================
  16525. ​
  16526. cls
  16527. if not defined terminal mode 105, 32
  16528. ​
  16529. :: Get build number for the target FFN, using build number with OfficeC2RClient.exe command to trigger updates provides accurate results
  16530. ​
  16531. set build=
  16532. for /f "delims=" %%a in ('%psc% "$f=[System.IO.File]::ReadAllText('!_batp!') -split ':getbuild\:.*';. ([scriptblock]::Create($f[1]))" %nul6%') do (set build=%%a)
  16533. echo "%build%" | find /i "16." %nul% || set build=
  16534. ​
  16535. echo:
  16536. for /f "tokens=1 delims=-" %%A in ("%targetchannel%") do (echo Target update channel: %%A)
  16537. echo Target build number: %build%
  16538. echo: %bypassFFN% | find /i "%targetFFN%" %nul% && goto :oe_changeunoff
  16539. ​
  16540. call :oe_cleanupreg
  16541. ​
  16542. if not defined build (
  16543. if %winbuild% GEQ 9200 call :dk_color %Gray% "Failed to detect build number for the target FFN."
  16544. set "updcommand="%_c2rCexe%" /update user"
  16545. ) else (
  16546. set "updcommand="%_c2rCexe%" /update user updatetoversion=%build%"
  16547. )
  16548. echo Running the below command to trigger updates...
  16549. echo:
  16550. echo %updcommand%
  16551. %updcommand%
  16552. echo:
  16553. echo Check this webpage for help - %mas%troubleshoot
  16554. goto :oe_goback
  16555. ​
  16556. ::=======================
  16557. ​
  16558. :: Unofficial method to change channel
  16559. ​
  16560. :oe_changeunoff
  16561. ​
  16562. set abortchange=
  16563. echo %targetchannel% | find /i "2019 VL" %nul% && (for %%A in (%_oIds%) do (echo %%A | find /i "2019Volume" %nul% || set abortchange=1))
  16564. echo %targetchannel% | find /i "2021 VL" %nul% && (for %%A in (%_oIds%) do (echo %%A | find /i "2021Volume" %nul% || set abortchange=1))
  16565. echo %targetchannel% | find /i "2024 VL" %nul% && (for %%A in (%_oIds%) do (echo %%A | find /i "2024Volume" %nul% || set abortchange=1))
  16566. ​
  16567. if defined abortchange (
  16568. %eline%
  16569. echo Mismatch found in installed Office products and target update channel. Aborting...
  16570. echo Non-perpetual Office products are not suppported with Perpetual VL update channels.
  16571. goto :oe_goback
  16572. )
  16573. ​
  16574. if not defined build (
  16575. %eline%
  16576. call :dk_color %Red% "Failed to detect build number for the target FFN."
  16577. set fixes=%fixes% %mas%troubleshoot
  16578. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  16579. goto :oe_goback
  16580. )
  16581. ​
  16582. set buildchk=0
  16583. for /f "tokens=3 delims=." %%a in ("%build%") do set "buildchk=%%a"
  16584. ​
  16585. call :oe_getlangs %_firstoId%
  16586. ​
  16587. echo %targetchannel% | find /i "2019 VL" %nul% && (
  16588. for %%A in (en-gb es-mx fr-ca) do (
  16589. echo %_allLangs% | find /i "%%A" %nul% && (
  16590. %eline%
  16591. echo [%%A] language is not supported on the Office 2019 Perpetual VL update channel. Aborting...
  16592. goto :oe_goback
  16593. )
  16594. )
  16595. )
  16596. ​
  16597. set "c2rcommand="%_c2rExe%" platform=%_oArch% culture=%_lang% productstoadd=%_firstoId%.16_%_allLangs% cdnbaseurl.16=http://officecdn.microsoft.com/pr/%targetFFN% baseurl.16=http://officecdn.microsoft.com/pr/%targetFFN% version.16=%build% mediatype.16=CDN sourcetype.16=CDN deliverymechanism=%targetFFN% %_firstoId%.excludedapps.16=%_firstoIdExcludelist% flt.useteamsaddon=disabled flt.usebingaddononinstall=disabled flt.usebingaddononupdate=disabled"
  16598. set "c2rclientupdate=!c2rcommand! scenario=CLIENTUPDATE"
  16599. ​
  16600. if %clverchk% LSS %buildchk% (
  16601. echo:
  16602. call :dk_color %Blue% "Do not terminate the operation before it completes..."
  16603. echo:
  16604. echo Updating Office C2R client with the command below, please wait...
  16605. echo:
  16606. echo %c2rclientupdate%
  16607. %c2rclientupdate%
  16608. for /l %%i in (1,1,30) do (if !clverchk! LSS %buildchk% (call :ch_getinfo&timeout /t 10 %nul%))
  16609. )
  16610. ​
  16611. if %clverchk% LSS %buildchk% (
  16612. echo:
  16613. call :dk_color %Red% "Failed to update Office C2R client. Aborting..."
  16614. set fixes=%fixes% %mas%troubleshoot
  16615. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  16616. goto :oe_goback
  16617. )
  16618. ​
  16619. call :oe_cleanupreg
  16620. ​
  16621. echo Running the below command to change update channel, please wait...
  16622. echo:
  16623. echo %c2rcommand%
  16624. %c2rcommand%
  16625. set errorcode=%errorlevel%
  16626. timeout /t 10 %nul%
  16627. ​
  16628. echo:
  16629. if %errorcode% EQU 0 (
  16630. call :dk_color %Gray% "Now run the Office activation option from the main menu."
  16631. ) else (
  16632. set fixes=%fixes% %mas%troubleshoot
  16633. call :dk_color2 %Blue% "Check this webpage for help - " %_Yellow% " %mas%troubleshoot"
  16634. )
  16635. ​
  16636. ::========================================================================================================================================
  16637. ​
  16638. :oe_goback
  16639. ​
  16640. call :oe_tempcleanup
  16641. ​
  16642. echo:
  16643. ​
  16644. if defined terminal (
  16645. call :dk_color %_Yellow% "Press [0] key to go back..."
  16646. choice /c 0 /n
  16647. ) else (
  16648. call :dk_color %_Yellow% "Press any key to go back..."
  16649. pause %nul1%
  16650. )
  16651. goto :oemenu
  16652. ​
  16653. ::========================================================================================================================================
  16654. ​
  16655. :oe_cleanupreg
  16656. ​
  16657. :: Cleanup Office update related registries, thanks to @abbodi1406
  16658. :: https://techcommunity.microsoft.com/t5/office-365-blog/how-to-manage-office-365-proplus-channels-for-it-pros/ba-p/795813
  16659. :: https://learn.microsoft.com/en-us/microsoft-365-apps/updates/change-update-channels#considerations-when-changing-channels
  16660. ​
  16661. echo:
  16662. echo Cleaning Office update registry keys...
  16663. echo Adding new update channel to registry keys...
  16664. echo:
  16665. ​
  16666. %nul% reg add %o16c2r_reg%\Configuration /v CDNBaseUrl /t REG_SZ /d "https://officecdn.microsoft.com/pr/%targetFFN%" /f
  16667. %nul% reg add %o16c2r_reg%\Configuration /v UpdateChannel /t REG_SZ /d "https://officecdn.microsoft.com/pr/%targetFFN%" /f
  16668. %nul% reg add %o16c2r_reg%\Configuration /v UpdateChannelChanged /t REG_SZ /d "True" /f
  16669. %nul% reg delete %o16c2r_reg%\Configuration /v UnmanagedUpdateURL /f
  16670. %nul% reg delete %o16c2r_reg%\Configuration /v UpdateUrl /f
  16671. %nul% reg delete %o16c2r_reg%\Configuration /v UpdatePath /f
  16672. %nul% reg delete %o16c2r_reg%\Configuration /v UpdateToVersion /f
  16673. %nul% reg delete %o16c2r_reg%\Updates /v UpdateToVersion /f
  16674. %nul% reg delete HKLM\SOFTWARE\Policies\Microsoft\office\16.0\common\officeupdate /f
  16675. %nul% reg delete HKLM\SOFTWARE\Policies\Microsoft\office\16.0\common\officeupdate /f /reg:32
  16676. %nul% reg delete HKCU\SOFTWARE\Policies\Microsoft\office\16.0\common\officeupdate /f
  16677. %nul% reg delete HKLM\SOFTWARE\Policies\Microsoft\cloud\office\16.0\Common\officeupdate /f
  16678. %nul% reg delete HKLM\SOFTWARE\Policies\Microsoft\cloud\office\16.0\Common\officeupdate /f /reg:32
  16679. %nul% reg delete HKCU\Software\Policies\Microsoft\cloud\office\16.0\Common\officeupdate /f
  16680. ​
  16681. exit /b
  16682. ​
  16683. ::========================================================================================================================================
  16684. ​
  16685. :oe_tempcleanup
  16686. ​
  16687. del /f /q %SystemRoot%\Temp\SingleApps_Volume.txt %nul%
  16688. del /f /q %SystemRoot%\Temp\SingleApps_Retail.txt %nul%
  16689. del /f /q %SystemRoot%\Temp\Suites_Volume.txt %nul%
  16690. del /f /q %SystemRoot%\Temp\Suites_Retail.txt %nul%
  16691. del /f /q %SystemRoot%\Temp\getAppIds.txt %nul%
  16692. exit /b
  16693. ​
  16694. ::========================================================================================================================================
  16695. ​
  16696. :: Fetch required info
  16697. ​
  16698. :ch_getinfo
  16699. ​
  16700. set _oRoot=
  16701. set _oArch=
  16702. set _updch=
  16703. set _oIds=
  16704. set _firstoId=
  16705. set _lang=
  16706. set _cfolder=
  16707. set _version=
  16708. set _clversion=
  16709. set _AudienceData=
  16710. set _actconfig=
  16711. set _c2rXml=
  16712. set _c2rExe=
  16713. set _c2rCexe=
  16714. set _masterxml=
  16715. set ltsc19=
  16716. set ltsc21=
  16717. set ltsc24=
  16718. set ltscfound=
  16719. ​
  16720. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg% /v InstallPath" %nul6%') do (set "_oRoot=%%b\root")
  16721. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v Platform" %nul6%') do (set "_oArch=%%b")
  16722. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v ClientFolder" %nul6%') do (set "_cfolder=%%b")
  16723. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v AudienceId" %nul6%') do (set "_updch=%%b")
  16724. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v ClientCulture" %nul6%') do (set "_lang=%%b")
  16725. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v ClientVersionToReport" %nul6%') do (set "_clversion=%%b")
  16726. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v VersionToReport" %nul6%') do (set "_version=%%b")
  16727. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v AudienceData" %nul6%') do (set "_AudienceData=%%b")
  16728. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\ProductReleaseIDs /v ActiveConfiguration" %nul6%') do (set "_actconfig=%%b")
  16729. ​
  16730. echo "%o16c2r_reg%" | find /i "Wow6432Node" %nul1% && (set _tok=9) || (set _tok=8)
  16731. for /f "tokens=%_tok% delims=\" %%a in ('reg query "%o16c2r_reg%\ProductReleaseIDs\%_actconfig%" /f ".16" /k %nul6% ^| findstr /i "Retail Volume"') do (
  16732. if defined _oIds (set "_oIds=!_oIds! %%a") else (set "_oIds=%%a")
  16733. )
  16734. set _oIds=%_oIds:.16=%
  16735. for /f "tokens=1" %%A in ("%_oIds%") do set _firstoId=%%A
  16736. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\Configuration /v %_firstoId%.ExcludedApps" %nul6%') do (set "_firstoIdExcludelist=%%b")
  16737. ​
  16738. set verchk=0
  16739. set clverchk=0
  16740. for /f "tokens=3 delims=." %%a in ("%_version%") do set "verchk=%%a"
  16741. for /f "tokens=3 delims=." %%a in ("%_clversion%") do set "clverchk=%%a"
  16742. ​
  16743. if exist "%_oRoot%\Licenses16\c2rpridslicensefiles_auto.xml" set "_c2rXml=%_oRoot%\Licenses16\c2rpridslicensefiles_auto.xml"
  16744. ​
  16745. if exist "%ProgramData%\Microsoft\ClickToRun\ProductReleases\%_actconfig%\x-none.16\MasterDescriptor.x-none.xml" (
  16746. set "_masterxml=%ProgramData%\Microsoft\ClickToRun\ProductReleases\%_actconfig%\x-none.16\MasterDescriptor.x-none.xml"
  16747. )
  16748. ​
  16749. if exist "%_cfolder%\OfficeClickToRun.exe" (
  16750. set "_c2rExe=%_cfolder%\OfficeClickToRun.exe"
  16751. )
  16752. ​
  16753. if exist "%_cfolder%\OfficeC2RClient.exe" (
  16754. set "_c2rCexe=%_cfolder%\OfficeC2RClient.exe"
  16755. )
  16756. ​
  16757. :: Check LTSC version files
  16758. ​
  16759. for /f "skip=2 tokens=2*" %%a in ('"reg query %o16c2r_reg%\ProductReleaseIDs\%_actconfig%" /s %nul6%') do (
  16760. echo "%%b" %nul2% | findstr "16.0.103 16.0.104 16.0.105" %nul% && set ltsc19=LTSC
  16761. echo "%%b" %nul2% | findstr "16.0.14332" %nul% && set ltsc21=LTSC2021
  16762. echo "%%b" %nul2% | findstr "16.0.17932" %nul% && set ltsc24=LTSC2024
  16763. )
  16764. ​
  16765. if not "%ltsc19%%ltsc21%%ltsc24%"=="" set ltscfound=1
  16766. ​
  16767. exit /b
  16768. ​
  16769. ::========================================================================================================================================
  16770. ​
  16771. :: Check all the installed languages
  16772. ​
  16773. :oe_getlangs
  16774. ​
  16775. if "%1"=="" (
  16776. set langreg=culture
  16777. ) else (
  16778. set langreg=%1.16
  16779. )
  16780. ​
  16781. set _allLangs=
  16782. echo "%o16c2r_reg%" | find /i "Wow6432Node" %nul1% && (set _tok=10) || (set _tok=9)
  16783. for /f "tokens=%_tok% delims=\" %%a in ('reg query "%o16c2r_reg%\ProductReleaseIDs\%_actconfig%\%langreg%" /f "-" /k ^| findstr /i "%langreg%\\.*-.*"') do (
  16784. if defined _allLangs (set "_allLangs=!_allLangs!_%%a") else (set "_allLangs=%%a")
  16785. )
  16786. ​
  16787. set _allLangs=%_allLangs:.16=%
  16788. exit /b
  16789. ​
  16790. ::========================================================================================================================================
  16791. ​
  16792. :: Check Internet connection
  16793. ​
  16794. :oe_chkinternet
  16795. ​
  16796. set _int=
  16797. for %%a in (download.windowsupdate.com) do if not defined _int (
  16798. for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do (if not "%%#"=="" set _int=1)
  16799. )
  16800. ​
  16801. if not defined _int (
  16802. %psc% "If([Activator]::CreateInstance([Type]::GetTypeFromCLSID([Guid]'{DCB00C01-570F-4A9B-8D69-199FDBA5723B}')).IsConnectedToInternet){Exit 0}Else{Exit 1}"
  16803. if !errorlevel!==0 (set _int=1)
  16804. )
  16805. ​
  16806. if not defined _int (
  16807. %eline%
  16808. call :dk_color %Red% "Internet is not connected."
  16809. call :dk_color %Blue% "Internet is required for this operation."
  16810. )
  16811. exit /b
  16812. ​
  16813. ::========================================================================================================================================
  16814. ​
  16815. :: Get available build number for a FFN
  16816. ​
  16817. :getbuild:
  16818. $Tls12 = [Enum]::ToObject([System.Net.SecurityProtocolType], 3072)
  16819. [System.Net.ServicePointManager]::SecurityProtocol = $Tls12
  16820. ​
  16821. $FFN = $env:targetFFN
  16822. $windowsBuild = [System.Environment]::OSVersion.Version.Build
  16823. ​
  16824. $baseUrl = "https://mrodevicemgr.officeapps.live.com/mrodevicemgrsvc/api/v2/C2RReleaseData?audienceFFN=$FFN"
  16825. $url = if ($windowsBuild -lt 9200) { "$baseUrl&osver=Client|6.1" } elseif ($windowsBuild -lt 10240) { "$baseUrl&osver=Client|6.3" } else { $baseUrl }
  16826. ​
  16827. $response = if ($windowsBuild -ge 9200) { irm -Uri $url -Method Get } else { (New-Object System.Net.WebClient).DownloadString($url) }
  16828. ​
  16829. if ($windowsBuild -lt 9200) {
  16830. if ($response -match '"AvailableBuild"\s*:\s*"([^"]+)"') { Write-Host $matches[1] }
  16831. } else {
  16832. Write-Host $response.AvailableBuild
  16833. }
  16834. :getbuild:
  16835. ​
  16836. ::========================================================================================================================================
  16837. ​
  16838. :: Get available edition list from c2rpridslicensefiles_auto.xml
  16839. :: and filter the list using MasterDescriptor.x-none.xml
  16840. :: and exclude unsupported products on Windows 7/8/8.1
  16841. ​
  16842. :getlist:
  16843. $xmlPath1 = $env:_c2rXml
  16844. $xmlPath2 = $env:_masterxml
  16845. $outputDir = $env:SystemRoot + "\Temp\"
  16846. $buildNumber = [System.Environment]::OSVersion.Version.Build
  16847. $excludedKeywords = @("2019", "2021", "2024")
  16848. $productReleaseIds = @()
  16849. ​
  16850. if (Test-Path $xmlPath1) {
  16851. $xml1 = New-Object -TypeName System.Xml.XmlDocument
  16852. $xml1.Load($xmlPath1)
  16853. foreach ($node in $xml1.SelectNodes("//ProductReleaseId")) {
  16854. $id = $node.GetAttribute("id")
  16855. $exclude = $false
  16856. if ($buildNumber -lt 10240) {
  16857. foreach ($keyword in $excludedKeywords) {
  16858. if ($id -match $keyword) { $exclude = $true; break }
  16859. }
  16860. }
  16861. if ($id -ne "CommonLicenseFiles" -and -not $exclude) { $productReleaseIds += $id }
  16862. }
  16863. }
  16864. ​
  16865. $categories = @{
  16866. "Suites_Retail" = @(); "Suites_Volume" = @()
  16867. "SingleApps_Retail" = @(); "SingleApps_Volume" = @()
  16868. }
  16869. ​
  16870. foreach ($id in $productReleaseIds) {
  16871. $category = if ($id -match "Retail") { "Retail" } else { "Volume" }
  16872. $categories["SingleApps_$category"] += $id
  16873. }
  16874. ​
  16875. if (Test-Path $xmlPath2) {
  16876. $xml2 = New-Object -TypeName System.Xml.XmlDocument
  16877. $xml2.Load($xmlPath2)
  16878. foreach ($sku in $xml2.SelectNodes("//SKU")) {
  16879. $skuId = $sku.GetAttribute("ID")
  16880. if ($productReleaseIds -contains $skuId) {
  16881. $appIds = $sku.SelectNodes("Apps/App") | ForEach-Object { $_.GetAttribute("id") }
  16882. if ($appIds -contains "Excel" -and $appIds -contains "Word") {
  16883. $category = if ($skuId -match "Retail") { "Retail" } else { "Volume" }
  16884. $categories["Suites_$category"] += $skuId
  16885. $categories["SingleApps_$category"] = $categories["SingleApps_$category"] | Where-Object { $_ -ne $skuId }
  16886. }
  16887. }
  16888. }
  16889. }
  16890. ​
  16891. foreach ($section in $categories.Keys) {
  16892. $filePath = Join-Path -Path $outputDir -ChildPath "$section.txt"
  16893. $ids = $categories[$section]
  16894. if ($ids.Count -gt 0) { $ids | Out-File -FilePath $filePath -Encoding ASCII }
  16895. }
  16896. :getlist:
  16897. ​
  16898. ::========================================================================================================================================
  16899. ​
  16900. :: Get App list for a specific product ID using MasterDescriptor.x-none.xml
  16901. ​
  16902. :getappnames:
  16903. $xmlPath = $env:_masterxml
  16904. $targetSkuId = $env:targetedition
  16905. $outputDir = $env:SystemRoot + "\Temp\"
  16906. $outputFile = Join-Path -Path $outputDir -ChildPath "getAppIds.txt"
  16907. $excludeIds = @("shared", "PowerPivot", "PowerView", "MondoOnly", "OSM", "OSMUX", "Groove", "DCF")
  16908. ​
  16909. $xml = New-Object -TypeName System.Xml.XmlDocument
  16910. $xml.Load($xmlPath)
  16911. ​
  16912. $appIdsList = @()
  16913. $skuNodes = $xml.SelectNodes("//SKU[@ID='$targetSkuId']")
  16914. ​
  16915. foreach ($skuNode in $skuNodes) {
  16916. foreach ($app in $skuNode.SelectNodes("Apps/App")) {
  16917. $appId = $app.GetAttribute("id")
  16918. if ($excludeIds -notcontains $appId) {
  16919. $appIdsList += $appId
  16920. }
  16921. }
  16922. }
  16923. ​
  16924. if ($appIdsList.Count -gt 0) {
  16925. $appIdsList | Out-File -FilePath $outputFile -Encoding ASCII
  16926. }
  16927. :getappnames:
  16928. ​
  16929. ::========================================================================================================================================
  16930. ::
  16931. :: Leave empty line below

Edit this Snippet