bigbrother87

Reset Windows Update

Jul 31st, 2022
7,966
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 6.06 KB | None | 0 0
  1. @echo off
  2.  
  3. :: Created by: Shawn Brink
  4. :: Created on: October 1, 2015
  5. :: Updated on: March 8, 2021
  6. :: Tutorial: https://www.tenforums.com/tutorials/24742-reset-windows-update-windows-10-a.html
  7.  
  8.  
  9. :: Prompt to Run as administrator
  10. Set "Variable=0" & if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs"
  11. fsutil dirty query %systemdrive%  >nul 2>&1 && goto :(Privileges_got)
  12. If "%1"=="%Variable%" (echo. &echo. Please right-click on the file and select &echo. "Run as administrator". &echo. Press any key to exit. &pause>nul 2>&1& exit)
  13. cmd /u /c echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "%~0", "%Variable%", "", "runas", 1 > "%temp%\getadmin.vbs"&cscript //nologo "%temp%\getadmin.vbs" & exit
  14. :(Privileges_got)
  15.  
  16. :: Checking and Stopping the Windows Update services
  17. set b=0
  18.  
  19. :bits
  20. set /a b=%b%+1
  21. if %b% equ 3 (
  22.    goto end1
  23. )
  24. net stop bits
  25. echo Checking the bits service status.
  26. sc query bits | findstr /I /C:"STOPPED"
  27. if not %errorlevel%==0 (
  28.     goto bits
  29. )
  30. goto loop2
  31.  
  32. :end1
  33. cls
  34. echo.
  35. echo Cannot reset Windows Update since "Background Intelligent Transfer Service" (bits) service failed to stop. Please restart the computer, and try again.
  36. echo.
  37. pause
  38. goto Start
  39.  
  40.  
  41. :loop2
  42. set w=0
  43.  
  44. :wuauserv
  45. set /a w=%w%+1
  46. if %w% equ 3 (
  47.    goto end2
  48. )
  49. net stop wuauserv
  50. echo Checking the wuauserv service status.
  51. sc query wuauserv | findstr /I /C:"STOPPED"
  52. if not %errorlevel%==0 (
  53.     goto wuauserv
  54. )
  55. goto loop3
  56.  
  57. :end2
  58. cls
  59. echo.
  60. echo Cannot reset Windows Update since "Windows Update" (wuauserv) service failed to stop. Please restart the computer, and try again.
  61. echo.
  62. pause
  63. goto Start
  64.  
  65.  
  66.  
  67. :loop3
  68. set app=0
  69.  
  70. :appidsvc
  71. set /a app=%app%+1
  72. if %app% equ 3 (
  73.    goto end3
  74. )
  75. net stop appidsvc
  76. echo Checking the appidsvc service status.
  77. sc query appidsvc | findstr /I /C:"STOPPED"
  78. if not %errorlevel%==0 (
  79.     goto appidsvc
  80. )
  81. goto loop4
  82.  
  83. :end3
  84. cls
  85. echo.
  86. echo Cannot reset Windows Update since "Application Identity" (appidsvc) service failed to stop. Please restart the computer, and try again.
  87. echo.
  88. pause
  89. goto Start
  90.  
  91.  
  92. :loop4
  93. set c=0
  94.  
  95. :cryptsvc
  96. set /a c=%c%+1
  97. if %c% equ 3 (
  98.    goto end4
  99. )
  100. net stop cryptsvc
  101. echo Checking the cryptsvc service status.
  102. sc query cryptsvc | findstr /I /C:"STOPPED"
  103. if not %errorlevel%==0 (
  104.     goto cryptsvc
  105. )
  106. goto Reset
  107.  
  108. :end4
  109. cls
  110. echo.
  111. echo Cannot reset Windows Update since "Cryptographic Services" (cryptsvc) service failed to stop. Please restart the computer, and try again.
  112. echo.
  113. pause
  114. goto Start
  115.  
  116.  
  117. :Reset
  118. Ipconfig /flushdns
  119. del /s /q /f "%ALLUSERSPROFILE%\Application Data\Microsoft\Network\Downloader\qmgr*.dat"
  120. del /s /q /f "%ALLUSERSPROFILE%\Microsoft\Network\Downloader\qmgr*.dat"
  121. del /s /q /f "%SYSTEMROOT%\Logs\WindowsUpdate\*"
  122.  
  123.  
  124. if exist "%SYSTEMROOT%\winsxs\pending.xml.bak" del /s /q /f "%SYSTEMROOT%\winsxs\pending.xml.bak"
  125. if exist "%SYSTEMROOT%\winsxs\pending.xml" (
  126.     takeown /f "%SYSTEMROOT%\winsxs\pending.xml"
  127.     attrib -r -s -h /s /d "%SYSTEMROOT%\winsxs\pending.xml"
  128.     ren "%SYSTEMROOT%\winsxs\pending.xml" pending.xml.bak
  129. )
  130.  
  131. if exist "%SYSTEMROOT%\SoftwareDistribution.bak" rmdir /s /q "%SYSTEMROOT%\SoftwareDistribution.bak"
  132. if exist "%SYSTEMROOT%\SoftwareDistribution" (
  133.     attrib -r -s -h /s /d "%SYSTEMROOT%\SoftwareDistribution"
  134.     ren "%SYSTEMROOT%\SoftwareDistribution" SoftwareDistribution.bak
  135. )
  136.  
  137. if exist "%SYSTEMROOT%\system32\Catroot2.bak" rmdir /s /q "%SYSTEMROOT%\system32\Catroot2.bak"
  138. if exist "%SYSTEMROOT%\system32\Catroot2" (
  139.     attrib -r -s -h /s /d "%SYSTEMROOT%\system32\Catroot2"
  140.     ren "%SYSTEMROOT%\system32\Catroot2" Catroot2.bak
  141. )
  142.  
  143.  
  144. :: Reset Windows Update policies
  145. reg delete "HKCU\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /f
  146. reg delete "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\WindowsUpdate" /f
  147. reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /f
  148. reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\WindowsUpdate" /f
  149. gpupdate /force
  150.  
  151.  
  152. :: Reset the BITS service and the Windows Update service to the default security descriptor
  153. sc.exe sdset bits D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)
  154.  
  155. sc.exe sdset wuauserv D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)
  156.  
  157. :: Reregister the BITS files and the Windows Update files
  158. cd /d %windir%\system32
  159. regsvr32.exe /s atl.dll
  160. regsvr32.exe /s urlmon.dll
  161. regsvr32.exe /s mshtml.dll
  162. regsvr32.exe /s shdocvw.dll
  163. regsvr32.exe /s browseui.dll
  164. regsvr32.exe /s jscript.dll
  165. regsvr32.exe /s vbscript.dll
  166. regsvr32.exe /s scrrun.dll
  167. regsvr32.exe /s msxml.dll
  168. regsvr32.exe /s msxml3.dll
  169. regsvr32.exe /s msxml6.dll
  170. regsvr32.exe /s actxprxy.dll
  171. regsvr32.exe /s softpub.dll
  172. regsvr32.exe /s wintrust.dll
  173. regsvr32.exe /s dssenh.dll
  174. regsvr32.exe /s rsaenh.dll
  175. regsvr32.exe /s gpkcsp.dll
  176. regsvr32.exe /s sccbase.dll
  177. regsvr32.exe /s slbcsp.dll
  178. regsvr32.exe /s cryptdlg.dll
  179. regsvr32.exe /s oleaut32.dll
  180. regsvr32.exe /s ole32.dll
  181. regsvr32.exe /s shell32.dll
  182. regsvr32.exe /s initpki.dll
  183. regsvr32.exe /s wuapi.dll
  184. regsvr32.exe /s wuaueng.dll
  185. regsvr32.exe /s wuaueng1.dll
  186. regsvr32.exe /s wucltui.dll
  187. regsvr32.exe /s wups.dll
  188. regsvr32.exe /s wups2.dll
  189. regsvr32.exe /s wuweb.dll
  190. regsvr32.exe /s qmgr.dll
  191. regsvr32.exe /s qmgrprxy.dll
  192. regsvr32.exe /s wucltux.dll
  193. regsvr32.exe /s muweb.dll
  194. regsvr32.exe /s wuwebv.dll
  195. regsvr32.exe /s wudriver.dll
  196. netsh winsock reset
  197. netsh winsock reset proxy
  198.  
  199. :: Set the startup type as automatic
  200. sc config wuauserv start= auto
  201. sc config bits start= auto
  202. sc config DcomLaunch start= auto
  203.  
  204. :Start
  205. net start bits
  206. net start wuauserv
  207. net start appidsvc
  208. net start cryptsvc
  209.  
  210. :: Restart computer
  211. cls
  212. echo It is required to restart the computer to finish resetting Windows Update.
  213. echo.
  214. echo Please save and close anything open now, before the computer is restarted.
  215. echo.
  216. pause
  217. echo.
  218. echo.
  219. echo.
  220. echo *** Restart computer now. ***
  221. echo.
  222. pause
  223. shutdown /r /f /t 0
Advertisement