From e81490b89c55d7b0477da6e72db36e13f2b15f63 Mon Sep 17 00:00:00 2001
From: WindowsAddict
Date: Mon, 25 Sep 2023 19:16:19 +0530
Subject: 1.9
---
.../Activators/Online_KMS_Activation.cmd | 117 +++++++++++++++------
1 file changed, 85 insertions(+), 32 deletions(-)
(limited to 'MAS/Separate-Files-Version/Activators/Online_KMS_Activation.cmd')
diff --git a/MAS/Separate-Files-Version/Activators/Online_KMS_Activation.cmd b/MAS/Separate-Files-Version/Activators/Online_KMS_Activation.cmd
index befbdc3..fd6df96 100644
--- a/MAS/Separate-Files-Version/Activators/Online_KMS_Activation.cmd
+++ b/MAS/Separate-Files-Version/Activators/Online_KMS_Activation.cmd
@@ -20,9 +20,15 @@
-
::========================================================================================================================================
+:: Set Path variable, it helps if it is misconfigured in the system
+
+set "PATH=%SystemRoot%\System32;%SystemRoot%\System32\wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\"
+if exist "%SystemRoot%\Sysnative\reg.exe" (
+set "PATH=%SystemRoot%\Sysnative;%SystemRoot%\Sysnative\wbem;%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\;%PATH%"
+)
+
:: Re-launch the script with x64 process if it was initiated by x86 process on x64 bit Windows
:: or with ARM64 process if it was initiated by x86/ARM32 process on ARM64 Windows
@@ -30,6 +36,10 @@ set "_cmdf=%~f0"
for %%# in (%*) do (
if /i "%%#"=="r1" set r1=1
if /i "%%#"=="r2" set r2=1
+if /i "%%#"=="-qedit" (
+reg add HKCU\Console /v QuickEdit /t REG_DWORD /d "1" /f 1>nul
+rem check the code below admin elevation to understand why it's here
+)
)
if exist %SystemRoot%\Sysnative\cmd.exe if not defined r1 (
@@ -46,22 +56,34 @@ start %SystemRoot%\SysArm32\cmd.exe /c ""!_cmdf!" %* r2"
exit /b
)
-:: Set Path variable, it helps if it is misconfigured in the system
+::========================================================================================================================================
-set "PATH=%SystemRoot%\System32;%SystemRoot%\System32\wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\"
-if exist "%SystemRoot%\Sysnative\reg.exe" (
-set "PATH=%SystemRoot%\Sysnative;%SystemRoot%\Sysnative\wbem;%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\;%PATH%"
+set "blank="
+set "mas=mass%blank%grave.dev"
+
+:: Check if Null service is working, it's important for the batch script
+
+sc query Null | find /i "RUNNING"
+if %errorlevel% NEQ 0 (
+echo:
+echo Null service is not running, script may crash...
+echo:
+echo:
+echo Help - https://%mas%/troubleshoot.html
+echo:
+echo:
+ping 127.0.0.1 -n 10
)
+cls
:: Check LF line ending
pushd "%~dp0"
->nul findstr /rxc:".*" "%~nx0"
-if not %errorlevel%==0 (
+>nul findstr /v "$" "%~nx0" && (
echo:
-echo Error: Script either has LF line ending issue, or it failed to read itself.
+echo Error: Script either has LF line ending issue or an empty line at the end of the script is missing.
echo:
-ping 127.0.0.1 -n 6 > nul
+ping 127.0.0.1 -n 6 >nul
popd
exit /b
)
@@ -96,8 +118,7 @@ set _unattendedact=
set _args=%*
if defined _args set _args=%_args:"=%
if defined _args (
-set _unattended=1
-if "%_args%"=="-el" set _unattended=
+echo "%_args%" | find /i "/KMS" >nul && set _unattended=1
for %%A in (%_args%) do (
if /i "%%A"=="-el" (set _elev=1
@@ -116,9 +137,9 @@ if /i "%%A"=="-el" (set _elev=1
::========================================================================================================================================
-set winbuild=1
set "nul=>nul 2>&1"
set psc=powershell.exe
+set winbuild=1
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G
set _NCS=1
@@ -136,7 +157,7 @@ if %_Debug% EQU 1 set _unattended=1
if %winbuild% LSS 7600 (
%nceline%
-echo Unsupported OS version detected.
+echo Unsupported OS version detected [%winbuild%].
echo Project is supported for Windows 7/8/8.1/10/11 and their Server equivalent.
goto Done
)
@@ -182,7 +203,7 @@ goto Done
:: Elevate script as admin and pass arguments and preventing loop
>nul fltmc || (
-if not defined _elev %nul% %psc% "start cmd.exe -arg '/c \"!_PSarg:'=''!\"' -verb runas" && exit /b
+if not defined _elev %psc% "start cmd.exe -arg '/c \"!_PSarg:'=''!\"' -verb runas" && exit /b
%nceline%
echo This script require admin privileges.
echo To do so, right click on this script and select 'Run as administrator'.
@@ -191,6 +212,21 @@ goto Done
::========================================================================================================================================
+:: This code disables QuickEdit for this cmd.exe session only without making permanent changes to the registry
+:: It is added because clicking on the script window pauses the operation and leads to the confusion that script stopped due to an error
+
+if defined _unattended set quedit=1
+for %%# in (%_args%) do (if /i "%%#"=="-qedit" set quedit=1)
+
+reg query HKCU\Console /v QuickEdit 2>nul | find /i "0x0" %nul% || if not defined quedit (
+reg add HKCU\Console /v QuickEdit /t REG_DWORD /d "0" /f %nul%
+start cmd.exe /c ""!_batf!" %_args% -qedit"
+rem quickedit reset code is added at the starting of the script instead of here because it takes time to reflect in some cases
+exit /b
+)
+
+::========================================================================================================================================
+
if %~z0 GEQ 300000 (set "_exitmsg=Go back") else (set "_exitmsg=Exit")
:: Check not x86 Windows
@@ -252,7 +288,7 @@ reg query %kNext% /v MigrationToV5Done 2>nul | find /i "0x1" %nul% && call :offi
set _tskinstalled=
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\taskcache\tasks" /f Path /s | find /i "\Activation-Renewal" >nul && (
-find /i "Ver:1.8" %ProgramData%\Activation-Renewal\Activation_task.cmd %nul% && set _tskinstalled=1
+find /i "Ver:1.9" "%ProgramFiles%\Activation-Renewal\Activation_task.cmd" %nul% && set _tskinstalled=1
)
set _oldtsk=
@@ -382,7 +418,12 @@ set "_log=%~dpn0"
set "_work=%~dp0"
if "%_work:~-1%"=="\" set "_work=%_work:~0,-1%"
set _UNC=0
-if "%_work:~0,2%"=="\\" set _UNC=1
+if "%_work:~0,2%"=="\\" (
+set _UNC=1
+) else (
+net use %~d0 %_Null%
+if not errorlevel 1 set _UNC=1
+)
for /f "skip=2 tokens=2*" %%a in ('reg query "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Desktop') do call set "_dsk=%%b"
if exist "%PUBLIC%\Desktop\desktop.ini" set "_dsk=%PUBLIC%\Desktop"
set "_mO21a=Detected Office 2021 C2R Retail is activated"
@@ -407,6 +448,8 @@ if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum
set "ESUEditions=ServerDatacenter,ServerDatacenterCore,ServerDatacenterV,ServerDatacenterVCore,ServerStandard,ServerStandardCore,ServerStandardV,ServerStandardVCore,ServerEnterprise,ServerEnterpriseCore,ServerEnterpriseV,ServerEnterpriseVCore"
)
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G
+set UBR=0
+if %winbuild% GEQ 7601 for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v UBR 2^>nul') do if not errorlevel 1 set /a UBR=%%b
set "_csq=cscript.exe //NoLogo //Job:WmiQuery "%~nx0?.wsf""
set "_csm=cscript.exe //NoLogo //Job:WmiMethod "%~nx0?.wsf""
set "_csp=cscript.exe //NoLogo //Job:WmiPKey "%~nx0?.wsf""
@@ -437,7 +480,7 @@ pushd "!_work!"
if not defined _unattended (
mode con cols=98 lines=31
-%nul% %psc% "&%_buf%"
+%psc% "&%_buf%"
title %_title%
) else (
title Online KMS Activation
@@ -608,7 +651,10 @@ IF %winbuild% LSS 14393 (
)
IF NOT "%EditionWMI%"=="" SET "EditionID=%EditionWMI%"
IF /I "%EditionID%"=="IoTEnterprise" SET "EditionID=Enterprise"
-IF /I "%EditionID%"=="IoTEnterpriseS" IF %winbuild% LSS 22610 SET "EditionID=EnterpriseS"
+IF /I "%EditionID%"=="IoTEnterpriseS" IF %winbuild% LSS 22610 (
+SET "EditionID=EnterpriseS"
+IF %winbuild% GEQ 19041 IF %UBR% GEQ 2788 SET "EditionID=IoTEnterpriseS"
+)
IF /I "%EditionID%"=="ProfessionalSingleLanguage" SET "EditionID=Professional"
IF /I "%EditionID%"=="ProfessionalCountrySpecific" SET "EditionID=Professional"
IF /I "%EditionID%"=="EnterpriseG" SET Win10Gov=1
@@ -2220,6 +2266,7 @@ if %_C16Msg% EQU 1 set _CtRMsg=1
if %_C15Msg% EQU 1 set _CtRMsg=1
if %_Office16% EQU 1 (
for %%a in (%_RetIds%,ProPlus) do set "_%%a="
+for %%A in (19,21) do call :officeLoc %%A
)
if %_Office15% EQU 1 (
for %%a in (%_R15Ids%,ProPlus) do set "_%%a="
@@ -3314,6 +3361,11 @@ echo Deleting [Folder] %ProgramData%\Activation-Renewal\
rmdir /s /q "%ProgramData%\Activation-Renewal\" %nul%
)
+If exist "%ProgramFiles%\Activation-Renewal\" (
+echo Deleting [Folder] %ProgramFiles%\Activation-Renewal\
+rmdir /s /q "%ProgramFiles%\Activation-Renewal\" %nul%
+)
+
reg query "HKCR\DesktopBackground\shell\Activate Windows - Office" %nul% && (
echo Deleting [Registry] HKCR\DesktopBackground\shell\Activate Windows - Office
Reg delete "HKCR\DesktopBackground\shell\Activate Windows - Office" /f %nul%
@@ -3321,13 +3373,13 @@ Reg delete "HKCR\DesktopBackground\shell\Activate Windows - Office" /f %nul%
reg query "%key%" /f Path /s | find /i "\Activation-Renewal" >nul && (set error_=1)
reg query "%key%" /f Path /s | find /i "\Activation-Run_Once" >nul && (set error_=1)
-reg query "%key%" /f Path /s | find /i "\Online_KMS_Activation_Script-Run_Once" >nul && (set error_=1)
-reg query "%key%" /f Path /s | find /i "\Online_KMS_Activation_Script-Run_Once" >nul && (set error_=1)
+reg query "%key%" /f Path /s | find /i "\Online_KMS_Activation_Script" >nul && (set error_=1)
If exist "%windir%\Online_KMS_Activation_Script\" (set error_=1)
reg query "HKCR\DesktopBackground\shell\Activate Windows - Office" %nul% && (set error_=1)
if exist "%ProgramData%\Online_KMS_Activation.cmd" (set error_=1)
if exist "%ProgramData%\Online_KMS_Activation\" (set error_=1)
if exist "%ProgramData%\Activation-Renewal\" (set error_=1)
+if exist "%ProgramFiles%\Activation-Renewal\" (set error_=1)
exit /b
:=========================================================================================================================================
@@ -3339,7 +3391,7 @@ mode con cols=91 lines=30
title Install Activation Auto-Renewal
set error_=
-set "_dest=%ProgramData%\Activation-Renewal"
+set "_dest=%ProgramFiles%\Activation-Renewal"
set "key=HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\taskcache\tasks"
call :clearstuff %nul%
@@ -3352,7 +3404,7 @@ goto :RenDone
)
if not exist "%_dest%\" md "%_dest%\" %nul%
-set "_temp=%SystemRoot%\Temp\_taskwork"
+set "_temp=%SystemRoot%\Temp\_taskwork_%Random%"
set nil=
if exist "%_temp%\.*" rmdir /s /q "%_temp%\" %nul%
@@ -3364,7 +3416,7 @@ if defined ActTask (s%nil%cht%nil%asks /cre%nil%ate /tn "Activation-Run_Once" /r
if exist "%_temp%\.*" rmdir /s /q "%_temp%\" %nul%
call :createInfo.txt
-%nul% %psc% "$f=[io.file]::ReadAllText('!_batp!') -split \":_extracttask\:.*`r`n\"; [io.file]::WriteAllText('%_dest%\Activation_task.cmd', '@REM Dummy ' + '%random%' + [Environment]::NewLine + $f[1].Trim(), [System.Text.Encoding]::ASCII);"
+%psc% "$f=[io.file]::ReadAllText('!_batp!') -split \":_extracttask\:.*`r`n\"; [io.file]::WriteAllText('%_dest%\Activation_task.cmd', '@REM Dummy ' + '%random%' + [Environment]::NewLine + $f[1].Trim(), [System.Text.Encoding]::ASCII);"
title Install Activation Auto-Renewal
::========================================================================================================================================
@@ -3445,9 +3497,9 @@ echo Activation-Run_Once [Activation Task - deletes itself once activated]
echo The scheduled tasks runs only if the system is connected to the Internet.
echo:
echo - Files
-echo C:\ProgramData\Activation-Renewal\Activation_task.cmd
-echo C:\ProgramData\Activation-Renewal\Info.txt
-echo C:\ProgramData\Activation-Renewal\Logs.txt
+echo C:\Program Files\Activation-Renewal\Activation_task.cmd
+echo C:\Program Files\Activation-Renewal\Info.txt
+echo C:\Program Files\Activation-Renewal\Logs.txt
echo ______________________________________________________________________________________________
echo:
echo Online KMS Activation Script is a part of 'Microsoft_Activation_Scripts' [MAS] project.
@@ -3516,7 +3568,7 @@ exit /b
- %ProgramData%\Activation-Renewal\Activation_task.cmd
+ %ProgramFiles%\Activation-Renewal\Activation_task.cmd
Task
@@ -3573,7 +3625,7 @@ exit /b
- %ProgramData%\Activation-Renewal\Activation_task.cmd
+ %ProgramFiles%\Activation-Renewal\Activation_task.cmd
Task
@@ -3586,7 +3638,7 @@ exit /b
:RenExport
-%nul% %psc% "$f=[io.file]::ReadAllText('!_batp!') -split \":%~1\:.*`r`n\"; [io.file]::WriteAllText('%~2',$f[1].Trim(),[System.Text.Encoding]::%~3);"
+%psc% "$f=[io.file]::ReadAllText('!_batp!') -split \":%~1\:.*`r`n\"; [io.file]::WriteAllText('%~2',$f[1].Trim(),[System.Text.Encoding]::%~3);"
exit /b
::========================================================================================================================================
@@ -3647,7 +3699,7 @@ wmic path Win32_ComputerSystem get CreationClassName /value 2>nul | find /i "com
)
setlocal EnableDelayedExpansion
-if exist "%ProgramData%\Activation-Renewal\" call :_taskstart>>"%ProgramData%\Activation-Renewal\Logs.txt" & exit
+if exist "%ProgramFiles%\Activation-Renewal\" call :_taskstart>>"%ProgramFiles%\Activation-Renewal\Logs.txt" & exit
::========================================================================================================================================
@@ -4047,7 +4099,7 @@ if not [%KMS_IP%]==[!KMS_IP!] exit /b
goto :_taskgetserv
)
-:: Ver:1.8
+:: Ver:1.9
::========================================================================================================================================
:_extracttask:
@@ -4192,4 +4244,5 @@ if ($OSPP) {
UninstallLicenses("sppc.dll")
:cleanlicense:
-::========================================================================================================================================
\ No newline at end of file
+::========================================================================================================================================
+:: Leave empty line below
--
cgit v1.2.3