Skip to content

Commit

Permalink
29: Code improvement, replaced key.vbs with key.cmd
Browse files Browse the repository at this point in the history
29: Code improvement, replaced key.vbs with key.cmd
  • Loading branch information
kkkgo committed Feb 24, 2019
1 parent 135cdcc commit e0fecce
Show file tree
Hide file tree
Showing 10 changed files with 1,721 additions and 531 deletions.
689 changes: 689 additions & 0 deletions $OEM$/$$/Setup/Scripts/Win32/key.cmd

Large diffs are not rendered by default.

200 changes: 0 additions & 200 deletions $OEM$/$$/Setup/Scripts/Win32/key.vbs

This file was deleted.

49 changes: 26 additions & 23 deletions $OEM$/$$/Setup/Scripts/setupcomplete.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ set Office2019=Random

set FixedEPID=1

set "_Nul_1=1>nul"
set "_Nul_2=2>nul"
set "_Nul_2e=2^>nul"
set "_Nul_1_2=1>nul 2>nul"
set "SysPath=%Windir%\System32"
if exist "%Windir%\Sysnative\reg.exe" (set "SysPath=%Windir%\Sysnative")
set "Path=%SysPath%;%Windir%;%SysPath%\Wbem;%SysPath%\WindowsPowerShell\v1.0\"
set "PSModulePath=%ProgramFiles%\WindowsPowerShell\Modules;%SysPath%\WindowsPowerShell\v1.0\Modules"

set W1nd0ws=1
set spp=SoftwareLicensingProduct
Expand All @@ -26,9 +26,11 @@ WMIC PATH %spp% WHERE (Name like 'Windows%%' and PartialProductKey is not NULL)
WMIC PATH %sps% WHERE version='%ver%' CALL RefreshLicenseStatus >nul 2>&1
WMIC PATH %spp% WHERE LicenseStatus=1 GET Name 2>nul | findstr /i "Windows" >nul && (set "W1nd0ws=")

set "_tempdir=%SystemRoot%\Temp"
set "_workdir=%~dp0"
set xOS=x64
if /i %PROCESSOR_ARCHITECTURE%==x86 (if "%PROCESSOR_ARCHITEW6432%"=="" set xOS=Win32)
setlocal EnableExtensions EnableDelayedExpansion
cd /d "%~dp0"
IF /I "%PROCESSOR_ARCHITECTURE%" EQU "AMD64" (set xOS=x64) else (set xOS=Win32)
set "IFEO=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
set "OSPP=HKLM\SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform"
set "SPPk=SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform"
Expand Down Expand Up @@ -71,7 +73,8 @@ SET EditionID=%EditionWMI%
:Main
call :StopService sppsvc
if %OsppHook% NEQ 0 call :StopService osppsvc
copy /y "%xOS%\SppExtComObjHook.dll" "%SystemRoot%\system32" >nul 2>&1
if exist "%SystemRoot%\system32\SppExtComObjPatcher.*" del /f /q "%SystemRoot%\system32\SppExtComObjPatcher.*" >nul 2>&1
copy /y "!_workdir!\!xOS!\SppExtComObjHook.dll" "%SystemRoot%\system32" >nul 2>&1
if %OSType% EQU Win8 call :CreateIFEOEntry SppExtComObj.exe
if %OSType% EQU Win7 if %SppHook% NEQ 0 call :CreateIFEOEntry sppsvc.exe
call :CreateIFEOEntry osppsvc.exe
Expand All @@ -85,9 +88,7 @@ if %winbuild% GEQ 9200 (
schtasks /query /tn "\Microsoft\Windows\SoftwareProtectionPlatform\SvcTrigger" 1>nul 2>nul || schtasks /create /tn "\Microsoft\Windows\SoftwareProtectionPlatform\SvcTrigger" /xml "%~dp0Win32\SvcTrigger.xml" /f >nul 2>&1
)
attrib -R -A -S -H *.*
del /f /q c2rchk.txt >nul 2>&1
del /f /q sppchk.txt >nul 2>&1
del /f /q osppchk.txt >nul 2>&1
if exist "!_tempdir!\*chk.txt" del /f /q "!_tempdir!\*chk.txt"
exit /b

:StopService
Expand Down Expand Up @@ -133,10 +134,10 @@ wmic path %sps% where version='%ver%' call DisableKeyManagementServiceHostCachin
exit /b

:sppchkoff
wmic path %spp% where ID='%app%' get Name > sppchk.txt
find /i "Office 15" sppchk.txt 1>nul && (if %loc_off15% equ 0 exit /b)
find /i "Office 16" sppchk.txt 1>nul && (if %loc_off16% equ 0 exit /b)
find /i "Office 19" sppchk.txt 1>nul && (if %loc_off19% equ 0 exit /b)
wmic path %spp% where ID='%app%' get Name > "!_tempdir!\sppchk.txt"
find /i "Office 15" "!_tempdir!\sppchk.txt" 1>nul && (if %loc_off15% equ 0 exit /b)
find /i "Office 16" "!_tempdir!\sppchk.txt" 1>nul && (if %loc_off16% equ 0 exit /b)
find /i "Office 19" "!_tempdir!\sppchk.txt" 1>nul && (if %loc_off19% equ 0 exit /b)
set office=1
wmic path %spp% where (PartialProductKey is not NULL) get ID 2>nul | findstr /i "%app%" 1>nul && (call :activate %app%&exit /b)
for /f "tokens=3 delims==, " %%G in ('"wmic path %spp% where ID='%app%' get Name /value"') do set OffVer=%%G
Expand Down Expand Up @@ -202,11 +203,11 @@ wmic path %sps% where version='%ver%' call DisableKeyManagementServiceHostCachin
exit /b

:osppchk
wmic path %spp% where ID='%app%' get Name > osppchk.txt
find /i "Office 14" osppchk.txt 1>nul && (if %loc_off14% equ 0 exit /b)
find /i "Office 15" osppchk.txt 1>nul && (if %loc_off15% equ 0 exit /b)
find /i "Office 16" osppchk.txt 1>nul && (if %loc_off16% equ 0 exit /b)
find /i "Office 19" osppchk.txt 1>nul && (if %loc_off19% equ 0 exit /b)
wmic path %spp% where ID='%app%' get Name > "!_tempdir!\osppchk.txt"
find /i "Office 14" "!_tempdir!\osppchk.txt" 1>nul && (if %loc_off14% equ 0 exit /b)
find /i "Office 15" "!_tempdir!\osppchk.txt" 1>nul && (if %loc_off15% equ 0 exit /b)
find /i "Office 16" "!_tempdir!\osppchk.txt" 1>nul && (if %loc_off16% equ 0 exit /b)
find /i "Office 19" "!_tempdir!\osppchk.txt" 1>nul && (if %loc_off19% equ 0 exit /b)
set office=0
wmic path %spp% where (PartialProductKey is not NULL) get ID | findstr /i "%app%" >nul 2>&1 && (call :activate %app%&exit /b)
for /f "tokens=3 delims==, " %%G in ('"wmic path %spp% where ID='%app%' get Name /value"') do set OffVer=%%G
Expand Down Expand Up @@ -389,10 +390,10 @@ for /f "tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\%1.0\Commo
for /f "tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\%1.0\Common\InstallRoot /v Path" 2^>nul') do if exist "%%b\OSPP.VBS" set loc_off%1=1

if %1 equ 16 if defined _C2R (
for /f "skip=2 tokens=2*" %%a in ('reg query %_C2R% /v ProductReleaseIds') do echo %%b> c2rchk.txt
for /f "skip=2 tokens=2*" %%a in ('reg query %_C2R% /v ProductReleaseIds') do echo %%b> "!_tempdir!\c2rchk.txt"
for %%a in (Mondo,ProPlus,Standard,ProjectProX,ProjectStdX,ProjectPro,ProjectStd,VisioProX,VisioStdX,VisioPro,VisioStd,Access,Excel,OneNote,Outlook,PowerPoint,Publisher,SkypeforBusiness,Word) do (
findstr /I /C:"%%aVolume" c2rchk.txt 1>nul && set loc_off%1=1
findstr /I /C:"%%aRetail" c2rchk.txt 1>nul && set loc_off%1=1
findstr /I /C:"%%aVolume" "!_tempdir!\c2rchk.txt" 1>nul && set loc_off%1=1
findstr /I /C:"%%aRetail" "!_tempdir!\c2rchk.txt" 1>nul && set loc_off%1=1
)
exit /b
)
Expand All @@ -403,9 +404,11 @@ exit /b

:insKey
set "key="
for /f %%A in ('cscript //Nologo Win32\key.vbs %1') do set "key=%%A"
call "!_workdir!\Win32\key.cmd" %1
if "%key%" EQU "" (exit /b)
wmic path %sps% where version='%ver%' call InstallProductKey ProductKey="%key%" >nul 2>&1
set ERRORCODE=%ERRORLEVEL%
if %ERRORCODE% neq 0 exit /b

:activate
wmic path %spp% where ID='%1' call ClearKeyManagementServiceMachine >nul 2>&1
Expand Down
40 changes: 27 additions & 13 deletions 1-SppExtComObjPatcher.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@echo off
cls
set ClearKMSCache=1

set KMS_Emulation=1
Expand All @@ -13,19 +14,17 @@ set Office2013=Random
set Office2016=Random
set Office2019=Random

%windir%\system32\reg.exe query "HKU\S-1-5-19" >nul 2>&1 || (
echo ==== ERROR ====
echo This script require administrator privileges.
echo To do so, right click on this script and select 'Run as administrator'
echo.
echo Press any key to exit...
pause >nul
goto :eof
)
set "SysPath=%Windir%\System32"
if exist "%Windir%\Sysnative\reg.exe" (set "SysPath=%Windir%\Sysnative")
set "Path=%SysPath%;%Windir%;%SysPath%\Wbem;%SysPath%\WindowsPowerShell\v1.0\"

fsutil dirty query %systemdrive% >nul 2>&1 || goto :E_Admin

title SppExtComObjPatcher
set "_workdir=%~dp0"
set xOS=x64
if /i %PROCESSOR_ARCHITECTURE%==x86 (if "%PROCESSOR_ARCHITEW6432%"=="" set xOS=Win32)
setlocal EnableExtensions EnableDelayedExpansion
cd /d "%~dp0"
IF /I "%PROCESSOR_ARCHITECTURE%" EQU "AMD64" (set xOS=x64) else (set xOS=Win32)
set "IFEO=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"
set "OSPP=HKLM\SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform"
set "SPPk=SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform"
Expand Down Expand Up @@ -60,7 +59,8 @@ WMIC /NAMESPACE:\\root\Microsoft\Windows\Defender PATH MSFT_MpPreference call Ad
)
echo.
echo Copying Files...
copy /y "%xOS%\SppExtComObjHook.dll" "%SystemRoot%\system32" >nul 2>&1 && (echo Copied SppExtComObjHook.dll) || (echo SppExtComObjHook.dll Failed&pause&exit)
if exist "%SystemRoot%\system32\SppExtComObjPatcher.*" del /f /q "%SystemRoot%\system32\SppExtComObjPatcher.*" %_Nul_1_2%
copy /y "!_workdir!\!xOS!\SppExtComObjHook.dll" "%SystemRoot%\system32" >nul 2>&1 && (echo Copied SppExtComObjHook.dll) || (echo SppExtComObjHook.dll Failed&pause&exit /b)
echo.
echo Creating Registry Entries...
if %OSType% EQU Win8 (
Expand All @@ -73,6 +73,9 @@ if %OSType% EQU Win7 if %SppHook% NEQ 0 (
)
echo osppsvc.exe of Office %OffVer%
call :CreateIFEOEntry osppsvc.exe
if %winbuild% GEQ 9200 (
schtasks /query /tn "\Microsoft\Windows\SoftwareProtectionPlatform\SvcTrigger" >nul 2>&1 || schtasks /create /tn "\Microsoft\Windows\SoftwareProtectionPlatform\SvcTrigger" /xml "!_workdir!\Win32\SvcTrigger.xml" /f >nul 2>&1
)
goto :End

:uninst
Expand Down Expand Up @@ -112,9 +115,11 @@ echo Clearing KMS Cache...
call :cKMS SoftwareLicensingProduct SoftwareLicensingService
if %OsppHook% NEQ 0 call :cKMS OfficeSoftwareProtectionProduct OfficeSoftwareProtectionService
)
if %winbuild% GEQ 9200 (
schtasks /query /tn "\Microsoft\Windows\SoftwareProtectionPlatform\SvcTrigger" >nul 2>&1 && schtasks /delete /f /tn "\Microsoft\Windows\SoftwareProtectionPlatform\SvcTrigger" >nul 2>&1
)
if %winbuild% GEQ 9600 (
reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\Software Protection Platform" /v "NoGenTicket" /f >nul 2>&1
schtasks /delete /f /tn "\Microsoft\Windows\SoftwareProtectionPlatform\SvcTrigger" >nul 2>&1
WMIC /NAMESPACE:\\root\Microsoft\Windows\Defender PATH MSFT_MpPreference call Remove ExclusionPath="%SystemRoot%\system32\SppExtComObjHook.dll" >nul 2>&1
WMIC /NAMESPACE:\\root\Microsoft\Windows\Defender PATH MSFT_MpPreference call Remove ExclusionPath="%SystemRoot%\system32\SppExtComObjPatcher.dll" >nul 2>&1
WMIC /NAMESPACE:\\root\Microsoft\Windows\Defender PATH MSFT_MpPreference call Remove ExclusionPath="%SystemRoot%\system32\SppExtComObjPatcher.exe" >nul 2>&1
Expand Down Expand Up @@ -183,6 +188,15 @@ wmic path %spp% where ID='%app%' call ClearKeyManagementServiceMachine >nul 2>&1
wmic path %spp% where ID='%app%' call ClearKeyManagementServicePort >nul 2>&1
goto :EOF

:E_Admin
echo ==== ERROR ====
echo This script require administrator privileges.
echo To do so, right click on this script and select 'Run as administrator'
echo.
echo Press any key to exit...
pause >nul
goto :EOF

:UnsupportedVersion
echo ==== ERROR ====
echo Unsupported OS version Detected.
Expand Down
64 changes: 37 additions & 27 deletions 2-Activate-Local.cmd
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
@echo off
cls
set _Debug=0

set Online=0
Expand All @@ -11,10 +12,21 @@ set KMS38=1

set FixedEPID=1

%windir%\system32\reg.exe query "HKU\S-1-5-19" >nul 2>&1 || goto :E_Admin
set "SysPath=%Windir%\System32"
if exist "%Windir%\Sysnative\reg.exe" (set "SysPath=%Windir%\Sysnative")
set "Path=%SysPath%;%Windir%;%SysPath%\Wbem;%SysPath%\WindowsPowerShell\v1.0\"

fsutil dirty query %systemdrive% >nul 2>&1 || goto :E_Admin
if %Online%==0 if not exist "%SystemRoot%\system32\SppExtComObj*.dll" goto :E_Patcher
if %Online%==0 set KMS_IP=172.16.0.2

set "_tempdir=%SystemRoot%\Temp"
set "_workdir=%~dp0"
set "_logpath=%~dpn0"
dir /b /adr "%_workdir%" 1>nul 2>nul && set "_logpath=%_tempdir%\%~n0"
if "%_workdir:~0,2%"=="\\" set "_logpath=%_tempdir%\%~n0"
setlocal EnableExtensions EnableDelayedExpansion

if %_Debug% EQU 0 (
set "_Nul_1=1>nul"
set "_Nul_2=2>nul"
Expand All @@ -31,16 +43,13 @@ if %_Debug% EQU 0 (
echo The window will be closed when finished
@echo on
@prompt $G
@call :Begin >"%~dpn0.tmp" 2>&1 &cmd /u /c type "%~dpn0.tmp">"%~dpn0_Debug.log"&del "%~dpn0.tmp"
@call :Begin >"!_logpath!.tmp" 2>&1 &cmd /u /c type "!_logpath!.tmp">"!_logpath!_Debug.log"&del "!_logpath!.tmp"
)
exit
exit /b

:Begin
color 1F
title KMS_VL_ALL Auto Renewal
setlocal EnableExtensions EnableDelayedExpansion
cd /d "%~dp0"
IF /I "%PROCESSOR_ARCHITECTURE%" EQU "AMD64" (set xOS=x64) else (set xOS=Win32)
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G
if %winbuild% GEQ 9600 (
reg add "HKLM\SOFTWARE\Policies\Microsoft\Windows NT\CurrentVersion\Software Protection Platform" /f /v NoGenTicket /t REG_DWORD /d 1 %_Nul_1_2%
Expand Down Expand Up @@ -75,12 +84,7 @@ for %%A in (14,15,16,19) do call :officeLoc %%A
call :SPP
call :OSPP
if %Online%==0 if %FixedEPID%==1 call :ePID
if %winbuild% GEQ 9200 (
schtasks /query /tn "\Microsoft\Windows\SoftwareProtectionPlatform\SvcTrigger" %_Nul_1_2% || schtasks /create /tn "\Microsoft\Windows\SoftwareProtectionPlatform\SvcTrigger" /xml "%~dp0Win32\SvcTrigger.xml" /f %_Nul_1_2%
)
del /f /q c2rchk.txt %_Nul_1_2%
del /f /q sppchk.txt %_Nul_1_2%
del /f /q osppchk.txt %_Nul_1_2%
if exist "!_tempdir!\*chk.txt" del /f /q "!_tempdir!\*chk.txt"
net stop sppsvc /y %_Nul_1_2% || sc stop sppsvc %_Nul_1_2%
sc start sppsvc trigger=timer;sessionid=0 %_Nul_1_2%
echo.
Expand Down Expand Up @@ -115,10 +119,10 @@ wmic path %sps% where version='%ver%' call DisableKeyManagementServiceHostCachin
exit /b

:sppchkoff
wmic path %spp% where ID='%app%' get Name > sppchk.txt
find /i "Office 15" sppchk.txt %_Nul_1% && (if %loc_off15% equ 0 exit /b)
find /i "Office 16" sppchk.txt %_Nul_1% && (if %loc_off16% equ 0 exit /b)
find /i "Office 19" sppchk.txt %_Nul_1% && (if %loc_off19% equ 0 exit /b)
wmic path %spp% where ID='%app%' get Name > "!_tempdir!\sppchk.txt"
find /i "Office 15" "!_tempdir!\sppchk.txt" %_Nul_1% && (if %loc_off15% equ 0 exit /b)
find /i "Office 16" "!_tempdir!\sppchk.txt" %_Nul_1% && (if %loc_off16% equ 0 exit /b)
find /i "Office 19" "!_tempdir!\sppchk.txt" %_Nul_1% && (if %loc_off19% equ 0 exit /b)
set office=1
wmic path %spp% where (PartialProductKey is not NULL) get ID %_Nul_2% | findstr /i "%app%" %_Nul_1% && (echo.&call :activate %app%&exit /b)
for /f "tokens=3 delims==, " %%G in ('"wmic path %spp% where ID='%app%' get Name /value"') do set OffVer=%%G
Expand Down Expand Up @@ -191,11 +195,11 @@ wmic path %sps% where version='%ver%' call DisableKeyManagementServiceHostCachin
exit /b

:osppchk
wmic path %spp% where ID='%app%' get Name > osppchk.txt
find /i "Office 14" osppchk.txt %_Nul_1% && (if %loc_off14% equ 0 exit /b)
find /i "Office 15" osppchk.txt %_Nul_1% && (if %loc_off15% equ 0 exit /b)
find /i "Office 16" osppchk.txt %_Nul_1% && (if %loc_off16% equ 0 exit /b)
find /i "Office 19" osppchk.txt %_Nul_1% && (if %loc_off19% equ 0 exit /b)
wmic path %spp% where ID='%app%' get Name > "!_tempdir!\osppchk.txt"
find /i "Office 14" "!_tempdir!\osppchk.txt" %_Nul_1% && (if %loc_off14% equ 0 exit /b)
find /i "Office 15" "!_tempdir!\osppchk.txt" %_Nul_1% && (if %loc_off15% equ 0 exit /b)
find /i "Office 16" "!_tempdir!\osppchk.txt" %_Nul_1% && (if %loc_off16% equ 0 exit /b)
find /i "Office 19" "!_tempdir!\osppchk.txt" %_Nul_1% && (if %loc_off19% equ 0 exit /b)
set office=0
wmic path %spp% where (PartialProductKey is not NULL) get ID | findstr /i "%app%" %_Nul_1_2% && (echo.&call :activate %app%&exit /b)
for /f "tokens=3 delims==, " %%G in ('"wmic path %spp% where ID='%app%' get Name /value"') do set OffVer=%%G
Expand Down Expand Up @@ -386,10 +390,10 @@ for /f "tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\%1.0\Commo
for /f "tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\%1.0\Common\InstallRoot /v Path" %_Nul_2e%') do if exist "%%b\OSPP.VBS" set loc_off%1=1

if %1 equ 16 if defined _C2R (
for /f "skip=2 tokens=2*" %%a in ('reg query %_C2R% /v ProductReleaseIds') do echo %%b> c2rchk.txt
for /f "skip=2 tokens=2*" %%a in ('reg query %_C2R% /v ProductReleaseIds') do echo %%b> "!_tempdir!\c2rchk.txt"
for %%a in (Mondo,ProPlus,Standard,ProjectProX,ProjectStdX,ProjectPro,ProjectStd,VisioProX,VisioStdX,VisioPro,VisioStd,Access,Excel,OneNote,Outlook,PowerPoint,Publisher,SkypeforBusiness,Word) do (
findstr /I /C:"%%aVolume" c2rchk.txt %_Nul_1% && set loc_off%1=1
findstr /I /C:"%%aRetail" c2rchk.txt %_Nul_1% && set loc_off%1=1
findstr /I /C:"%%aVolume" "!_tempdir!\c2rchk.txt" %_Nul_1% && set loc_off%1=1
findstr /I /C:"%%aRetail" "!_tempdir!\c2rchk.txt" %_Nul_1% && set loc_off%1=1
)
exit /b
)
Expand All @@ -402,9 +406,15 @@ exit /b
echo.
set "key="
for /f "tokens=2 delims==" %%A in ('"wmic path %spp% where ID='%1' get Name /VALUE"') do echo Installing Key for: %%A
for /f %%A in ('cscript //Nologo Win32\key.vbs %1') do set "key=%%A"
call "!_workdir!\Win32\key.cmd" %1
if "%key%" EQU "" (echo Could not find matching KMS Client key&exit /b)
wmic path %sps% where version='%ver%' call InstallProductKey ProductKey="%key%" %_Nul_1_2%
set ERRORCODE=%ERRORLEVEL%
if %ERRORCODE% neq 0 (
cmd /c exit /b %ERRORCODE%
echo Failed: 0x!=ExitCode!
exit /b
)

:activate
wmic path %spp% where ID='%1' call ClearKeyManagementServiceMachine %_Nul_1_2%
Expand All @@ -427,8 +437,8 @@ if %gpr% gtr 259200 (echo Windows 10 EnterpriseG/EnterpriseGN Activation Success
if %gpr% equ 259200 (
echo Product Activation Successful
) else (
call cmd /c exit /b %ERRORCODE%
echo Product Activation Failed: 0x%=ExitCode%
cmd /c exit /b %ERRORCODE%
echo Product Activation Failed: 0x!=ExitCode!
)
echo Remaining Period: %gpr2% days ^(%gpr% minutes^)
exit /b
Expand Down
Loading

0 comments on commit e0fecce

Please sign in to comment.