diff options
Diffstat (limited to 'MAS/Separate-Files-Version/Troubleshoot.cmd')
| -rw-r--r-- | MAS/Separate-Files-Version/Troubleshoot.cmd | 919 |
1 files changed, 508 insertions, 411 deletions
diff --git a/MAS/Separate-Files-Version/Troubleshoot.cmd b/MAS/Separate-Files-Version/Troubleshoot.cmd index 1317df5..46021c3 100644 --- a/MAS/Separate-Files-Version/Troubleshoot.cmd +++ b/MAS/Separate-Files-Version/Troubleshoot.cmd @@ -1,15 +1,12 @@ -@set masver=2.6
-@setlocal DisableDelayedExpansion
+@set masver=2.7
@echo off
::============================================================================
::
-:: This script is a part of 'Microsoft-Activation-Scripts' (MAS) project.
-::
:: Homepage: mass grave[.]dev
-:: Email: [email protected]
+:: Email: [email protected]
::
::============================================================================
@@ -17,26 +14,32 @@ ::========================================================================================================================================
-:: Set Path variable, it helps if it is misconfigured in the system
+:: Set environment variables, it helps if they are misconfigured in the system
+
+setlocal EnableExtensions
+setlocal DisableDelayedExpansion
+
+set "PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC"
-set "PATH=%SystemRoot%\System32;%SystemRoot%\System32\wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\"
+set "SysPath=%SystemRoot%\System32"
+set "Path=%SystemRoot%\System32;%SystemRoot%;%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 "SysPath=%SystemRoot%\Sysnative"
+set "Path=%SystemRoot%\Sysnative;%SystemRoot%;%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
+set "ComSpec=%SysPath%\cmd.exe"
+set "PSModulePath=%ProgramFiles%\WindowsPowerShell\Modules;%SysPath%\WindowsPowerShell\v1.0\Modules"
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
start %SystemRoot%\Sysnative\cmd.exe /c ""!_cmdf!" %* r1"
@@ -64,10 +67,10 @@ echo: echo Null service is not running, script may crash...
echo:
echo:
-echo Help - %mas%troubleshoot.html
+echo Help - %mas%troubleshoot
echo:
echo:
-ping 127.0.0.1 -n 10
+ping 127.0.0.1 -n 20
)
cls
@@ -76,9 +79,13 @@ 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:
-ping 127.0.0.1 -n 6 >nul
+echo:
+ping 127.0.0.1 -n 20 >nul
popd
exit /b
)
@@ -92,6 +99,7 @@ title Troubleshoot %masver% set _args=
set _elev=
+set _unattended=0
set _args=%*
if defined _args set _args=%_args:"=%
@@ -106,39 +114,21 @@ set "nul2=2>nul" set "nul6=2^>nul"
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
-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:"
+call :dk_setvar
set "line=_________________________________________________________________________________________________"
-if %~z0 GEQ 200000 (set "_exitmsg=Go back") else (set "_exitmsg=Exit")
::========================================================================================================================================
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 at_done
-)
-
-for %%# in (powershell.exe) do @if "%%~$PATH:#"=="" (
-%nceline%
-echo Unable to find powershell.exe in the system.
-goto at_done
+echo Project is supported only for Windows 7/8/8.1/10/11 and their Server equivalents.
+goto dk_done
)
::========================================================================================================================================
-:: Fix special characters limitation in path name
+:: Fix special character limitations in path name
set "_work=%~dp0"
if "%_work:~-1%"=="\" set "_work=%_work:~0,-1%"
@@ -147,6 +137,7 @@ set "_batf=%~f0" set "_batp=%_batf:'=''%"
set _PSarg="""%~f0""" -el %_args%
+set _PSarg=%_PSarg:'=''%
set "_ttemp=%userprofile%\AppData\Local\Temp"
@@ -156,13 +147,39 @@ setlocal EnableDelayedExpansion echo "!_batf!" | find /i "!_ttemp!" %nul1% && (
if /i not "!_work!"=="!_ttemp!" (
-%nceline%
-echo Script is launched from the temp folder,
-echo Most likely you are running the script directly from the archive file.
+%eline%
+echo The script was launched from the temp folder.
+echo You are most likely running the script directly from the archive file.
echo:
echo Extract the archive file and launch the script from the extracted folder.
-goto at_done
+goto dk_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
)
::========================================================================================================================================
@@ -170,27 +187,54 @@ goto at_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
-%nceline%
+if not defined _elev %psc% "start cmd.exe -arg '/c \"!_PSarg!\"' -verb runas" && exit /b
+%eline%
echo This script needs admin rights.
-echo To do so, right click on this script and select 'Run as administrator'.
-goto at_done
+echo Right click on this script and select 'Run as administrator'.
+goto dk_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
+:: Disable QuickEdit and launch from conhost.exe to avoid Terminal app
-for %%# in (%_args%) do (if /i "%%#"=="-qedit" set quedit=1)
+if %winbuild% GEQ 17763 (
+set terminal=1
+) else (
+set terminal=
+)
-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
@@ -199,24 +243,25 @@ set -= set old=
for /f "delims=[] tokens=2" %%# in ('ping -4 -n 1 updatecheck.mass%-%grave.dev') do (
-if not [%%#]==[] (echo "%%#" | find "127.69" %nul1% && (echo "%%#" | find "127.69.%masver%" %nul1% || set old=1))
+if not "%%#"=="" (echo "%%#" | find "127.69" %nul1% && (echo "%%#" | find "127.69.%masver%" %nul1% || set old=1))
)
if defined old (
echo ________________________________________________
%eline%
-echo You are running outdated version MAS %masver%
+echo Your version of MAS [%masver%] is outdated.
echo ________________________________________________
echo:
+if not %_unattended%==1 (
echo [1] Get Latest MAS
echo [0] Continue Anyway
echo:
-call :_color %_Green% "Enter a menu option in the Keyboard [1,0] :"
+call :dk_color %_Green% "Choose a menu option using your 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
+)
::========================================================================================================================================
@@ -230,8 +275,8 @@ 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 at_done
+echo Unable to detect Desktop location, aborting...
+goto dk_done
)
setlocal EnableDelayedExpansion
@@ -243,7 +288,7 @@ setlocal EnableDelayedExpansion cls
color 07
title Troubleshoot %masver%
-mode con cols=77 lines=30
+if not defined terminal mode 77, 30
echo:
echo:
@@ -251,7 +296,7 @@ echo: echo:
echo: _______________________________________________________________
echo:
-call :_color2 %_White% " [1] " %_Green% "Help"
+call :dk_color2 %_White% " [1] " %_Green% "Help"
echo: ___________________________________________________
echo:
echo: [2] Dism RestoreHealth
@@ -265,12 +310,12 @@ echo: echo: [0] %_exitmsg%
echo: _______________________________________________________________
echo:
-call :_color2 %_White% " " %_Green% "Enter a menu option in the Keyboard :"
+call :dk_color2 %_White% " " %_Green% "Choose a menu option using your keyboard :"
choice /C:1234560 /N
set _erl=%errorlevel%
if %_erl%==7 exit /b
-if %_erl%==6 start %mas%fix-wpa-registry.html &goto at_menu
+if %_erl%==6 start %mas%fix-wpa-registry &goto at_menu
if %_erl%==5 goto:retokens
if %_erl%==4 goto:fixwmi
if %_erl%==3 goto:sfcscan
@@ -283,38 +328,38 @@ goto :at_menu :dism_rest
cls
-mode 98, 30
+if not defined terminal mode 98, 30
title Dism /English /Online /Cleanup-Image /RestoreHealth
if %winbuild% LSS 9200 (
%eline%
-echo Unsupported OS version Detected.
-echo This command is supported only for Windows 8/8.1/10/11 and their Server equivalent.
+echo Unsupported OS version detected.
+echo This command only works on Windows 8/8.1/10/11 and their Server equivalents.
goto :at_back
)
set _int=
for %%a in (l.root-servers.net resolver1.opendns.com download.windowsupdate.com google.com) do if not defined _int (
-for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do (if not [%%#]==[] set _int=1)
+for /f "delims=[] tokens=2" %%# in ('ping -n 1 %%a') do (if not "%%#"=="" set _int=1)
)
echo:
if defined _int (
echo Checking Internet Connection [Connected]
) else (
-call :_color2 %_White% " " %Red% "Checking Internet Connection [Not connected]"
+call :dk_color2 %_White% " " %Red% "Checking Internet Connection [Not connected]"
)
echo %line%
echo:
-echo Dism uses Windows Update to provide the files required to fix corruption.
+echo DISM uses Windows Update to provide replacement files required to fix corruption.
echo This will take 5-15 minutes or more..
echo %line%
echo:
echo Notes:
echo:
-call :_color2 %_White% " - " %Gray% "Make sure the Internet is connected."
-call :_color2 %_White% " - " %Gray% "Make sure the Windows update is properly working."
+call :dk_color2 %_White% " - " %Gray% "Make sure the internet is connected."
+call :dk_color2 %_White% " - " %Gray% "Make sure that Windows update is properly working."
echo:
echo %line%
echo:
@@ -322,22 +367,29 @@ choice /C:09 /N /M "> [9] Continue [0] Go back : " if %errorlevel%==1 goto at_menu
cls
-mode 110, 30
+if not defined terminal mode 110, 30
+
+for /f %%a in ('%psc% "(Get-Date).ToString('yyyyMMdd-HHmmssfff')"') do set _time=%%a
+
%psc% Stop-Service TrustedInstaller -force %nul%
-set _time=
-for /f %%a in ('%psc% "Get-Date -format HH_mm_ss"') do set _time=%%a
+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%
+
echo:
-echo Applying the command,
+echo Applying the command...
echo dism /english /online /cleanup-image /restorehealth
dism /english /online /cleanup-image /restorehealth
-%psc% Stop-Service TrustedInstaller -force %nul%
+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%
if not exist "!desktop!\AT_Logs\" md "!desktop!\AT_Logs\" %nul%
-
-call :compresslog cbs\CBS.log RHealth_CBS %nul%
-call :compresslog DISM\dism.log RHealth_DISM %nul%
+call :compresslog cbs\cbs_%_time%.log AT_Logs\RHealth_CBS %nul%
+call :compresslog DISM\dism_%_time%.log AT_Logs\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%
@@ -348,7 +400,7 @@ copy /y /b "%SystemRoot%\logs\DISM\dism.log" "!desktop!\AT_Logs\RHealth_DISM_%_t )
echo:
-call :_color %Gray% "CBS and DISM logs are copied to the AT_Logs folder on the dekstop."
+call :dk_color %Gray% "CBS and DISM logs are copied to the AT_Logs folder on your desktop."
goto :at_back
::========================================================================================================================================
@@ -356,13 +408,14 @@ goto :at_back :sfcscan
cls
-mode 98, 30
+if not defined terminal mode 98, 30
title sfc /scannow
echo:
echo %line%
echo:
-echo System File Checker will repair missing or corrupted system files.
+echo SFC will repair missing or corrupted system files.
+echo It is recommended you run the DISM option first before this one.
echo This will take 10-15 minutes or more..
echo:
echo If SFC could not fix something, then run the command again to see if it may be able
@@ -375,27 +428,30 @@ 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%
-set _time=
-for /f %%a in ('%psc% "Get-Date -format HH_mm_ss"') do set _time=%%a
+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%
+
echo:
-echo Applying the command,
+echo Applying the command...
echo sfc /scannow
sfc /scannow
-%psc% Stop-Service TrustedInstaller -force %nul%
+timeout /t 5 %nul1%
+copy /y /b "%SystemRoot%\logs\cbs\cbs.log" "%SystemRoot%\logs\cbs\cbs_%_time%.log" %nul%
if not exist "!desktop!\AT_Logs\" md "!desktop!\AT_Logs\" %nul%
-
-call :compresslog cbs\CBS.log SFC_CBS %nul%
+call :compresslog cbs\cbs_%_time%.log AT_Logs\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 :_color %Gray% "CBS log is copied to the AT_Logs folder on the dekstop."
+call :dk_color %Gray% "The CBS log was copied to the AT_Logs folder on your Desktop."
goto :at_back
::========================================================================================================================================
@@ -403,26 +459,29 @@ goto :at_back :retokens
cls
-mode con cols=125 lines=32
+if not defined terminal (
+mode 125, 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^)
+)
+title Fix Licensing ^(ClipSVC ^+ SPP ^+ OSPP^)
echo:
echo %line%
echo:
echo Notes:
echo:
-echo - It helps in troubleshooting activation issues.
+echo - This option helps in troubleshooting activation issues.
echo:
-echo - This option will,
-echo - Deactivate Windows and Office, you may need to reactivate
-echo If Windows is activated with motherboard / OEM / Digital license then don't worry
+echo - This option will:
+echo - Deactivate Windows and Office, you may need to reactivate.
+echo If Windows is activated with motherboard / OEM / Digital license
+echo then Windows will activate itself again.
echo:
-echo - Clear ClipSVC, Office vNext, SPP and OSPP licenses
-echo - Fix SPP permissions of tokens folder and registries
+echo - Clear ClipSVC, SPP and OSPP licenses.
+echo - Fix permissions of SPP tokens folder and registries.
echo - Trigger the repair option for Office.
echo:
-call :_color2 %_White% " - " %Red% "Apply it only when it is necessary."
+call :dk_color2 %_White% " - " %Red% "Apply this option only when it is necessary."
echo:
echo %line%
echo:
@@ -439,19 +498,19 @@ cls echo:
echo %line%
echo:
-call :_color %Blue% "Rebuilding ClipSVC Licences"
+call :dk_color %Blue% "Rebuilding ClipSVC Licenses..."
echo:
if %winbuild% LSS 10240 (
-echo ClipSVC Licence rebuilding is supported only on Win 10/11 and Server equivalent.
+echo ClipSVC license rebuilding is supported only on Windows 10/11 and their Server equivalents.
echo Skipping...
-goto :cleanvnext
+goto :rebuildspptok
)
-%psc% "(([WMISEARCHER]'SELECT Name FROM SoftwareLicensingProduct WHERE LicenseStatus=1 AND GracePeriodRemaining=0 AND PartialProductKey IS NOT 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 AND LicenseDependsOn is NULL').Get()).Name" %nul2% | findstr /i "Windows" %nul1% && (
echo Windows is permanently activated.
-echo Skipping rebuilding ClipSVC licences...
-goto :cleanvnext
+echo Skipping...
+goto :rebuildspptok
)
echo Stopping ClipSVC service...
@@ -459,7 +518,7 @@ echo Stopping ClipSVC service... timeout /t 2 %nul%
echo:
-echo Applying the command to Clean ClipSVC Licences...
+echo Applying the command to clean ClipSVC Licenses...
echo rundll32 clipc.dll,ClipCleanUpState
rundll32 clipc.dll,ClipCleanUpState
@@ -468,7 +527,7 @@ if %winbuild% LEQ 10240 ( echo [Successful]
) else (
if exist "%ProgramData%\Microsoft\Windows\ClipSVC\tokens.dat" (
-call :_color %Red% "[Failed]"
+call :dk_color %Red% "[Failed]"
) else (
echo [Successful]
)
@@ -487,20 +546,20 @@ echo: echo Deleting a Volatile ^& Protected Registry Key...
echo [%RegKey%]
reg query "%RegKey%" %nul% && (
-call :_color %Red% "[Failed]"
-echo Restart the system, that will delete this registry key automatically.
+call :dk_color %Red% "[Failed]"
+echo Reboot your machine using the restart option, that will delete this registry key automatically.
) || (
echo [Successful]
)
-:: Clear HWID token related registry to fix activation incase if there is any corruption
+:: Clear HWID token related registry to fix activation incase there is any corruption
echo:
-echo Deleting a IdentityCRL Registry Key...
+echo Deleting IdentityCRL Registry Key...
echo [%_ident%]
reg delete "%_ident%" /f %nul%
reg query "%_ident%" %nul% && (
-call :_color %Red% "[Failed]"
+call :dk_color %Red% "[Failed]"
) || (
echo [Successful]
)
@@ -511,160 +570,74 @@ echo [Successful] echo:
if %winbuild% GTR 10240 (
-echo Deleting Folder %ProgramData%\Microsoft\Windows\ClipSVC\
+echo Deleting folder %ProgramData%\Microsoft\Windows\ClipSVC\
rmdir /s /q "C:\ProgramData\Microsoft\Windows\ClipSvc" %nul%
if exist "%ProgramData%\Microsoft\Windows\ClipSVC\" (
-call :_color %Red% "[Failed]"
+call :dk_color %Red% "[Failed]"
) else (
echo [Successful]
)
echo:
-echo Rebuilding Folder %ProgramData%\Microsoft\Windows\ClipSVC\
+echo Rebuilding the %ProgramData%\Microsoft\Windows\ClipSVC\ folder...
%psc% Start-Service ClipSVC %nul%
timeout /t 3 %nul%
if not exist "%ProgramData%\Microsoft\Windows\ClipSVC\" timeout /t 5 %nul%
if not exist "%ProgramData%\Microsoft\Windows\ClipSVC\" (
-call :_color %Red% "[Failed]"
+call :dk_color %Red% "[Failed]"
) else (
echo [Successful]
)
)
echo:
-echo Restarting [wlidsvc LicenseManager] services...
-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
+echo Restarting wlidsvc ^& LicenseManager services...
+for %%# in (wlidsvc LicenseManager) do (%psc% "Start-Job { Restart-Service %%# } | Wait-Job -Timeout 10 | Out-Null")
::========================================================================================================================================
:: Rebuild SPP Tokens
+:rebuildspptok
+
echo:
echo %line%
echo:
-call :_color %Blue% "Rebuilding SPP Licensing Tokens"
+call :dk_color %Blue% "Rebuilding SPP licensing tokens..."
echo:
call :scandat check
if not defined token (
-call :_color %Red% "tokens.dat file not found."
+call :dk_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=
+set badregistry=
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"
+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" (
+set badregistry=1
+echo:
+call :dk_color %Red% "Correct path not found in TokenStore Registry [%tokenstore%]"
+)
:: Check sppsvc permissions and apply fixes
-if %winbuild% GEQ 10240 (
-
+if %winbuild% GEQ 9200 if not defined badregistry (
echo:
echo Checking SPP permission related issues...
call :checkperms
-
if defined permerror (
-
-mkdir "%tokenstore%" %nul%
-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)';"
-set "d=!d! $AclObject = New-Object System.Security.AccessControl.DirectorySecurity;"
-set "d=!d! $AclObject.SetSecurityDescriptorSddlForm($sddl);"
-set "d=!d! Set-Acl -Path %tokenstore% -AclObject $AclObject;"
-%psc% "!d!" %nul%
-
-for %%# in (
-"HKLM:\SYSTEM\WPA_QueryValues, EnumerateSubKeys, WriteKey"
-"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform_SetValue"
-) do for /f "tokens=1,2 delims=_" %%A in (%%#) do (
-set "d=$acl = Get-Acl '%%A';"
-set "d=!d! $rule = New-Object System.Security.AccessControl.RegistryAccessRule ('NT Service\sppsvc', '%%B', 'ContainerInherit, ObjectInherit','None','Allow');"
-set "d=!d! $acl.ResetAccessRule($rule);"
-set "d=!d! $acl.SetAccessRule($rule);"
-set "d=!d! Set-Acl -Path '%%A' -AclObject $acl"
-%psc% "!d!" %nul%
-)
-
+call :dk_color %Red% "[!permerror!]"
+%psc% "$f=[io.file]::ReadAllText('!_batp!') -split ':fixsppperms\:.*';iex ($f[1])" %nul%
call :checkperms
if defined permerror (
-call :_color %Red% "[Failed To Fix]"
+call :dk_color %Red% "[!permerror!] [Failed To Fix]"
) else (
-echo [Successfully Fixed]
+call :dk_color %Green% "[Successfully Fixed]"
)
) else (
echo [No Error Found]
@@ -675,35 +648,75 @@ echo: echo Stopping sppsvc service...
%psc% Stop-Service sppsvc -force %nul%
+set w=
+set _sppint=
+for %%# in (SppEx%w%tComObj.exe sppsvc.exe) do (reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ima%w%ge File Execu%w%tion Options\%%#" %nul% && (set _sppint=1))
+if defined _sppint (
+echo:
+echo Removing SPP IFEO registry keys...
+for %%# in (SppE%w%xtComObj.exe sppsvc.exe) do (reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Ima%w%ge File Execu%w%tion Options\%%#" /f %nul%)
+)
+
+if %winbuild% LSS 9200 (
+REM Fix issues caused by Update KB971033 in Windows 7
+REM https://support.microsoft.com/help/4487266
+echo:
+echo Checking Update KB971033...
+%psc% "if (Get-Hotfix -Id KB971033 -ErrorAction SilentlyContinue) {Exit 3}" %nul%
+if !errorlevel!==3 (
+echo Found, uninstalling it...
+wusa /uninstall /quiet /norestart /kb:971033
+) else (
+echo [Not Found]
+)
+%psc% Stop-Service sppuinotify -force %nul%
+sc config sppuinotify start= disabled
+del /f /q %SysPath%\7B296FB0-376B-497e-B012-9C450E1B7327-*.C7483456-A289-439d-8115-601632D005A0 /ah
+)
+
+:: Delete registry keys that are not deleted by activation scripts
+
+echo:
+echo Cleaning some licensing-related registry keys...
+%nul% reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "ServiceSessionId" /f
+%nul% reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "LicStatusArray" /f
+%nul% reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "PolicyValuesArray" /f
+%nul% reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" /v "actionlist" /f
+%nul% reg delete "HKLM\SOFTWARE\Microsoft\OfficeSoftwareProtectionPlatform\data" /f
+
echo:
call :scandat delete
call :scandat check
if defined token (
echo:
-call :_color %Red% "Failed to delete .dat files."
+call :dk_color %Red% "Failed to delete .dat files."
echo:
)
echo:
-echo Reinstalling System Licenses [slmgr /rilc]...
-cscript //nologo %windir%\system32\slmgr.vbs /rilc %nul%
-if %errorlevel% NEQ 0 cscript //nologo %windir%\system32\slmgr.vbs /rilc %nul%
+echo Reinstalling system licenses...
+%psc% "Stop-Service sppsvc -force; $sls = Get-WmiObject SoftwareLicensingService; $f=[io.file]::ReadAllText('!_batp!') -split ':xrm\:.*';iex ($f[1]); ReinstallLicenses" %nul%
+if %errorlevel% NEQ 0 %psc% "$sls = Get-WmiObject SoftwareLicensingService; $f=[io.file]::ReadAllText('!_batp!') -split ':xrm\:.*';iex ($f[1]); ReinstallLicenses" %nul%
if %errorlevel% EQU 0 (
echo [Successful]
) else (
-call :_color %Red% "[Failed]"
+call :dk_color %Red% "[Failed]"
)
call :scandat check
echo:
if not defined token (
-call :_color %Red% "Failed to rebuilt tokens.dat file."
+call :dk_color %Red% "Failed to rebuild tokens.dat file."
) else (
echo tokens.dat file was rebuilt successfully.
)
+if %winbuild% LSS 9200 (
+sc config sppuinotify start= demand
+)
+
::========================================================================================================================================
:: Rebuild OSPP Tokens
@@ -711,11 +724,11 @@ echo tokens.dat file was rebuilt successfully. echo:
echo %line%
echo:
-call :_color %Blue% "Rebuilding OSPP Licensing Tokens"
+call :dk_color %Blue% "Rebuilding OSPP licensing tokens..."
echo:
sc qc osppsvc %nul% || (
-echo OSPP based Office is not installed
+echo OSPP-based Office is not installed.
echo Skipping rebuilding OSPP tokens...
goto :repairoffice
)
@@ -723,7 +736,7 @@ goto :repairoffice call :scandatospp check
if not defined token (
-call :_color %Red% "tokens.dat file not found."
+call :dk_color %Red% "tokens.dat file not found."
) else (
echo tokens.dat file: [%token%]
)
@@ -738,12 +751,12 @@ call :scandatospp check if defined token (
echo:
-call :_color %Red% "Failed to delete .dat files."
+call :dk_color %Red% "Failed to delete .dat files."
echo:
)
echo:
-echo Starting osppsvc service to generate tokens.dat
+echo Starting osppsvc service to generate tokens.dat...
%psc% Start-Service osppsvc %nul%
call :scandatospp check
if not defined token (
@@ -756,7 +769,7 @@ call :scandatospp check echo:
if not defined token (
-call :_color %Red% "Failed to rebuilt tokens.dat file."
+call :dk_color %Red% "Failed to rebuild tokens.dat file."
) else (
echo tokens.dat file was rebuilt successfully.
)
@@ -768,20 +781,11 @@ echo tokens.dat file was rebuilt successfully. echo:
echo %line%
echo:
-call :_color %Blue% "Repairing Office Licenses"
+call :dk_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
-if /i "%arch%"=="ARM64" (
-echo:
-echo ARM64 Windows Found.
-echo You need to use repair option in Windows settings for Office.
-echo:
-start ms-settings:appsfeatures
-goto :repairend
-)
-
if /i "%arch%"=="x86" (
set arch=X86
) else (
@@ -798,12 +802,12 @@ set _86=HKLM\SOFTWARE\Wow6432Node\Microsoft\Office reg query %_68%\14.0\CVH /f Click2run /k %nul% && (set "c2r14_68=Office 14.0 C2R x86/x64" & set "c2r14repair68=")
reg query %_86%\14.0\CVH /f Click2run /k %nul% && (set "c2r14_86=Office 14.0 C2R x86" & set "c2r14repair86=")
-for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi14_86=Office 14.0 MSI x86" & set "msi14repair86=%systemdrive%\Program Files (x86)\Common Files\Microsoft Shared\OFFICE14\Office Setup Controller\Setup.exe")
-for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi14_68=Office 14.0 MSI x86/x64" & set "msi14repair68=%systemdrive%\Program Files\Common Files\microsoft shared\OFFICE14\Office Setup Controller\Setup.exe")
-for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi15_86=Office 15.0 MSI x86" & set "msi15repair86=%systemdrive%\Program Files (x86)\Common Files\Microsoft Shared\OFFICE15\Office Setup Controller\Setup.exe")
-for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi15_68=Office 15.0 MSI x86/x64" & set "msi15repair68=%systemdrive%\Program Files\Common Files\microsoft shared\OFFICE15\Office Setup Controller\Setup.exe")
-for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi16_86=Office 16.0 MSI x86" & set "msi16repair86=%systemdrive%\Program Files (x86)\Common Files\Microsoft Shared\OFFICE16\Office Setup Controller\Setup.exe")
-for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi16_68=Office 16.0 MSI x86/x64" & set "msi16repair68=%systemdrive%\Program Files\Common Files\Microsoft Shared\OFFICE16\Office Setup Controller\Setup.exe")
+for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi14_86=Office 14.0 MSI x86" & call :getrepairsetup msi14repair86 14)
+for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\14.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi14_68=Office 14.0 MSI x86/x64" & call :getrepairsetup msi14repair68 14)
+for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi15_86=Office 15.0 MSI x86" & call :getrepairsetup msi15repair86 15)
+for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\15.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi15_68=Office 15.0 MSI x86/x64" & call :getrepairsetup msi15repair68 15)
+for /f "skip=2 tokens=2*" %%a in ('"reg query %_86%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi16_86=Office 16.0 MSI x86" & call :getrepairsetup msi16repair86 16)
+for /f "skip=2 tokens=2*" %%a in ('"reg query %_68%\16.0\Common\InstallRoot /v Path" %nul6%') do if exist "%%b\EntityPicker.dll" (set "msi16_68=Office 16.0 MSI x86/x64" & call :getrepairsetup msi16repair68 16)
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" & set "c2r15repair86=%systemdrive%\Program Files\Microsoft Office 15\Client%arch%\integratedoffice.exe")
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" & set "c2r15repair68=%systemdrive%\Program Files\Microsoft Office 15\Client%arch%\integratedoffice.exe")
@@ -844,29 +848,33 @@ set /a counter+=1 if %counter% GTR 1 (
%eline%
-echo Multiple office versions found.
-echo It's recommended to install only one version of office.
+echo Multiple Office versions found.
+echo It is recommended to only install one version of Office.
echo ________________________________________________________________
echo:
)
if %counter% EQU 0 (
echo:
-echo Installed Office is not found.
+echo Office ^(2010 and later^) is not installed.
goto :repairend
echo:
) else (
echo:
-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:
+call :dk_color %_Yellow% "A new window will appear, in that window you need to select [Quick Repair] option."
+if defined terminal (
+call :dk_color %_Yellow% "Press [0] to continue..."
+choice /c 0 /n
+) else (
+call :dk_color %_Yellow% "Press any key to continue..."
pause %nul1%
)
+)
if defined uwp16 (
echo:
-echo Note: Skipping repair for Office 16.0 UWP.
-echo You need to use reset option in Windows settings for it.
+echo Note: Skipping repair for Office 16.0 UWP...
+echo You need to use the Reset option in Windows Settings instead.
echo ________________________________________________________________
echo:
start ms-settings:appsfeatures
@@ -878,8 +886,8 @@ if defined c2r14_86 set c2r14=1 if defined c2r14 (
echo:
-echo Note: Skipping repair for Office 14.0 C2R
-echo You need to use Repair option in Windows settings for it.
+echo Note: Skipping repair for Office 14.0 C2R...
+echo You need to use the Repair option in Windows Settings for it.
echo ________________________________________________________________
echo:
start appwiz.cpl
@@ -902,28 +910,31 @@ echo: echo %line%
echo:
echo:
-call :_color %Green% "Finished"
+call :dk_color %Green% "Finished"
goto :at_back
+:getrepairsetup
+
+set "_common86=%systemdrive%\Program Files (x86)\Common Files\Microsoft Shared\OFFICE%2\Office Setup Controller\setup.exe"
+set "_common68=%systemdrive%\Program Files\Common Files\Microsoft Shared\OFFICE%2\Office Setup Controller\setup.exe"
+
+if exist "%_common86%" set "%1=%_common86%"
+if exist "%_common68%" set "%1=%_common68%"
+exit /b
+
::========================================================================================================================================
:fixwmi
cls
-mode 98, 34
+if not defined terminal mode 98, 34
title Fix WMI
:: https://techcommunity.microsoft.com/t5/ask-the-performance-team/wmi-repository-corruption-or-not/ba-p/375484
if exist "%SystemRoot%\Servicing\Packages\Microsoft-Windows-Server*Edition~*.mum" (
%eline%
-echo WMI rebuild is not recommended on Windows Server. Aborting...
-goto :at_back
-)
-
-for %%# in (wmic.exe) do @if "%%~$PATH:#"=="" (
-%eline%
-echo wmic.exe file is not found in the system. Aborting...
+echo Rebuilding WMI is not recommended on Windows Server, aborting...
goto :at_back
)
@@ -941,11 +952,11 @@ call :checkwmi if not defined error (
echo [Working]
-echo No need to apply this option. Aborting...
+echo No need to apply this option, aborting...
goto :at_back
)
-call :_color %Red% "[Not Responding]"
+call :dk_color %Red% "[Not Responding]"
set _corrupt=
sc start Winmgmt %nul%
@@ -956,7 +967,7 @@ for %%G in (DependOnService Description DisplayName ErrorControl ImagePath Objec echo:
if defined _corrupt (
%eline%
-echo Winmgmt service is corrupted. Aborting...
+echo Winmgmt service is corrupted, aborting...
goto :at_back
)
@@ -965,7 +976,7 @@ sc config Winmgmt start= disabled %nul% if %errorlevel% EQU 0 (
echo [Successful]
) else (
-call :_color %Red% "[Failed] Aborting..."
+call :dk_color %Red% "[Failed] Aborting..."
sc config Winmgmt start= auto %nul%
goto :at_back
)
@@ -978,9 +989,9 @@ echo Stopping Winmgmt service sc query Winmgmt | find /i "STOPPED" %nul% && (
echo [Successful]
) || (
-call :_color %Red% "[Failed]"
+call :dk_color %Red% "[Failed]"
echo:
-call :_color %Blue% "Its recommended to select [Restart] option and then apply Fix WMI option again."
+call :dk_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 :"
@@ -993,9 +1004,9 @@ exit echo:
echo Deleting WMI repository
-rmdir /s /q "%windir%\System32\wbem\repository\" %nul%
-if exist "%windir%\System32\wbem\repository\" (
-call :_color %Red% "[Failed]"
+rmdir /s /q "%SysPath%\wbem\repository\" %nul%
+if exist "%SysPath%\wbem\repository\" (
+call :dk_color %Red% "[Failed]"
) else (
echo [Successful]
)
@@ -1006,14 +1017,14 @@ sc config Winmgmt start= auto %nul% if %errorlevel% EQU 0 (
echo [Successful]
) else (
-call :_color %Red% "[Failed]"
+call :dk_color %Red% "[Failed]"
)
call :checkwmi
if not defined error (
echo:
echo Checking WMI
-call :_color %Green% "[Working]"
+call :dk_color %Green% "[Working]"
goto :at_back
)
@@ -1025,11 +1036,11 @@ echo: echo Checking WMI
call :checkwmi
if defined error (
-call :_color %Red% "[Not Responding]"
+call :dk_color %Red% "[Not Responding]"
echo:
echo Run [Dism RestoreHealth] and [SFC Scannow] options and make sure there are no errors.
) else (
-call :_color %Green% "[Working]"
+call :dk_color %Green% "[Working]"
)
goto :at_back
@@ -1039,9 +1050,9 @@ goto :at_back :: https://eskonr.com/2012/01/how-to-fix-wmi-issues-automatically/
%psc% Stop-Service Winmgmt -force %nul%
-cd /d %systemroot%\system32\wbem\
-regsvr32 /s %systemroot%\system32\scecli.dll
-regsvr32 /s %systemroot%\system32\userenv.dll
+cd /d %SysPath%\wbem\
+regsvr32 /s %SysPath%\scecli.dll
+regsvr32 /s %SysPath%\userenv.dll
mofcomp cimwin32.mof
mofcomp cimwin32.mfl
mofcomp rsop.mof
@@ -1059,12 +1070,12 @@ exit /b :: https://learn.microsoft.com/en-us/windows/win32/wmisdk/wmi-error-constants
set error=
-wmic path Win32_ComputerSystem get CreationClassName /value %nul2% | find /i "computersystem" %nul1%
+%psc% "Get-WmiObject -Class Win32_ComputerSystem | Select-Object -Property CreationClassName" %nul2% | find /i "computersystem" %nul1%
if %errorlevel% NEQ 0 (set error=1& exit /b)
winmgmt /verifyrepository %nul%
if %errorlevel% NEQ 0 (set error=1& exit /b)
-cscript //nologo %windir%\system32\slmgr.vbs /dlv %nul%
+%psc% "try { $null=([WMISEARCHER]'SELECT * FROM SoftwareLicensingService').Get().Version; exit 0 } catch { exit $_.Exception.InnerException.HResult }" %nul%
cmd /c exit /b %errorlevel%
echo "0x%=ExitCode%" | findstr /i "0x800410 0x800440" %nul1%
if %errorlevel% EQU 0 set error=1
@@ -1077,21 +1088,17 @@ exit /b echo:
echo %line%
echo:
-call :_color %_Yellow% "Press any key to go back..."
+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%
+)
goto :at_menu
::========================================================================================================================================
-:at_done
-
-echo:
-echo Press any key to %_exitmsg%...
-pause %nul1%
-exit /b
-
-::========================================================================================================================================
-
:compresslog
:: https://stackoverflow.com/a/46268232
@@ -1118,64 +1125,172 @@ 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!\AT_Logs\%2_%_time%.cab"
+makecab /F %ddf% /D DiskDirectory1="" /D CabinetNameTemplate="!desktop!\%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
+:checkperms
+
+:: This code checks if SPP has permission access to tokens folder and required registry keys. Incorrect permissions are often set by gaming spoofers.
+
+set permerror=
+if not exist "%tokenstore%\" set "permerror=Error Found In Token Folder"
+
+for %%# in (
+"%tokenstore%+FullControl"
+"HKLM:\SYSTEM\WPA+QueryValues, EnumerateSubKeys, WriteKey"
+"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform+SetValue"
+) do for /f "tokens=1,2 delims=+" %%A in (%%#) do if not defined permerror (
+%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%
+if !errorlevel!==2 (
+if "%%A"=="%tokenstore%" (
+set "permerror=Error Found In Token Folder"
+) else (
+set "permerror=Error Found In SPP Registries"
+)
+)
+)
+
+REM https://learn.microsoft.com/office/troubleshoot/activation/license-issue-when-start-office-application
+
+if not defined permerror (
+reg query "HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion" %nul% && (
+set "pol=HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform\Policies"
+reg query "!pol!" %nul% || reg add "!pol!" %nul%
+%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%
+if !errorlevel!==3 set "permerror=Error Found In S-1-5-20 SPP"
+)
+)
+exit /b
+
+::========================================================================================================================================
+
+:: Fix SPP related registry and folder permissions
-:wpatest:
-$wpaKey = [Microsoft.Win32.RegistryKey]::OpenBaseKey('LocalMachine', 'Registry64').OpenSubKey("SYSTEM\\WPA")
-$count = $wpaKey.SubKeyCount
+:fixsppperms:
+# Fix perms for Token Folder
-$osVersion = [System.Environment]::OSVersion.Version
-$minBuildNumber = 14393
+if ($env:permerror -eq 'Error Found In Token Folder') {
+ New-Item -Path $env:tokenstore -ItemType Directory -Force
+ $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)'
+ $AclObject = New-Object System.Security.AccessControl.DirectorySecurity
+ $AclObject.SetSecurityDescriptorSddlForm($sddl)
+ Set-Acl -Path $env:tokenstore -AclObject $AclObject
+ exit
+}
+
+# Fix perms for SPP registries
+
+if ($env:permerror -eq 'Error Found In SPP Registries') {
+ $acl = Get-Acl 'HKLM:\SYSTEM\WPA'
+ $rule = New-Object System.Security.AccessControl.RegistryAccessRule ('NT Service\sppsvc', 'QueryValues, EnumerateSubKeys, WriteKey', 'ContainerInherit, ObjectInherit', 'None', 'Allow')
+ $acl.ResetAccessRule($rule)
+ $acl.SetAccessRule($rule)
+ Set-Acl -Path 'HKLM:\SYSTEM\WPA' -AclObject $acl
+
+ $acl = Get-Acl 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform'
+ $rule = New-Object System.Security.AccessControl.RegistryAccessRule ('NT Service\sppsvc', 'SetValue', 'ContainerInherit, ObjectInherit', 'None', 'Allow')
+ $acl.ResetAccessRule($rule)
+ $acl.SetAccessRule($rule)
+ Set-Acl -Path 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform' -AclObject $acl
+ exit
+}
+
+# Fix perms for SPP in HKU\S-1-5-20
+# https://learn.microsoft.com/office/troubleshoot/activation/license-issue-when-start-office-application
+
+if ($env:permerror -ne 'Error Found In S-1-5-20 SPP') {
+ exit
+}
+if (-not (Test-Path 'Registry::HKU\S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform')) {
+ exit
+}
-if ($osVersion.Build -ge $minBuildNumber) {
- $subkeyHashTable = @{}
- foreach ($subkeyName in $wpaKey.GetSubKeyNames()) {
- $keyNumber = $subkeyName -replace '.*-', ''
- $subkeyHashTable[$keyNumber] = $true
+# https://stackoverflow.com/a/35843420
+
+function Take-Permissions {
+ param($rootKey, $key, [System.Security.Principal.SecurityIdentifier]$sid = 'S-1-5-32-545', $recurse = $true)
+
+ switch -regex ($rootKey) {
+ 'HKCU|HKEY_CURRENT_USER' { $rootKey = 'CurrentUser' }
+ 'HKLM|HKEY_LOCAL_MACHINE' { $rootKey = 'LocalMachine' }
+ 'HKCR|HKEY_CLASSES_ROOT' { $rootKey = 'ClassesRoot' }
+ 'HKCC|HKEY_CURRENT_CONFIG' { $rootKey = 'CurrentConfig' }
+ 'HKU|HKEY_USERS' { $rootKey = 'Users' }
}
- 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
+
+ ### Step 1 - escalate current process's privilege
+ # get SeTakeOwnership, SeBackup and SeRestore privileges before executes next lines, script needs Admin privilege
+ $AssemblyBuilder = [AppDomain]::CurrentDomain.DefineDynamicAssembly(4, 1)
+ $ModuleBuilder = $AssemblyBuilder.DefineDynamicModule(2, $False)
+ $TypeBuilder = $ModuleBuilder.DefineType(0)
+ $TypeBuilder.DefinePInvokeMethod('RtlAdjustPrivilege', 'ntdll.dll', 'Public, Static', 1, [int], @([int], [bool], [bool], [bool].MakeByRefType()), 1, 3) | Out-Null
+ 9, 17, 18 | ForEach-Object { $TypeBuilder.CreateType()::RtlAdjustPrivilege($_, $true, $false, [ref]$false) | Out-Null }
+
+ function Take-KeyPermissions {
+ param($rootKey, $key, $sid, $recurse, $recurseLevel = 0)
+
+ ### Step 2 - get ownerships of key - it works only for current key
+ $regKey = [Microsoft.Win32.Registry]::$rootKey.OpenSubKey($key, 'ReadWriteSubTree', 'TakeOwnership')
+ $acl = New-Object System.Security.AccessControl.RegistrySecurity
+ $acl.SetOwner($sid)
+ $regKey.SetAccessControl($acl)
+
+ ### Step 3 - enable inheritance of permissions (not ownership) for current key from parent
+ $acl.SetAccessRuleProtection($false, $false)
+ $regKey.SetAccessControl($acl)
+
+ ### Step 4 - only for top-level key, change permissions for current key and propagate it for subkeys
+ # to enable propagations for subkeys, it needs to execute Steps 2-3 for each subkey (Step 5)
+ if ($recurseLevel -eq 0) {
+ $regKey = $regKey.OpenSubKey('', 'ReadWriteSubTree', 'ChangePermissions')
+ $rule = New-Object System.Security.AccessControl.RegistryAccessRule($sid, 'FullControl', 'ContainerInherit', 'None', 'Allow')
+ $acl.ResetAccessRule($rule)
+ $regKey.SetAccessControl($acl)
+ }
+
+ ### Step 5 - recursively repeat steps 2-5 for subkeys
+ if ($recurse) {
+ foreach ($subKey in $regKey.OpenSubKey('').GetSubKeyNames()) {
+ Take-KeyPermissions $rootKey ($key + '\' + $subKey) $sid $recurse ($recurseLevel + 1)
+ }
}
}
+
+ Take-KeyPermissions $rootKey $key $sid $recurse
}
-$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:
-::========================================================================================================================================
+Take-Permissions "Users" "S-1-5-20\Software\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform" "S-1-5-20"
+:fixsppperms:
-:checkperms
+::========================================================================================================================================
-set permerror=
-if not exist "%tokenstore%\" set permerror=1
+:: Install License files using Powershell/WMI instead of slmgr.vbs
-for %%# in (
-"%tokenstore%"
-"HKLM:\SYSTEM\WPA"
-"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform"
-) do if not defined permerror (
-%psc% "$acl = Get-Acl '%%#'; if ($acl.Access.Where{ $_.IdentityReference -eq 'NT SERVICE\sppsvc' -and $_.AccessControlType -eq 'Deny' -or $acl.Access.IdentityReference -notcontains 'NT SERVICE\sppsvc'}) {Exit 2}" %nul%
-if !errorlevel!==2 set permerror=1
-)
-exit /b
+:xrm:
+function InstallLicenseFile($Lsc) {
+ try {
+ $null = $sls.InstallLicense([IO.File]::ReadAllText($Lsc))
+ } catch {
+ $host.SetShouldExit($_.Exception.HResult)
+ }
+}
+function InstallLicenseArr($Str) {
+ $a = $Str -split ';'
+ ForEach ($x in $a) {InstallLicenseFile "$x"}
+}
+function InstallLicenseDir($Loc) {
+ dir $Loc *.xrm-ms -af -s | select -expand FullName | % {InstallLicenseFile "$_"}
+}
+function ReinstallLicenses() {
+ $Oem = "$env:SysPath\oem"
+ $Spp = "$env:SysPath\spp\tokens"
+ InstallLicenseDir "$Spp"
+ If (Test-Path $Oem) {InstallLicenseDir "$Oem"}
+}
+:xrm:
::========================================================================================================================================
@@ -1183,9 +1298,9 @@ exit /b set token=
for %%# in (
-%Systemdrive%\Windows\System32\spp\store_test\2.0\
-%Systemdrive%\Windows\System32\spp\store\
-%Systemdrive%\Windows\System32\spp\store\2.0\
+%SysPath%\spp\store_test\2.0\
+%SysPath%\spp\store\
+%SysPath%\spp\store\2.0\
%Systemdrive%\Windows\ServiceProfiles\NetworkService\AppData\Roaming\Microsoft\SoftwareProtectionPlatform\
) do (
@@ -1262,106 +1377,88 @@ $key.SetAccessControl($acl) ::========================================================================================================================================
-:_color
+: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
if %_NCS% EQU 1 (
echo %esc%[%~1%~2%esc%[0m
) else (
-call :batcol %~1 "%~2"
+%psc% write-host -back '%1' -fore '%2' '%3'
)
exit /b
-:_color2
+:dk_color2
if %_NCS% EQU 1 (
echo %esc%[%~1%~2%esc%[%~3%~4%esc%[0m
) else (
-call :batcol %~1 "%~2" %~3 "%~4"
+%psc% write-host -back '%1' -fore '%2' '%3' -NoNewline; write-host -back '%4' -fore '%5' '%6'
)
exit /b
-::=======================================
-
-:: Colored text with pure batch method
-:: Thanks to @dbenham and @jeb
-:: stackoverflow.com/a/10407642
-
-:batcol
+::========================================================================================================================================
-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 variables
-:_batcol
+:dk_setvar
-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
-
-::=======================================
+set psc=powershell.exe
+set winbuild=1
+for /f "tokens=6 delims=[]. " %%G in ('ver') do set winbuild=%%G
-:_colorprep
+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)
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 "_Green="40;92m""
-set "_Blue="40;94m""
set "_White="40;37m""
+set "_Green="40;92m""
set "_Yellow="40;93m""
-
-exit /b
+) 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""
)
-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""
-
+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."
+)
exit /b
::========================================================================================================================================
|
