Last active
May 4, 2023 15:12
-
-
Save mirh/145f22ccb57e36a76c17a3a8ca4b64a7 to your computer and use it in GitHub Desktop.
Dalai's improved universal Wupdate fix (+ SHA-2 support)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
set wu_stopped= | |
set wu_disabled= | |
REM --- Check for admin rights | |
REM fsutil dirty query %SystemDrive% >NUL && set admin=1 | |
REM if NOT "%admin%"=="1" ( | |
REM echo. | |
REM echo Run this script as administrator! | |
REM pause | |
REM goto :EOF | |
REM ) | |
setlocal | |
if "%~1"=="dry" set dry=1 | |
REM --- List of updates for the various Windows versions, 2018 (rightmost come first) | |
set prereq_windows6.0=KB4015380 KB4015195 KB4012583 KB3205638 KB3194371 KB3193418 KB3183431 KB3124275 | |
set prereq_windows6.1=KB4550735 KB4474419 KB3172605 KB4490628 | |
set prereq_windows8.1=KB3172614 KB3173424 | |
set find=%SystemRoot%\system32\find.exe | |
set wmic=%SystemRoot%\system32\wbem\wmic.exe | |
set wusaSN=%SystemRoot%\SysNative\wusa.exe | |
set scSN=%SystemRoot%\SysNative\sc.exe | |
set wu=wuauserv | |
set sc=%SystemRoot%\system32\sc.exe | |
set wusa=%SystemRoot%\system32\wusa.exe | |
if exist "%scSN%" set sc=%scSN% | |
if exist "%wusaSN%" set wusa=%wusaSN% | |
REM --- Prüfung des Diensts "Windows Update" | |
"%sc%" qc %wu% | "%find%" /i "DISABLED" > NUL && set wu_disabled=1 | |
"%sc%" query %wu% | "%find%" /i "STOPPED" > NUL && set wu_stopped=1 | |
if "%wu_disabled%"=="1" if "%wu_stopped%"=="1" ( | |
echo. | |
echo Service "Windows Update" is disabled! | |
echo Please enable it and try again. | |
echo. | |
pause | |
goto :EOF | |
) | |
"%sc%" query %wu% | "%find%" /i "RUNNING" > NUL && "%sc%" stop %wu% > NUL | |
set win= | |
ver | "%find%" "6.3." >NUL && set win=windows8.1 | |
ver | "%find%" "6.1." >NUL && set win=windows6.1 | |
ver | "%find%" "6.0." >NUL && set win=windows6.0 | |
if "%win%"=="" ( | |
echo. | |
echo Error determining the Windows version! | |
pause | |
goto :EOF | |
) | |
call set prereq=%%prereq_%win%%% | |
REM --- Determine the Windows architecture | |
set arch=x86 | |
"%wmic%" COMPUTERSYSTEM GET SystemType | "%find%" /i "x64" >NUL && set arch=x64 | |
for %%i IN (win arch wusa) DO ( | |
call echo %%i = %%%%i%% | |
) | |
echo. | |
pause | |
REM --- Determine Internet Explorer version | |
set IEver= | |
FOR /F "skip=2 tokens=2,*" %%A IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Internet Explorer" /v Build') DO (SET IEver=%%B) | |
if %win%==windows6.0 if %IEver% GEQ 90000 set prereq=KB4014661 %prereq% | |
echo Checking installed updates | |
for %%A IN (%prereq%) DO ( | |
for /f "skip=1" %%B IN ('%wmic% QFE GET HotFixID ^| findstr .') DO ( | |
if %%A==%%B ( | |
REM --- if "drop everything after" condition is not appreciated you could just use instead 'call set prereq=%%prereq: %%A=%%' | |
call set "prereq=%%prereq: %%A="%% & rem."%" | |
) | |
) | |
) | |
for %%A IN (%prereq%) DO (call :MAGIC %%A) | |
pushd %~dp0 | |
echo List: %prereqr% | |
for %%A IN (%prereqr%) DO ( | |
echo. | |
echo %%A | |
for /F %%i IN ('dir /b "%win%-%%A-*%arch%*.msu"') DO ( | |
call :INSTALL_MSU "%%~i" | |
) | |
) | |
popd | |
endlocal | |
echo. | |
echo. | |
echo Installation finished. Please reboot the system. | |
echo. | |
pause | |
goto :EOF | |
:INSTALL_MSU | |
echo %~1 | |
if NOT "%dry%"=="1" start /wait "install" "%wusa%" "%~dp0%~1" /quiet /norestart | |
echo Errorlevel: %errorlevel% | |
if "%errorlevel%"=="0" ( | |
echo Update installed successfully. | |
goto :EOF | |
) | |
if "%errorlevel%"=="2359302" echo Update already installed. | |
if "%errorlevel%"=="3010" echo Reboot required, please do now. | |
if "%errorlevel%"=="-2145124329" echo Uh? Seems like I wronged architecture or some dependency? :\ | |
pause > nul | |
pause | |
exit | |
:DOWNLOAD_MSU | |
echo You are missing %~1 installer, so I'm downloading it. | |
echo If the thing stalls for too much time (e.g. you have no net) quit with CTRL+C | |
bitsadmin /rawreturn /transfer WUpdates /download /priority foreground %~2 "%~dp0%win%-%~1-%arch%.msu" | |
goto :EOF | |
:MAGIC | |
set prereqr=%~1 %prereqr% | |
if NOT exist "%win%-%1-*%arch%*.msu" ( | |
if %~1==KB3124275 ( | |
if %arch%==x64 ( | |
if %IEver% LSS 80000 call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/secu/2015/12/windows6.0-kb3124275-x64_572858baa4ef118b22efcb72c9521039e81918a8.msu | |
if %IEver% GEQ 80000 if %IEver% LSS 90000 call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/secu/2015/12/ie8-windows6.0-kb3124275-x64_d9247dac49712a66fe48196fcd8e75400115062d.msu | |
if %IEver% GEQ 90000 call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/secu/2015/12/ie9-windows6.0-kb3124275-x64_ef0bb9b7760a867755c33023e843105e8af9a6be.msu | |
) else ( | |
if %IEver% LSS 80000 call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/secu/2015/12/windows6.0-kb3124275-x86_d201b142f2fbb037e5a28fd277062ffa169fed2a.msu | |
if %IEver% GEQ 80000 if %IEver% LSS 90000 call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/secu/2015/12/ie8-windows6.0-kb3124275-x86_7b98ec75e2e79562590656f2a9f2df59dc238318.msu | |
if %IEver% GEQ 90000 call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/secu/2015/12/ie9-windows6.0-kb3124275-x86_4d448436fbc1c38b92aaeccb55fb7e3e8193143b.msu | |
) | |
) | |
if %~1==KB3183431 ( | |
if %arch%==x64 (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/secu/2016/09/windows6.0-kb3183431-x64_bf6fe91703fd4da37648a3f3cbd574606e630c1a.msu | |
) else (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/secu/2016/09/windows6.0-kb3183431-x86_e7c78348dd1f8e9074266e58b7b603e34cff57b4.msu) | |
) | |
if %~1==KB3193418 ( | |
if %arch%==x64 (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/secu/2016/10/windows6.0-kb3193418-x64_1f1729bb70ef55a5e3570fc271a47e7ea003a1e5.msu | |
) else (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/secu/2016/10/windows6.0-kb3193418-x86_8bcecda3daec879fd2a71d91e5e5bd66e91741da.msu) | |
) | |
if %~1==KB3194371 ( | |
if %arch%==x64 (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/secu/2016/10/windows6.0-kb3194371-x64_6460d4026a97d715f83a3456b384a9f43a72621c.msu | |
) else (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/secu/2016/10/windows6.0-kb3194371-x86_a5b6ce91a2602762af0210102192b0999e60d985.msu) | |
) | |
if %~1==KB3205638 ( | |
if %arch%==x64 (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/secu/2016/11/windows6.0-kb3205638-x64_a52aaa009ee56ca941e21a6009c00bc4c88cbb7c.msu | |
) else (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/secu/2016/11/windows6.0-kb3205638-x86_e2211e9a6523061972decd158980301fc4c32a47.msu) | |
) | |
if %~1==KB4012583 ( | |
if %arch%==x64 (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/secu/2017/02/windows6.0-kb4012583-x64_f63c9a85aa877d86c886e432560fdcfad53b752d.msu | |
) else (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/secu/2017/02/windows6.0-kb4012583-x86_1887cb5393b62cbd2dbb6a6ff6b136e809a2fbd0.msu) | |
) | |
if %~1==KB4015195 ( | |
if %arch%==x64 (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/secu/2017/03/windows6.0-kb4015195-x64_2e310724d86b6a43c5ae8ec659685dd6cfb28ba4.msu | |
) else (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/secu/2017/03/windows6.0-kb4015195-x86_eb045e0144266b20b615f29fa581c4001ebb7852.msu) | |
) | |
if %~1==KB4015380 ( | |
if %arch%==x64 (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/secu/2017/03/windows6.0-kb4015380-x64_959aedbe0403d160be89f4dac057e2a0cd0c6d40.msu | |
) else (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/secu/2017/03/windows6.0-kb4015380-x86_3f3548db24cf61d6f47d2365c298d739e6cb069a.msu) | |
) | |
if %~1==KB4014661 ( | |
if %arch%==x64 (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/secu/2017/04/ie9-windows6.0-kb4014661-x64_b0fd6aaf25578ac22e771e9420fb691845cc3c90.msu | |
) else (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/secu/2017/04/ie9-windows6.0-kb4014661-x86_41c4885409c1e7712495cda5067389e9d58be7e7.msu) | |
) | |
REM Windows 7 (still takes north of 600MB to finish.. do I need something else?) | |
if %~1==KB4490628 ( | |
if %arch%==x64 (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/secu/2019/03/windows6.1-kb4490628-x64_d3de52d6987f7c8bdc2c015dca69eac96047c76e.msu | |
) else (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/secu/2019/03/windows6.1-kb4490628-x86_3cdb3df55b9cd7ef7fcb24fc4e237ea287ad0992.msu) | |
) | |
if %~1==KB3172605 ( | |
if %arch%==x64 (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/updt/2016/09/windows6.1-kb3172605-x64_2bb9bc55f347eee34b1454b50c436eb6fd9301fc.msu | |
) else (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/updt/2016/09/windows6.1-kb3172605-x86_ae03ccbd299e434ea2239f1ad86f164e5f4deeda.msu) | |
) | |
if %~1==KB4474419 ( | |
if %arch%==x64 (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/secu/2019/09/windows6.1-kb4474419-v3-x64_b5614c6cea5cb4e198717789633dca16308ef79c.msu | |
) else (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/secu/2019/09/windows6.1-kb4474419-v3-x86_0f687d50402790f340087c576886501b3223bec6.msu) | |
) | |
if %~1==KB4550735 ( | |
if %arch%==x64 (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/secu/2020/03/windows6.1-kb4550735-x64_18117664b4a0482c3d34a2f05f70c6819296240f.msu | |
) else (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/secu/2020/03/windows6.1-kb4550735-x86_5811def508a4d12403ecd1cb4bbb5c9922c792ea.msu) | |
) | |
REM Windows 8 (untested) | |
if %~1==KB3173424 ( | |
if %arch%==x64 (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/crup/2016/06/windows8.1-kb3173424-x64_9a1c9e0082978d92abee71f2cfed5e0f4b6ce85c.msu | |
) else (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/d/msdownload/update/software/crup/2016/06/windows8.1-kb3173424-x86_fcf7142a388a08fde7c54f23e84450f18a8aaec5.msu) | |
) | |
if %~1==KB3172614 ( | |
if %arch%==x64 (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/updt/2016/07/windows8.1-kb3172614-x64_e41365e643b98ab745c21dba17d1d3b6bb73cfcc.msu | |
) else (call :DOWNLOAD_MSU %~1 http://download.windowsupdate.com/c/msdownload/update/software/updt/2016/07/windows8.1-kb3172614-x86_d11c233c8598b734de72665e0d0a3f2ef007b91f.msu) | |
) | |
) | |
goto :EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment