Compare commits

..

No commits in common. "73eabbff59964ef0386c014e5256d33981211f1a" and "5f5a51322d35aa3dae58cde5edb70e324cbf0ad8" have entirely different histories.

1 changed files with 308 additions and 228 deletions

View File

@ -1,12 +1,15 @@
@set masver=2.6
@setlocal DisableDelayedExpansion
@echo off
::============================================================================
::
:: This script is a part of 'Microsoft-Activation-Scripts' (MAS) project.
::
:: Homepage: mass grave[.]dev
:: Email: mas.help@outlook.com
:: Email: windowsaddict@protonmail.com
::
::============================================================================
@ -14,31 +17,25 @@
::========================================================================================================================================
:: Set Environment variables, it helps if they are misconfigured in the system
:: Set Path variable, it helps if it is misconfigured in the system
setlocal EnableExtensions
setlocal DisableDelayedExpansion
set "PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
set "SysPath=%SystemRoot%\System32"
set "Path=%SystemRoot%\System32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\"
set "PATH=%SystemRoot%\System32;%SystemRoot%\System32\wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\"
if exist "%SystemRoot%\Sysnative\reg.exe" (
set "SysPath=%SystemRoot%\Sysnative"
set "Path=%SystemRoot%\Sysnative;%SystemRoot%;%SystemRoot%\Sysnative\Wbem;%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\;%Path%"
set "PATH=%SystemRoot%\Sysnative;%SystemRoot%\Sysnative\wbem;%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\;%PATH%"
)
set "ComSpec=%SysPath%\cmd.exe"
set "PSModulePath=%ProgramFiles%\WindowsPowerShell\Modules;%SysPath%\WindowsPowerShell\v1.0\Modules"
:: 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
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 %nul1%
rem check the code below admin elevation to understand why it's here
)
)
:: 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
if exist %SystemRoot%\Sysnative\cmd.exe if not defined r1 (
setlocal EnableDelayedExpansion
@ -67,10 +64,10 @@ echo:
echo Null service is not running, script may crash...
echo:
echo:
echo Help - %mas%troubleshoot
echo Help - %mas%troubleshoot.html
echo:
echo:
ping 127.0.0.1 -n 20
ping 127.0.0.1 -n 10
)
cls
@ -79,13 +76,9 @@ cls
pushd "%~dp0"
>nul findstr /v "$" "%~nx0" && (
echo:
echo Error - Script either has LF line ending issue or an empty line at the end of the script is missing.
echo Error: Script either has LF line ending issue or an empty line at the end of the script is missing.
echo:
echo:
echo Help - %mas%troubleshoot
echo:
echo:
ping 127.0.0.1 -n 20 >nul
ping 127.0.0.1 -n 6 >nul
popd
exit /b
)
@ -99,7 +92,6 @@ title Troubleshoot %masver%
set _args=
set _elev=
set _unattended=0
set _args=%*
if defined _args set _args=%_args:"=%
@ -114,8 +106,20 @@ set "nul2=2>nul"
set "nul6=2^>nul"
set "nul=>nul 2>&1"
call :dk_setvar
set psc=powershell.exe
set winbuild=1
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G
set _NCS=1
if %winbuild% LSS 10586 set _NCS=0
if %winbuild% GEQ 10586 reg query "HKCU\Console" /v ForceV2 %nul2% | find /i "0x0" %nul1% && (set _NCS=0)
call :_colorprep
set "nceline=echo: &echo ==== ERROR ==== &echo:"
set "eline=echo: &call :_color %Red% "==== ERROR ====" &echo:"
set "line=_________________________________________________________________________________________________"
if %~z0 GEQ 200000 (set "_exitmsg=Go back") else (set "_exitmsg=Exit")
::========================================================================================================================================
@ -123,7 +127,13 @@ if %winbuild% LSS 7600 (
%nceline%
echo Unsupported OS version detected [%winbuild%].
echo Project is supported only for Windows 7/8/8.1/10/11 and their Server equivalent.
goto dk_done
goto at_done
)
for %%# in (powershell.exe) do @if "%%~$PATH:#"=="" (
%nceline%
echo Unable to find powershell.exe in the system.
goto at_done
)
::========================================================================================================================================
@ -137,7 +147,6 @@ set "_batf=%~f0"
set "_batp=%_batf:'=''%"
set _PSarg="""%~f0""" -el %_args%
set _PSarg=%_PSarg:'=''%
set "_ttemp=%userprofile%\AppData\Local\Temp"
@ -147,94 +156,41 @@ setlocal EnableDelayedExpansion
echo "!_batf!" | find /i "!_ttemp!" %nul1% && (
if /i not "!_work!"=="!_ttemp!" (
%eline%
%nceline%
echo Script is launched from the temp folder,
echo Most likely you are running the script directly from the archive file.
echo:
echo Extract the archive file and launch the script from the extracted folder.
goto dk_done
goto at_done
)
)
::========================================================================================================================================
:: Check PowerShell
REM :PowerShellTest: $ExecutionContext.SessionState.LanguageMode :PowerShellTest:
cmd /c "%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':PowerShellTest:\s*';iex ($f[1])"" | find /i "FullLanguage" %nul1% || (
%eline%
cmd /c "%psc% "$ExecutionContext.SessionState.LanguageMode""
echo:
cmd /c "%psc% "$ExecutionContext.SessionState.LanguageMode"" | find /i "FullLanguage" %nul1% && (
echo Failed to run Powershell command but Powershell is working.
call :dk_color %Blue% "Check if your antivirus is blocking the script."
echo:
set fixes=%fixes% %mas%troubleshoot
call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%troubleshoot"
) || (
echo PowerShell is not working. Aborting...
echo If you have applied restrictions on Powershell then undo those changes.
echo:
set fixes=%fixes% %mas%fix_powershell
call :dk_color2 %Blue% "Help - " %_Yellow% " %mas%fix_powershell"
)
goto dk_done
)
::========================================================================================================================================
:: Elevate script as admin and pass arguments and preventing loop
%nul1% fltmc || (
if not defined _elev %psc% "start cmd.exe -arg '/c \"!_PSarg!\"' -verb runas" && exit /b
%eline%
if not defined _elev %psc% "start cmd.exe -arg '/c \"!_PSarg:'=''!\"' -verb runas" && exit /b
%nceline%
echo This script needs admin rights.
echo To do so, right click on this script and select 'Run as administrator'.
goto dk_done
goto at_done
)
::========================================================================================================================================
:: Disable QuickEdit and launch from conhost.exe to avoid Terminal app
:: 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 %winbuild% GEQ 17763 (
set terminal=1
) else (
set terminal=
for %%# in (%_args%) do (if /i "%%#"=="-qedit" set quedit=1)
reg query HKCU\Console /v QuickEdit %nul2% | find /i "0x0" %nul1% || if not defined quedit (
reg add HKCU\Console /v QuickEdit /t REG_DWORD /d "0" /f %nul1%
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
)
:: Check if script is running in Terminal app
set r1=$TB = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0);
set r2=%r1% [void]$TB.DefinePInvokeMethod('GetConsoleWindow', 'kernel32.dll', 22, 1, [IntPtr], @(), 1, 3).SetImplementationFlags(128);
set r3=%r2% [void]$TB.DefinePInvokeMethod('SendMessageW', 'user32.dll', 22, 1, [IntPtr], @([IntPtr], [UInt32], [IntPtr], [IntPtr]), 1, 3).SetImplementationFlags(128);
set d1=%r3% $hIcon = $TB.CreateType(); $hWnd = $hIcon::GetConsoleWindow();
set d2=%d1% echo $($hIcon::SendMessageW($hWnd, 127, 0, 0) -ne [IntPtr]::Zero);
if defined terminal (
%psc% "%d2%" %nul2% | find /i "True" %nul1% && set terminal=
)
if %_unattended%==1 goto :skipQE
for %%# in (%_args%) do (if /i "%%#"=="-qedit" goto :skipQE)
if defined terminal (
set "launchcmd=start conhost.exe %psc%"
) else (
set "launchcmd=%psc%"
)
:: Disable QuickEdit in current session
set "d1=$t=[AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1).DefineDynamicModule(2, $False).DefineType(0);"
set "d2=$t.DefinePInvokeMethod('GetStdHandle', 'kernel32.dll', 22, 1, [IntPtr], @([Int32]), 1, 3).SetImplementationFlags(128);"
set "d3=$t.DefinePInvokeMethod('SetConsoleMode', 'kernel32.dll', 22, 1, [Boolean], @([IntPtr], [Int32]), 1, 3).SetImplementationFlags(128);"
set "d4=$k=$t.CreateType(); $b=$k::SetConsoleMode($k::GetStdHandle(-10), 0x0080);"
%launchcmd% "%d1% %d2% %d3% %d4% & cmd.exe '/c' '!_PSarg! -qedit'" && (exit /b) || (set terminal=1)
:skipQE
::========================================================================================================================================
:: Check for updates
@ -249,19 +205,18 @@ if not [%%#]==[] (echo "%%#" | find "127.69" %nul1% && (echo "%%#" | find "127.6
if defined old (
echo ________________________________________________
%eline%
echo Version %masver% of MAS is outdated.
echo You are running outdated version MAS %masver%
echo ________________________________________________
echo:
if not %_unattended%==1 (
echo [1] Get Latest MAS
echo [0] Continue Anyway
echo:
call :dk_color %_Green% "Enter a menu option in the Keyboard [1,0] :"
call :_color %_Green% "Enter a menu option in the Keyboard [1,0] :"
choice /C:10 /N
if !errorlevel!==2 rem
if !errorlevel!==1 (start ht%-%tps://github.com/mass%-%gravel/Microsoft-Acti%-%vation-Scripts & start %mas% & exit /b)
)
)
cls
::========================================================================================================================================
@ -276,7 +231,7 @@ if not defined desktop for /f "delims=" %%a in ('%psc% "& {write-host $([Environ
if not defined desktop (
%eline%
echo Desktop location was not detected, aborting...
goto dk_done
goto at_done
)
setlocal EnableDelayedExpansion
@ -288,7 +243,7 @@ setlocal EnableDelayedExpansion
cls
color 07
title Troubleshoot %masver%
if not defined terminal mode 77, 30
mode con cols=77 lines=30
echo:
echo:
@ -296,7 +251,7 @@ echo:
echo:
echo: _______________________________________________________________
echo:
call :dk_color2 %_White% " [1] " %_Green% "Help"
call :_color2 %_White% " [1] " %_Green% "Help"
echo: ___________________________________________________
echo:
echo: [2] Dism RestoreHealth
@ -310,12 +265,12 @@ echo:
echo: [0] %_exitmsg%
echo: _______________________________________________________________
echo:
call :dk_color2 %_White% " " %_Green% "Enter a menu option in the Keyboard :"
call :_color2 %_White% " " %_Green% "Enter a menu option in the Keyboard :"
choice /C:1234560 /N
set _erl=%errorlevel%
if %_erl%==7 exit /b
if %_erl%==6 start %mas%fix-wpa-registry &goto at_menu
if %_erl%==6 start %mas%fix-wpa-registry.html &goto at_menu
if %_erl%==5 goto:retokens
if %_erl%==4 goto:fixwmi
if %_erl%==3 goto:sfcscan
@ -328,7 +283,7 @@ goto :at_menu
:dism_rest
cls
if not defined terminal mode 98, 30
mode 98, 30
title Dism /English /Online /Cleanup-Image /RestoreHealth
if %winbuild% LSS 9200 (
@ -347,7 +302,7 @@ echo:
if defined _int (
echo Checking Internet Connection [Connected]
) else (
call :dk_color2 %_White% " " %Red% "Checking Internet Connection [Not connected]"
call :_color2 %_White% " " %Red% "Checking Internet Connection [Not connected]"
)
echo %line%
@ -358,8 +313,8 @@ echo %line%
echo:
echo Notes:
echo:
call :dk_color2 %_White% " - " %Gray% "Make sure the Internet is connected."
call :dk_color2 %_White% " - " %Gray% "Make sure the Windows update is properly working."
call :_color2 %_White% " - " %Gray% "Make sure the Internet is connected."
call :_color2 %_White% " - " %Gray% "Make sure the Windows update is properly working."
echo:
echo %line%
echo:
@ -367,29 +322,22 @@ choice /C:09 /N /M "> [9] Continue [0] Go back : "
if %errorlevel%==1 goto at_menu
cls
if not defined terminal mode 110, 30
for /f %%a in ('%psc% "(Get-Date).ToString('yyyyMMdd-HHmmssfff')"') do set _time=%%a
mode 110, 30
%psc% Stop-Service TrustedInstaller -force %nul%
copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\backup_cbs_%_time%.log" %nul%
copy /y /b "%SystemRoot%\logs\DISM\dism.log" "%SystemRoot%\logs\DISM\backup_dism_%_time%.log" %nul%
del /f /q "%SystemRoot%\logs\cbs\cbs.log" %nul%
del /f /q "%SystemRoot%\logs\DISM\dism.log" %nul%
set _time=
for /f %%a in ('%psc% "Get-Date -format HH_mm_ss"') do set _time=%%a
echo:
echo Applying the command,
echo dism /english /online /cleanup-image /restorehealth
dism /english /online /cleanup-image /restorehealth
timeout /t 5 %nul1%
copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\cbs_%_time%.log" %nul%
copy /y /b "%SystemRoot%\logs\DISM\dism.log" "%SystemRoot%\logs\DISM\dism_%_time%.log" %nul%
%psc% Stop-Service TrustedInstaller -force %nul%
if not exist "!desktop!\AT_Logs\" md "!desktop!\AT_Logs\" %nul%
call :compresslog cbs\cbs_%_time%.log AT_Logs\RHealth_CBS %nul%
call :compresslog DISM\dism_%_time%.log AT_Logs\RHealth_DISM %nul%
call :compresslog cbs\CBS.log RHealth_CBS %nul%
call :compresslog DISM\dism.log RHealth_DISM %nul%
if not exist "!desktop!\AT_Logs\RHealth_CBS_%_time%.cab" (
copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "!desktop!\AT_Logs\RHealth_CBS_%_time%.log" %nul%
@ -400,7 +348,7 @@ copy /y /b "%SystemRoot%\logs\DISM\dism.log" "!desktop!\AT_Logs\RHealth_DISM_%_t
)
echo:
call :dk_color %Gray% "CBS and DISM logs are copied to the AT_Logs folder on the desktop."
call :_color %Gray% "CBS and DISM logs are copied to the AT_Logs folder on the dekstop."
goto :at_back
::========================================================================================================================================
@ -408,7 +356,7 @@ goto :at_back
:sfcscan
cls
if not defined terminal mode 98, 30
mode 98, 30
title sfc /scannow
echo:
@ -427,30 +375,27 @@ choice /C:09 /N /M "> [9] Continue [0] Go back : "
if %errorlevel%==1 goto at_menu
cls
for /f %%a in ('%psc% "(Get-Date).ToString('yyyyMMdd-HHmmssfff')"') do set _time=%%a
%psc% Stop-Service TrustedInstaller -force %nul%
copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\backup_cbs_%_time%.log" %nul%
del /f /q "%SystemRoot%\logs\cbs\cbs.log" %nul%
set _time=
for /f %%a in ('%psc% "Get-Date -format HH_mm_ss"') do set _time=%%a
echo:
echo Applying the command,
echo sfc /scannow
sfc /scannow
timeout /t 5 %nul1%
copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\cbs_%_time%.log" %nul%
%psc% Stop-Service TrustedInstaller -force %nul%
if not exist "!desktop!\AT_Logs\" md "!desktop!\AT_Logs\" %nul%
call :compresslog cbs\cbs_%_time%.log AT_Logs\SFC_CBS %nul%
call :compresslog cbs\CBS.log SFC_CBS %nul%
if not exist "!desktop!\AT_Logs\SFC_CBS_%_time%.cab" (
copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "!desktop!\AT_Logs\SFC_CBS_%_time%.log" %nul%
)
echo:
call :dk_color %Gray% "CBS log is copied to the AT_Logs folder on the desktop."
call :_color %Gray% "CBS log is copied to the AT_Logs folder on the dekstop."
goto :at_back
::========================================================================================================================================
@ -458,10 +403,8 @@ goto :at_back
:retokens
cls
if not defined terminal (
mode 125, 32
mode con cols=125 lines=32
%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;}"
)
title Fix Licensing ^(ClipSVC ^+ Office vNext ^+ SPP ^+ OSPP^)
echo:
@ -479,7 +422,7 @@ echo - Clear ClipSVC, Office vNext, SPP and OSPP licenses
echo - Fix SPP permissions of tokens folder and registries
echo - Trigger the repair option for Office.
echo:
call :dk_color2 %_White% " - " %Red% "Apply it only when it is necessary."
call :_color2 %_White% " - " %Red% "Apply it only when it is necessary."
echo:
echo %line%
echo:
@ -496,19 +439,19 @@ cls
echo:
echo %line%
echo:
call :dk_color %Blue% "Rebuilding ClipSVC Licences"
call :_color %Blue% "Rebuilding ClipSVC Licences"
echo:
if %winbuild% LSS 10240 (
echo ClipSVC Licence rebuilding is supported only on Win 10/11 and Server equivalent.
echo Skipping...
goto :rebuildspptok
goto :cleanvnext
)
%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% && (
%psc% "(([WMISEARCHER]'SELECT Name FROM SoftwareLicensingProduct WHERE LicenseStatus=1 AND GracePeriodRemaining=0 AND PartialProductKey IS NOT NULL').Get()).Name" %nul2% | findstr /i "Windows" %nul1% && (
echo Windows is permanently activated.
echo Skipping...
goto :rebuildspptok
echo Skipping rebuilding ClipSVC licences...
goto :cleanvnext
)
echo Stopping ClipSVC service...
@ -525,7 +468,7 @@ if %winbuild% LEQ 10240 (
echo [Successful]
) else (
if exist "%ProgramData%\Microsoft\Windows\ClipSVC\tokens.dat" (
call :dk_color %Red% "[Failed]"
call :_color %Red% "[Failed]"
) else (
echo [Successful]
)
@ -544,7 +487,7 @@ echo:
echo Deleting a Volatile ^& Protected Registry Key...
echo [%RegKey%]
reg query "%RegKey%" %nul% && (
call :dk_color %Red% "[Failed]"
call :_color %Red% "[Failed]"
echo Restart the system, that will delete this registry key automatically.
) || (
echo [Successful]
@ -557,7 +500,7 @@ echo Deleting a IdentityCRL Registry Key...
echo [%_ident%]
reg delete "%_ident%" /f %nul%
reg query "%_ident%" %nul% && (
call :dk_color %Red% "[Failed]"
call :_color %Red% "[Failed]"
) || (
echo [Successful]
)
@ -572,7 +515,7 @@ echo Deleting Folder %ProgramData%\Microsoft\Windows\ClipSVC\
rmdir /s /q "C:\ProgramData\Microsoft\Windows\ClipSvc" %nul%
if exist "%ProgramData%\Microsoft\Windows\ClipSVC\" (
call :dk_color %Red% "[Failed]"
call :_color %Red% "[Failed]"
) else (
echo [Successful]
)
@ -583,7 +526,7 @@ echo Rebuilding Folder %ProgramData%\Microsoft\Windows\ClipSVC\
timeout /t 3 %nul%
if not exist "%ProgramData%\Microsoft\Windows\ClipSVC\" timeout /t 5 %nul%
if not exist "%ProgramData%\Microsoft\Windows\ClipSVC\" (
call :dk_color %Red% "[Failed]"
call :_color %Red% "[Failed]"
) else (
echo [Successful]
)
@ -591,28 +534,100 @@ echo [Successful]
echo:
echo Restarting [wlidsvc LicenseManager] services...
for %%# in (wlidsvc LicenseManager) do (%psc% "Start-Job { Restart-Service %%# } | Wait-Job -Timeout 10 | Out-Null")
for %%# in (wlidsvc LicenseManager) do (%psc% Restart-Service %%# %nul%)
::========================================================================================================================================
:: Find remnants of Office vNext license block and remove it because it stops non vNext licenses from appearing
:: https://learn.microsoft.com/en-us/office/troubleshoot/activation/reset-office-365-proplus-activation-state
:cleanvnext
echo:
echo %line%
echo:
call :_color %Blue% "Clearing Office vNext License"
echo:
setlocal DisableDelayedExpansion
set "_Local=%LocalAppData%"
setlocal EnableDelayedExpansion
attrib -R "!ProgramData!\Microsoft\Office\Licenses" %nul%
attrib -R "!_Local!\Microsoft\Office\Licenses" %nul%
if exist "!ProgramData!\Microsoft\Office\Licenses\" (
rd /s /q "!ProgramData!\Microsoft\Office\Licenses\" %nul%
if exist "!ProgramData!\Microsoft\Office\Licenses\" (
echo Failed To Delete - !ProgramData!\Microsoft\Office\Licenses\
) else (
echo Deleted Folder - !ProgramData!\Microsoft\Office\Licenses\
)
) else (
echo Not Found - !ProgramData!\Microsoft\Office\Licenses\
)
if exist "!_Local!\Microsoft\Office\Licenses\" (
rd /s /q "!_Local!\Microsoft\Office\Licenses\" %nul%
if exist "!_Local!\Microsoft\Office\Licenses\" (
echo Failed To Delete - !_Local!\Microsoft\Office\Licenses\
) else (
echo Deleted Folder - !_Local!\Microsoft\Office\Licenses\
)
) else (
echo Not Found - !_Local!\Microsoft\Office\Licenses\
)
echo:
for /f "tokens=* delims=" %%a in ('%psc% "Get-ChildItem -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList' | ForEach-Object { Split-Path -Path $_.PSPath -Leaf }" %nul6%') do (if defined _sid (set "_sid=!_sid! HKU\%%a") else (set "_sid=HKU\%%a"))
set regfound=
for %%# in (HKCU !_sid!) do (
for %%A in (
%%#\Software\Microsoft\Office\16.0\Common\Licensing
%%#\Software\Microsoft\Office\16.0\Common\Identity
%%#\Software\Microsoft\Office\16.0\Registration
) do (
reg query %%A %nul% && (
set regfound=1
reg delete %%A /f %nul% && (
echo Deleted Registry - %%A
) || (
echo Failed to Delete - %%A
)
)
)
)
if not defined regfound echo Not Found - Office vNext Registry Keys
::========================================================================================================================================
:: Rebuild SPP Tokens
:rebuildspptok
echo:
echo %line%
echo:
call :dk_color %Blue% "Rebuilding SPP Licensing Tokens"
call :_color %Blue% "Rebuilding SPP Licensing Tokens"
echo:
call :scandat check
if not defined token (
call :dk_color %Red% "tokens.dat file not found."
call :_color %Red% "tokens.dat file not found."
) else (
echo tokens.dat file: [%token%]
)
echo:
set wpainfo=
for /f "delims=" %%a in ('%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':wpatest\:.*';iex ($f[1]);" %nul6%') do (set wpainfo=%%a)
echo "%wpainfo%" | find /i "Error Found" %nul% && (
call :_color %Red% "WPA Registry Error: %wpainfo%"
) || (
echo WPA Registry Count: %wpainfo%
)
set tokenstore=
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"
@ -647,7 +662,7 @@ set "d=!d! Set-Acl -Path '%%A' -AclObject $acl"
call :checkperms
if defined permerror (
call :dk_color %Red% "[Failed To Fix]"
call :_color %Red% "[Failed To Fix]"
) else (
echo [Successfully Fixed]
)
@ -666,7 +681,7 @@ call :scandat check
if defined token (
echo:
call :dk_color %Red% "Failed to delete .dat files."
call :_color %Red% "Failed to delete .dat files."
echo:
)
@ -677,14 +692,14 @@ if %errorlevel% NEQ 0 cscript //nologo %windir%\system32\slmgr.vbs /rilc %nul%
if %errorlevel% EQU 0 (
echo [Successful]
) else (
call :dk_color %Red% "[Failed]"
call :_color %Red% "[Failed]"
)
call :scandat check
echo:
if not defined token (
call :dk_color %Red% "Failed to rebuilt tokens.dat file."
call :_color %Red% "Failed to rebuilt tokens.dat file."
) else (
echo tokens.dat file was rebuilt successfully.
)
@ -696,7 +711,7 @@ echo tokens.dat file was rebuilt successfully.
echo:
echo %line%
echo:
call :dk_color %Blue% "Rebuilding OSPP Licensing Tokens"
call :_color %Blue% "Rebuilding OSPP Licensing Tokens"
echo:
sc qc osppsvc %nul% || (
@ -708,7 +723,7 @@ goto :repairoffice
call :scandatospp check
if not defined token (
call :dk_color %Red% "tokens.dat file not found."
call :_color %Red% "tokens.dat file not found."
) else (
echo tokens.dat file: [%token%]
)
@ -723,7 +738,7 @@ call :scandatospp check
if defined token (
echo:
call :dk_color %Red% "Failed to delete .dat files."
call :_color %Red% "Failed to delete .dat files."
echo:
)
@ -741,7 +756,7 @@ call :scandatospp check
echo:
if not defined token (
call :dk_color %Red% "Failed to rebuilt tokens.dat file."
call :_color %Red% "Failed to rebuilt tokens.dat file."
) else (
echo tokens.dat file was rebuilt successfully.
)
@ -753,7 +768,7 @@ echo tokens.dat file was rebuilt successfully.
echo:
echo %line%
echo:
call :dk_color %Blue% "Repairing Office Licenses"
call :_color %Blue% "Repairing Office Licenses"
echo:
for /f "skip=2 tokens=2*" %%a in ('reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE') do set arch=%%b
@ -842,8 +857,8 @@ goto :repairend
echo:
) else (
echo:
call :dk_color %_Yellow% "A Window will popup, in that Window you need to select [Quick] Repair Option..."
call :dk_color %_Yellow% "Press any key to continue..."
call :_color %_Yellow% "A Window will popup, in that Window you need to select [Quick] Repair Option..."
call :_color %_Yellow% "Press any key to continue..."
echo:
pause %nul1%
)
@ -887,7 +902,7 @@ echo:
echo %line%
echo:
echo:
call :dk_color %Green% "Finished"
call :_color %Green% "Finished"
goto :at_back
::========================================================================================================================================
@ -895,7 +910,7 @@ goto :at_back
:fixwmi
cls
if not defined terminal mode 98, 34
mode 98, 34
title Fix WMI
:: https://techcommunity.microsoft.com/t5/ask-the-performance-team/wmi-repository-corruption-or-not/ba-p/375484
@ -930,7 +945,7 @@ echo No need to apply this option. Aborting...
goto :at_back
)
call :dk_color %Red% "[Not Responding]"
call :_color %Red% "[Not Responding]"
set _corrupt=
sc start Winmgmt %nul%
@ -950,7 +965,7 @@ sc config Winmgmt start= disabled %nul%
if %errorlevel% EQU 0 (
echo [Successful]
) else (
call :dk_color %Red% "[Failed] Aborting..."
call :_color %Red% "[Failed] Aborting..."
sc config Winmgmt start= auto %nul%
goto :at_back
)
@ -963,9 +978,9 @@ echo Stopping Winmgmt service
sc query Winmgmt | find /i "STOPPED" %nul% && (
echo [Successful]
) || (
call :dk_color %Red% "[Failed]"
call :_color %Red% "[Failed]"
echo:
call :dk_color %Blue% "Its recommended to select [Restart] option and then apply Fix WMI option again."
call :_color %Blue% "Its recommended to select [Restart] option and then apply Fix WMI option again."
echo %line%
echo:
choice /C:21 /N /M "> [1] Restart [2] Revert Back Changes :"
@ -980,7 +995,7 @@ echo:
echo Deleting WMI repository
rmdir /s /q "%windir%\System32\wbem\repository\" %nul%
if exist "%windir%\System32\wbem\repository\" (
call :dk_color %Red% "[Failed]"
call :_color %Red% "[Failed]"
) else (
echo [Successful]
)
@ -991,14 +1006,14 @@ sc config Winmgmt start= auto %nul%
if %errorlevel% EQU 0 (
echo [Successful]
) else (
call :dk_color %Red% "[Failed]"
call :_color %Red% "[Failed]"
)
call :checkwmi
if not defined error (
echo:
echo Checking WMI
call :dk_color %Green% "[Working]"
call :_color %Green% "[Working]"
goto :at_back
)
@ -1010,11 +1025,11 @@ echo:
echo Checking WMI
call :checkwmi
if defined error (
call :dk_color %Red% "[Not Responding]"
call :_color %Red% "[Not Responding]"
echo:
echo Run [Dism RestoreHealth] and [SFC Scannow] options and make sure there are no errors.
) else (
call :dk_color %Green% "[Working]"
call :_color %Green% "[Working]"
)
goto :at_back
@ -1062,12 +1077,21 @@ exit /b
echo:
echo %line%
echo:
call :dk_color %_Yellow% "Press any key to go back..."
call :_color %_Yellow% "Press any key to go back..."
pause %nul1%
goto :at_menu
::========================================================================================================================================
:at_done
echo:
echo Press any key to %_exitmsg%...
pause %nul1%
exit /b
::========================================================================================================================================
:compresslog
:: https://stackoverflow.com/a/46268232
@ -1094,12 +1118,50 @@ echo/.set UniqueFiles=ON>>%ddf%
for /f "tokens=* delims=" %%D in ('dir /a:-D/b/s "%SystemRoot%\logs\%1"') do (
echo/"%%~fD" /inf=no;>>%ddf%
)
makecab /F %ddf% /D DiskDirectory1="" /D CabinetNameTemplate="!desktop!\%2_%_time%.cab"
makecab /F %ddf% /D DiskDirectory1="" /D CabinetNameTemplate="!desktop!\AT_Logs\%2_%_time%.cab"
del /q /f %ddf%
exit /b
::========================================================================================================================================
:: This code checks for invalid registry keys in HKLM\SYSTEM\WPA. This issue may appear even on healthy systems
:wpatest:
$wpaKey = [Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine', 'Registry64').OpenSubKey("SYSTEM\\WPA")
$count = $wpaKey.SubKeyCount
$osVersion = [System.Environment]::OSVersion.Version
$minBuildNumber = 14393
if ($osVersion.Build -ge $minBuildNumber) {
$subkeyHashTable = @{}
foreach ($subkeyName in $wpaKey.GetSubKeyNames()) {
$keyNumber = $subkeyName -replace '.*-', ''
$subkeyHashTable[$keyNumber] = $true
}
for ($i=1; $i -le $count; $i++) {
if (-not $subkeyHashTable.ContainsKey("$i")) {
Write-Host "Total Keys $count. Error Found- $i key does not exist"
$wpaKey.Close()
exit
}
}
}
$wpaKey.GetSubKeyNames() | ForEach-Object {
$subkey = $wpaKey.OpenSubKey($_)
$p = $subkey.GetValueNames()
if (($p | Where-Object { $subkey.GetValueKind($_) -eq [Microsoft.Win32.RegistryValueKind]::Binary }).Count -eq 0) {
Write-Host "Total Keys $count. Error Found- Binary Data is corrupt"
$wpaKey.Close()
exit
}
}
$count
$wpaKey.Close()
:wpatest:
::========================================================================================================================================
:checkperms
set permerror=
@ -1200,88 +1262,106 @@ $key.SetAccessControl($acl)
::========================================================================================================================================
:dk_done
echo:
if defined fixes (
call :dk_color2 %Blue% "Press [1] To Open Troubleshoot Page " %Gray% " Press [0] To Ignore"
choice /C:10 /N
if !errorlevel!==1 (for %%# in (%fixes%) do (start %%#))
)
if defined terminal (
call :dk_color %_Yellow% "Press 0 key to %_exitmsg%..."
choice /c 0 /n
) else (
call :dk_color %_Yellow% "Press any key to %_exitmsg%..."
pause %nul1%
)
exit /b
::========================================================================================================================================
:dk_color
:_color
if %_NCS% EQU 1 (
echo %esc%[%~1%~2%esc%[0m
) else (
if not exist %psc% (echo %~3) else (%psc% write-host -back '%1' -fore '%2' '%3')
call :batcol %~1 "%~2"
)
exit /b
:dk_color2
:_color2
if %_NCS% EQU 1 (
echo %esc%[%~1%~2%esc%[%~3%~4%esc%[0m
) else (
if not exist %psc% (echo %~3%~6) else (%psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6')
call :batcol %~1 "%~2" %~3 "%~4"
)
exit /b
::========================================================================================================================================
::=======================================
:: Set variables
:: Colored text with pure batch method
:: Thanks to @dbenham and @jeb
:: stackoverflow.com/a/10407642
:dk_setvar
:batcol
set psc=powershell.exe
set winbuild=1
for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G
pushd %_coltemp%
if not exist "'" (<nul >"'" set /p "=.")
setlocal
set "s=%~2"
set "t=%~4"
call :_batcol %1 s %3 t
del /f /q "'"
del /f /q "`.txt"
popd
exit /b
set _NCS=1
if %winbuild% LSS 10586 set _NCS=0
if %winbuild% GEQ 10586 reg query "HKCU\Console" /v ForceV2 %nul2% | find /i "0x0" %nul1% && (set _NCS=0)
:_batcol
setlocal EnableDelayedExpansion
set "s=!%~2!"
set "t=!%~4!"
for /f delims^=^ eol^= %%i in ("!s!") do (
if "!" equ "" setlocal DisableDelayedExpansion
>`.txt (echo %%i\..\')
findstr /a:%~1 /f:`.txt "."
<nul set /p "=%_BS%%_BS%%_BS%%_BS%%_BS%%_BS%%_BS%"
)
if "%~4"=="" echo(&exit /b
setlocal EnableDelayedExpansion
for /f delims^=^ eol^= %%i in ("!t!") do (
if "!" equ "" setlocal DisableDelayedExpansion
>`.txt (echo %%i\..\')
findstr /a:%~3 /f:`.txt "."
<nul set /p "=%_BS%%_BS%%_BS%%_BS%%_BS%%_BS%%_BS%"
)
echo(
exit /b
::=======================================
:_colorprep
if %_NCS% EQU 1 (
for /F %%a in ('echo prompt $E ^| cmd') do set "esc=%%a"
set "Red="41;97m""
set "Gray="100;97m""
set "Black="30m""
set "Green="42;97m""
set "Blue="44;97m""
set "Yellow="43;97m""
set "Magenta="45;97m""
set "_Red="40;91m""
set "_White="40;37m""
set "_Green="40;92m""
set "_Blue="40;94m""
set "_White="40;37m""
set "_Yellow="40;93m""
) else (
set "Red="Red" "white""
set "Gray="Darkgray" "white""
set "Green="DarkGreen" "white""
set "Blue="Blue" "white""
set "_Red="Black" "Red""
set "_White="Black" "Gray""
set "_Green="Black" "Green""
set "_Yellow="Black" "Yellow""
exit /b
)
set "nceline=echo: &echo ==== ERROR ==== &echo:"
set "eline=echo: &call :dk_color %Red% "==== ERROR ====" &echo:"
if %~z0 GEQ 200000 (
set "_exitmsg=Go back"
set "_fixmsg=Go back to Main Menu, select Troubleshoot and run Fix Licensing option."
) else (
set "_exitmsg=Exit"
set "_fixmsg=In MAS folder, run Troubleshoot script and select Fix Licensing option."
)
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "_BS=%%A %%A"
set "_coltemp=%SystemRoot%\Temp"
set "Red="CF""
set "Gray="8F""
set "Black="00""
set "Green="2F""
set "Blue="1F""
set "Yellow="6F""
set "Magenta="5F""
set "_Red="0C""
set "_Green="0A""
set "_Blue="09""
set "_White="07""
set "_Yellow="0E""
exit /b
::========================================================================================================================================