Advertisement
aveyo

windows_update_refresh

Mar 14th, 2022 (edited)
7,150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 2.92 KB | None | 0 0
  1. @(set '(=)||' <# lean and mean cmd / ps1 hybrid, can paste into powershell console #> @'
  2.  
  3. @echo off & title WINDOWS UPDATE REFRESH
  4.  
  5. ::# elevate with native shell by AveYo
  6. >nul reg add hkcu\software\classes\.Admin\shell\runas\command /f /ve /d "cmd /x /d /r set \"f0=%%2\"& call \"%%2\" %%3"& set _= %*
  7. >nul fltmc|| if "%f0%" neq "%~f0" (cd.>"%temp%\runas.Admin" & start "%~n0" /high "%temp%\runas.Admin" "%~f0" "%_:"=""%" & exit /b)
  8.  
  9. ::# stop pending updates
  10. for /f "tokens=6 delims=[]. " %%b in ('ver') do set /a BUILD=%%b
  11. set KILL=& set UPDATE=windowsupdatebox updateassistant updateassistantcheck windows10upgrade windows10upgraderapp
  12. for %%w in (dism setuphost tiworker usoclient sihclient wuauclt culauncher sedlauncher osrrb ruximics ruximih disktoast eosnotify
  13.   musnotification musnotificationux musnotifyicon monotificationux mousocoreworker %UPDATE%) do call set KILL=/im %%w.exe %%KILL%%
  14. taskkill /f %KILL% 2>nul & dism /cleanup-wim & bitsadmin /reset /allusers
  15. for %%w in (msiserver wuauserv bits usosvc dosvc cryptsvc) do start /min cmd /d /x /c net stop %%w /y
  16. taskkill /f %KILL% /im systemsettings.exe 2>nul & timeout 7 /nobreak >nul
  17. for /f tokens^=3^,5^ delims^=^" %%X in ('tasklist /fo csv /nh /svc /fi "services eq wuauserv"') do (
  18.   taskkill /f /pid %%X & for %%w in (%%Y) do if /i %%w neq wuauserv if /i %%w neq bits if /i %%w neq usosvc net start %%w /y
  19. )
  20.  
  21. ::# clear update logs
  22. set "DATA=%ProgramData%" & set "LOG=%SystemRoot%\Logs\WindowsUpdate" & set "SRC=%SystemDrive%\$WINDOWS.~BT\Sources"
  23. del /f /s /q "%DATA%\USOShared\Logs\*" "%DATA%\USOPrivate\UpdateStore\*" "%DATA%\Microsoft\Network\Downloader\*" >nul 2>nul
  24. powershell -nop -c "try {$null=Get-WindowsUpdateLog -LogPath $env:temp\WU.log -ForceFlush -Confirm:$false -ea 0} catch {}" >nul
  25. rmdir /s /q "%LOG%" "%ProgramFiles%\UNP" "%SystemRoot%\SoftwareDistribution" "%SystemDrive%\Windows.old\Cleanup" >nul 2>nul
  26. if exist %SRC%\setuphost.exe if exist %SRC%\setupprep.exe start "cleanup" /wait %SRC%\setupprep.exe /cleanup /quiet
  27.  
  28. ::# remove forced upgraders and update remediators
  29. call "%SystemRoot%\UpdateAssistant\Windows10Upgrade.exe" /ForceUninstall 2>nul
  30. call "%SystemDrive%\Windows10Upgrade\Windows10UpgraderApp.exe" /ForceUninstall 2>nul
  31. msiexec /X {1BA1133B-1C7A-41A0-8CBF-9B993E63D296} /qn 2>nul && echo;Removed osrss
  32. msiexec /X {8F2D6CEB-BC98-4B69-A5C1-78BED238FE77} /qn 2>nul && echo;Removed rempl, ruxim
  33. msiexec /X {0746492E-47B6-4251-940C-44462DFD74BB} /qn 2>nul && echo;Removed CUAssistant
  34. msiexec /X {76A22428-2400-4521-96AF-7AC4A6174CA5} /qn 2>nul && echo;Removed UpdateAssistant
  35. echo;
  36.  
  37. ::# start update services
  38. net start bits /y & net start wuauserv /y & net start usosvc /y 2>nul & start /min UsoClient RefreshSettings
  39. echo;AveYo: run again / reboot if there are still pending files or services & pause
  40. exit /b
  41.  
  42. '@); $0 = "$env:temp\windows_update_refresh.bat"; ${(=)||} -split "\r?\n" | out-file $0 -encoding default -force; & $0
  43. # press enter
  44.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement