Advertisement
dantpro

Reset Windows Update Components

Oct 27th, 2015
892
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 17.79 KB | None | 0 0
  1. :: ==================================================================================
  2. :: NAME     : Reset Windows Update Components.
  3. :: DESCRIPTION     : This script reset the Windows Update Components.
  4. :: AUTOR     : Manuel Gil.
  5. :: VERSION     : 8.0.
  6. ::
  7. :: http://windowsitpro.com/powershell/cool-tool-script-selectively-fix-common-windows-update-problems
  8. :: https://gallery.technet.microsoft.com/scriptcenter/Reset-Windows-Update-Agent-d824badc
  9. :: ==================================================================================
  10.  
  11.  
  12. :: CMD Screen Settings.
  13. :: /************************************************************************************/
  14. echo off
  15. title Reset Windows Update Components.
  16. color 17
  17. cls
  18. :: /************************************************************************************/
  19.  
  20.  
  21. :: Checking for Administrator elevation.
  22. :: /************************************************************************************/
  23. openfiles>nul 2>&1
  24.  
  25. if %errorlevel%==0 goto Variables
  26.  
  27. cls
  28. ver
  29. echo Reset Windows Update Components Tool.
  30. echo.
  31. echo Checking for Administrator elevation.
  32. echo.
  33. echo     You are not running as Administrator.
  34. echo     This batch cannot do it's job without elevation.
  35. echo.
  36. echo     You must run this tool as Administrator.
  37. echo.
  38. echo Press any key to continue . . .  
  39. pause>nul
  40. goto Close
  41. :: /************************************************************************************/
  42.  
  43.  
  44. :: Set variables.
  45. :: /************************************************************************************/
  46. :Variables
  47.  
  48. set version=0.0.0000
  49. set name=Windows
  50. set allow=0
  51.  
  52. for /f "tokens=4-5 delims=[] " %%a in ('ver') do set version=%%a %%b
  53.  
  54. for %%a in (%version%) do set version=%%a
  55.  
  56. if %version%==5.1.2600 (
  57.     set name=Windows XP
  58.     set allow=1
  59. )
  60.  
  61. if %version%==5.2.3790 (
  62.     set name=Windows XP Professional x64 Edition
  63.     set allow=1
  64. )
  65.  
  66. if %version%==6.0.6000 (
  67.     set name=Windows Vista
  68.     set allow=1
  69. )
  70.  
  71. if %version%==6.0.6001 (
  72.     set name=Windows Vista SP1
  73.     set allow=1
  74. )
  75.  
  76. if %version%==6.0.6002 (
  77.     set name=Windows Vista SP2
  78.     set allow=1
  79. )
  80.  
  81. if %version%==6.1.7600 (
  82.     set name=Windows 7
  83.     set allow=1
  84. )
  85.  
  86. if %version%==6.1.7601 (
  87.     set name=Windows 7 SP1
  88.     set allow=1
  89. )
  90.  
  91. if %version%==6.2.9200 (
  92.     set name=Windows 8
  93.      set allow=1
  94. )
  95.  
  96. if %version%==6.3.9200 (
  97.     set name=Windows 8.1
  98.      set allow=1
  99. )
  100.  
  101. if %version%==6.3.9600 (
  102.     set name=Windows 8.1 Update 1
  103.      set allow=1
  104. )
  105.  
  106. if %version%==10.0.10240 (
  107.     set name=Windows 10
  108.      set allow=1
  109. )
  110.  
  111. if %version%==10.0.10565 (
  112.     set name=Windows 10 Insider
  113.      set allow=1
  114. )
  115.  
  116. cls
  117. ver
  118. echo Reset Windows Update Components Tool.
  119. echo.
  120. echo Microsoft %name% detected . . .  
  121. -echo.
  122.  
  123. if %allow%==0 echo Sorry, this Operative System is not compatible whit this tool.
  124. if %allow%==1 goto Terms
  125.  
  126. echo.
  127. echo     An error occurred while attempting to verify your system.
  128. echo     Can this using a business or test version.
  129. echo.
  130. echo     If not, verify that your system has the correct security fix.
  131. echo.
  132. echo Press any key to continue . . .  
  133. pause>nul
  134. goto Close
  135. :: /************************************************************************************/
  136.  
  137.  
  138. :: Terms.
  139. :: /*************************************************************************************/
  140. :Terms
  141.  
  142. cls
  143. echo.
  144. echo Microsoft %name% [Versi?n: %version%]
  145. echo Reset Windows Update Components Tool.
  146. echo.
  147. echo     The methods inside this batch modify files and registry settings.
  148. echo     While they are tested and tend to work, I take no responsibility for
  149. echo     the use of this file.
  150. echo     This batch is provided without warranty. Any damage caused is your
  151. echo     own responsibility.
  152. echo.
  153. echo     As well, batch files are almost always flagged by anti-virus, feel free
  154. echo     to review the code if you're unsure.
  155. echo.
  156.  
  157. choice /c YN /n /m "Do you want to continue with this process? (Yes/No) "
  158. if %errorlevel%==1 goto Menu
  159. if %errorlevel%==2 goto Close
  160.  
  161. echo.
  162. echo An unexpected error has occurred.
  163. echo.
  164. echo Press any key to continue . . .  
  165. pause>nul
  166. goto Close
  167. :: /*************************************************************************************/
  168.  
  169.  
  170. :: Menu of tool.
  171. :: /*************************************************************************************/
  172. :Menu
  173.  
  174. cls
  175. echo.
  176. echo Microsoft %name% [Versi?n: %version%]
  177. echo Reset Windows Update Components Tool.
  178. echo.
  179. echo      1. Change invalid values in the Registry.
  180. echo      2. Reset Windows Update Components.
  181. echo      3. Delete temporary files in Windows.
  182. echo      4. Open the Internet Explorer options.
  183. echo      5. Reset the Winsock settings.
  184. echo      6. Search updates.
  185. echo      7. Explore other local solutions.
  186. echo      8. Explore other online solutions.
  187. echo      9. Restart your PC.
  188. echo      0. Close.
  189. echo.
  190.  
  191. set /p Opcion=  Select an option:  
  192. if %Opcion%==1 goto Regedit
  193. if %Opcion%==2 goto Reset
  194. if %Opcion%==3 goto Temp
  195. if %Opcion%==4 goto Historic
  196. if %Opcion%==5 goto Winsock
  197. if %Opcion%==6 goto Search
  198. if %Opcion%==7 goto Local
  199. if %Opcion%==8 goto Online
  200. if %Opcion%==9 goto Restart
  201. if %Opcion%==0 goto Close
  202.  
  203. echo.
  204. echo Invalid option.
  205. echo.
  206. echo Press any key to continue . . .  
  207. pause>nul
  208. goto Menu
  209. :: /*************************************************************************************/
  210.  
  211.  
  212. :: Change invalid values.
  213. :: /*************************************************************************************/
  214. :Regedit
  215.  
  216. for /f "tokens=1-5 delims=/, " %%a in ("%date%") do (
  217.     set now=%%a%%b%%c%%d%time:~0,2%%time:~3,2%
  218. )
  219.  
  220. :: ------------------------------------------------------------------------
  221. :: Create a backup of the Registry.
  222. cls
  223. echo.
  224. echo Microsoft %name% [Versi?n: %version%]
  225. echo Reset Windows Update Components Tool.
  226. echo.
  227. echo Making a backup copy of the Registry in: %USERPROFILE%\Desktop\Backup%now%.reg
  228. echo.
  229.  
  230. if exist "%USERPROFILE%\Desktop\Backup%now%.reg" (
  231.     echo An unexpected error has occurred.
  232.     echo.
  233.     echo     Changes were not carried out in the registry.
  234.     echo     Will try it later.
  235.     echo.
  236.     echo Press any key to continue . . .  
  237.     pause>nul
  238.     goto Menu
  239. ) else (
  240.     regedit /e "%USERPROFILE%\Desktop\Backup%now%.reg"
  241. )
  242. :: ------------------------------------------------------------------------
  243.  
  244. :: ------------------------------------------------------------------------
  245. :: Checking backup.
  246. cls
  247. echo.
  248. echo Microsoft %name% [Versi?n: %version%]
  249. echo Reset Windows Update Components Tool.
  250. echo.
  251. echo Checking the backup copy.
  252. echo.
  253.  
  254. if not exist "%USERPROFILE%\Desktop\Backup%now%.reg" (
  255.     echo An unexpected error has occurred.
  256.     echo.
  257.     echo     Something went wrong.
  258.     echo     You manually create a backup of the registry before continuing.
  259.     echo.
  260.     echo Press any key to continue . . .  
  261.     pause>nul
  262. ) else (
  263.     echo The operation completed successfully.
  264.     echo.
  265. )
  266. :: ------------------------------------------------------------------------
  267.  
  268. :: ------------------------------------------------------------------------
  269. :: Delete keys in the Registry.
  270. cls
  271. echo.
  272. echo Microsoft %name% [Versi?n: %version%]
  273. echo Reset Windows Update Components Tool.
  274. echo.
  275. echo Deleting values in the Registry.
  276. echo.
  277. reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /f
  278. reg delete "HKLM\COMPONENTS\PendingXmlIdentifier" /f
  279. reg delete "HKLM\COMPONENTS\NextQueueEntryIndex" /f
  280. reg delete "HKLM\COMPONENTS\AdvancedInstallersNeedResolving" /f
  281. :: ------------------------------------------------------------------------
  282.  
  283. :: ------------------------------------------------------------------------
  284. :: Add keys in the Registry.
  285. cls
  286. echo.
  287. echo Microsoft %name% [Versi?n: %version%]
  288. echo Reset Windows Update Components Tool.
  289. echo.
  290. echo Adding values in the Registry.
  291. echo.
  292. reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v AppData /t REG_EXPAND_SZ /d "%USERPROFILE%\AppData\Roaming" /f  
  293. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v AppData /t REG_EXPAND_SZ /d "%USERPROFILE%\AppData\Roaming" /f  
  294. reg add "HKU\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v AppData /t REG_EXPAND_SZ /d "%USERPROFILE%\AppData\Roaming" /f  
  295. reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v AllowOSUpgrade /t REG_DWORD /d 1 /f
  296.  
  297. reg add "HKLM\SYSTEM\CurrentControlSet\Control\BackupRestore\FilesNotToBackup" /f
  298.  
  299. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\update" /v http /t REG_DWORD /d 2 /f
  300. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\update" /v https /t REG_DWORD /d 2 /f
  301. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\windowsupdate" /v http /t REG_DWORD /d 2 /f
  302. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\update.microsoft.com" /v http /t REG_DWORD /d 2 /f
  303. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\update.microsoft.com" /v https /t REG_DWORD /d 2 /f
  304. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windowsupdate.com" /v http /t REG_DWORD /d 2 /f
  305. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windowsupdate.microsoft.com" /v http /t REG_DWORD /d 2 /f
  306. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\download.microsoft.com" /v http /t REG_DWORD /d 2 /f
  307.  
  308. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windowsupdate.com" /v http /t REG_DWORD /d 2 /f
  309. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windowsupdate.com" /v https /t REG_DWORD /d 2 /f
  310.  
  311. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windowsupdate.com\download" /v http /t REG_DWORD /d 2 /f
  312. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windowsupdate.com\download" /v https /t REG_DWORD /d 2 /f
  313. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\download.windowsupdate.com" /v http /t REG_DWORD /d 2 /f
  314. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\download.windowsupdate.com" /v https /t REG_DWORD /d 2 /f
  315.  
  316. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windows.com\wustat" /v http /t REG_DWORD /d 2 /f
  317. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\wustat.windows.com" /v http /t REG_DWORD /d 2 /f
  318.  
  319. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\ntservicepack" /v http /t REG_DWORD /d 2 /f
  320. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\ntservicepack.microsoft.com" /v http /t REG_DWORD /d 2 /f
  321.  
  322. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\ws" /v http /t REG_DWORD /d 2 /f
  323. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\ws" /v https /t REG_DWORD /d 2 /f
  324. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\ws.microsoft.com" /v http /t REG_DWORD /d 2 /f
  325. reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\ws.microsoft.com" /v https /t REG_DWORD /d 2 /f
  326. :: ------------------------------------------------------------------------
  327.  
  328. :: ------------------------------------------------------------------------
  329. :: End process.
  330. cls
  331. echo.
  332. echo Microsoft %name% [Versi?n: %version%]
  333. echo Reset Windows Update Components Tool.
  334. echo.
  335. echo The operation completed successfully.
  336. echo.
  337. echo Press any key to continue . . .  
  338. pause>nul
  339. goto Menu
  340. :: ------------------------------------------------------------------------
  341.  
  342. :: /*************************************************************************************/
  343.  
  344.  
  345. :: Run the reset Windows Update components.
  346. :: /*************************************************************************************/
  347. :Reset
  348.  
  349. :: ------------------------------------------------------------------------
  350. :: Stopping the Windows Update services.
  351. cls
  352. echo.
  353. echo Microsoft %name% [Versi?n: %version%]
  354. echo Reset Windows Update Components Tool.
  355. echo.
  356. echo Stopping the Windows Update services.
  357. echo.
  358. net stop bits
  359.  
  360. cls
  361. echo.
  362. echo Microsoft %name% [Versi?n: %version%]
  363. echo Reset Windows Update Components Tool.
  364. echo.
  365. echo Stopping the Windows Update services.
  366. echo.
  367. net stop wuauserv
  368.  
  369. cls
  370. echo.
  371. echo Microsoft %name% [Versi?n: %version%]
  372. echo Reset Windows Update Components Tool.
  373. echo.
  374. echo Stopping the Windows Update services.
  375. echo.
  376. net stop appidsvc
  377.  
  378. cls
  379. echo.
  380. echo Microsoft %name% [Versi?n: %version%]
  381. echo Reset Windows Update Components Tool.
  382. echo.
  383. echo Stopping the Windows Update services.
  384. echo.
  385. net stop cryptsvc
  386. :: ------------------------------------------------------------------------
  387.  
  388. :: ------------------------------------------------------------------------
  389. :: Checking the services status.
  390. cls
  391. echo.
  392. echo Microsoft %name% [Versi?n: %version%]
  393. echo Reset Windows Update Components Tool.
  394. echo.
  395. echo Checking the services status.
  396. echo.
  397. sc query bits | findstr /I /C:"STOPPED"
  398. If not %errorlevel%==0 (
  399.     echo Failed to stop the BITS service.
  400.     echo.
  401.     echo Press any key to continue . . .  
  402.     pause>nul
  403.     goto Close
  404. )
  405.  
  406. cls
  407. echo.
  408. echo Microsoft %name% [Versi?n: %version%]
  409. echo Reset Windows Update Components Tool.
  410. echo.
  411. echo Checking the services status.
  412. echo.
  413. sc query wuauserv | findstr /I /C:"STOPPED"
  414. if not %errorlevel%==0 (
  415.     echo Failed to stop the Windows Update service.
  416.     echo.
  417.     echo Press any key to continue . . .  
  418.     pause>nul
  419.     goto Close
  420. )
  421.  
  422. cls
  423. echo.
  424. echo Microsoft %name% [Versi?n: %version%]
  425. echo Reset Windows Update Components Tool.
  426. echo.
  427. echo Checking the services status.
  428. echo.
  429. sc query appidsvc | findstr /I /C:"STOPPED"
  430. if not %errorlevel%==0 (
  431.     sc query appidsvc | findstr /I /C:"OpenService FAILED 1060"
  432.     if not %errorlevel%==0 (
  433.         echo Failed to stop the Application Identity service.
  434.         echo.
  435.         echo Press any key to continue . . .  
  436.         pause>nul
  437.         goto Close
  438.     )
  439. )
  440.  
  441. cls
  442. echo.
  443. echo Microsoft %name% [Versi?n: %version%]
  444. echo Reset Windows Update Components Tool.
  445. echo.
  446. echo Checking the services status.
  447. echo.
  448. sc query cryptsvc | findstr /I /C:"STOPPED"
  449. If not %errorlevel%==0 (
  450.     echo Failed to stop the Cryptographic Services service.
  451.     echo.
  452.     echo Press any key to continue . . .  
  453.     pause>nul
  454.     goto Close
  455. )
  456. :: ------------------------------------------------------------------------
  457.  
  458. :: ------------------------------------------------------------------------
  459. :: Delete the qmgr*.dat files.
  460. cls
  461. echo.
  462. echo Microsoft %name% [Versi?n: %version%]
  463. echo Reset Windows Update Components Tool.
  464. echo.
  465. echo Deleting the qmgr*.dat files.
  466. echo.
  467. del /s /q /f "%ALLUSERSPROFILE%\Application Data\Microsoft\Network\Downloader\qmgr*.dat"
  468. :: ------------------------------------------------------------------------
  469.  
  470. :: ------------------------------------------------------------------------
  471. :: Renaming the softare distribution folders backup copies.
  472. cls
  473. echo.
  474. echo Microsoft %name% [Versi?n: %version%]
  475. echo Reset Windows Update Components Tool.
  476. echo.
  477. echo Renaming the softare distribution folders backup copies.
  478. echo.
  479. cd /d %SYSTEMROOT%
  480.  
  481. if exist "%SYSTEMROOT%\winsxs\pending.xml" takeown /f "%SYSTEMROOT%\winsxs\pending.xml"
  482. if exist "%SYSTEMROOT%\winsxs\pending.xml" attrib -r -s -h "%SYSTEMROOT%\winsxs\pending.xml"
  483. if exist "%SYSTEMROOT%\winsxs\pending.xml.bak" del /s /q /f "%SYSTEMROOT%\winsxs\pending.xml.bak"
  484. if exist "%SYSTEMROOT%\winsxs\pending.xml" ren "%SYSTEMROOT%\winsxs\pending.xml" pending.xml.bak
  485.  
  486. if exist "%SYSTEMROOT%\SoftwareDistribution" attrib -r -s -h "%SYSTEMROOT%\SoftwareDistribution"
  487. if exist "%SYSTEMROOT%\SoftwareDistribution.bak" rmdir /s /q "%SYSTEMROOT%\SoftwareDistribution.bak"
  488. if exist "%SYSTEMROOT%\SoftwareDistribution" ren "%SYSTEMROOT%\SoftwareDistribution" SoftwareDistribution.bak
  489.  
  490. if exist "%SYSTEMROOT%\system32\Catroot2" attrib -r -s -h "%SYSTEMROOT%\system32\Catroot2"
  491. if exist "%SYSTEMROOT%\system32\Catroot2.bak" rmdir /s /q "%SYSTEMROOT%\system32\Catroot2.bak"
  492. if exist "%SYSTEMROOT%\system32\Catroot2" ren "%SYSTEMROOT%\system32\Catroot2" Catroot2.bak
  493.  
  494. if exist "%SYSTEMROOT%\WindowsUpdate.log" attrib -r -s -h "%SYSTEMROOT%\WindowsUpdate.log"
  495. if exist "%SYSTEMROOT%\WindowsUpdate.log.bak" del /s /q /f "%SYSTEMROOT%\WindowsUpdate.log.bak"
  496. if exist "%SYSTEMROOT%\WindowsUpdate.log" ren "%SYSTEMROOT%\WindowsUpdate.log" WindowsUpdate.log.bak
  497. :: ------------------------------------------------------------------------
  498.  
  499. :: ------------------------------------------------------------------------
  500. :: Reset the BITS service and the Windows Update service to the default security descriptor.
  501. cls
  502. echo.
  503. echo Microsoft %name% [Versi?n: %version%]
  504. echo Reset Windows Update Components Tool.
  505. echo.
  506. echo Reset the BITS service and the Windows Update service to the default security descriptor.
  507. echo.
  508. sc.exe sdset bits D:(A
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement