This Script allow reset the Windows Update Agent resolving issues with Windows Update. Author: Manuel Gil. Description This script allow reset the Windows Update Agent resolving issues whit Windows Update. Infomation Development This script can be modificated to be compatible With others operative systems. For more information about the version of system https://en.wikipedia.org/wiki/Ver_(Command). For more information about Windows Update Components https://support.microsoft.com/en-us/kb/971058. Windows Shell Script Code: :: ================================================================================== :: NAME : Reset Windows Update Components. :: DESCRIPTION : This script reset the Windows Update Components. :: AUTOR : Manuel Gil. :: VERSION : 8.0. :: ================================================================================== :: CMD Screen Settings. :: /************************************************************************************/ echo off title Reset Windows Update Components. color 17 cls :: /************************************************************************************/ :: Checking for Administrator elevation. :: /************************************************************************************/ openfiles>nul 2>&1 if %errorlevel%==0 goto Variables cls ver echo Reset Windows Update Components Tool. echo. echo Checking for Administrator elevation. echo. echo You are not running as Administrator. echo This batch cannot do it's job without elevation. echo. echo You must run this tool as Administrator. echo. echo Press any key to continue . . . pause>nul goto Close :: /************************************************************************************/ :: Set variables. :: /************************************************************************************/ :Variables set version=0.0.0000 set name=Windows set allow=0 for /f "tokens=4-5 delims=[] " %%a in ('ver') do set version=%%a %%b for %%a in (%version%) do set version=%%a if %version%==5.1.2600 ( set name=Windows XP set allow=1 ) if %version%==5.2.3790 ( set name=Windows XP Professional x64 Edition set allow=1 ) if %version%==6.0.6000 ( set name=Windows Vista set allow=1 ) if %version%==6.0.6001 ( set name=Windows Vista SP1 set allow=1 ) if %version%==6.0.6002 ( set name=Windows Vista SP2 set allow=1 ) if %version%==6.1.7600 ( set name=Windows 7 set allow=1 ) if %version%==6.1.7601 ( set name=Windows 7 SP1 set allow=1 ) if %version%==6.2.9200 ( set name=Windows 8 set allow=1 ) if %version%==6.3.9200 ( set name=Windows 8.1 set allow=1 ) if %version%==6.3.9600 ( set name=Windows 8.1 Update 1 set allow=1 ) if %version%==10.0.10240 ( set name=Windows 10 set allow=1 ) if %version%==10.0.10565 ( set name=Windows 10 Insider set allow=1 ) cls ver echo Reset Windows Update Components Tool. echo. echo Microsoft %name% detected . . . -echo. if %allow%==0 echo Sorry, this Operative System is not compatible whit this tool. if %allow%==1 goto Terms echo. echo An error occurred while attempting to verify your system. echo Can this using a business or test version. echo. echo If not, verify that your system has the correct security fix. echo. echo Press any key to continue . . . pause>nul goto Close :: /************************************************************************************/ :: Terms. :: /*************************************************************************************/ :Terms cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo The methods inside this batch modify files and registry settings. echo While they are tested and tend to work, I take no responsibility for echo the use of this file. echo This batch is provided without warranty. Any damage caused is your echo own responsibility. echo. echo As well, batch files are almost always flagged by anti-virus, feel free echo to review the code if you're unsure. echo. choice /c YN /n /m "Do you want to continue with this process? (Yes/No) " if %errorlevel%==1 goto Menu if %errorlevel%==2 goto Close echo. echo An unexpected error has occurred. echo. echo Press any key to continue . . . pause>nul goto Close :: /*************************************************************************************/ :: Menu of tool. :: /*************************************************************************************/ :Menu cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo 1. Change invalid values in the Registry. echo 2. Reset Windows Update Components. echo 3. Delete temporary files in Windows. echo 4. Open the Internet Explorer options. echo 5. Reset the Winsock settings. echo 6. Search updates. echo 7. Explore other local solutions. echo 8. Explore other online solutions. echo 9. Restart your PC. echo 0. Close. echo. set /p Opcion= Select an option: if %Opcion%==1 goto Regedit if %Opcion%==2 goto Reset if %Opcion%==3 goto Temp if %Opcion%==4 goto Historic if %Opcion%==5 goto Winsock if %Opcion%==6 goto Search if %Opcion%==7 goto Local if %Opcion%==8 goto Online if %Opcion%==9 goto Restart if %Opcion%==0 goto Close echo. echo Invalid option. echo. echo Press any key to continue . . . pause>nul goto Menu :: /*************************************************************************************/ :: Change invalid values. :: /*************************************************************************************/ :Regedit for /f "tokens=1-5 delims=/, " %%a in ("%date%") do ( set now=%%a%%b%%c%%d%time:~0,2%%time:~3,2% ) :: ------------------------------------------------------------------------ :: Create a backup of the Registry. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Making a backup copy of the Registry in: %USERPROFILE%\Desktop\Backup%now%.reg echo. if exist "%USERPROFILE%\Desktop\Backup%now%.reg" ( echo An unexpected error has occurred. echo. echo Changes were not carried out in the registry. echo Will try it later. echo. echo Press any key to continue . . . pause>nul goto Menu ) else ( regedit /e "%USERPROFILE%\Desktop\Backup%now%.reg" ) :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: Checking backup. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Checking the backup copy. echo. if not exist "%USERPROFILE%\Desktop\Backup%now%.reg" ( echo An unexpected error has occurred. echo. echo Something went wrong. echo You manually create a backup of the registry before continuing. echo. echo Press any key to continue . . . pause>nul ) else ( echo The operation completed successfully. echo. ) :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: Delete keys in the Registry. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Deleting values in the Registry. echo. reg delete "HKLM\SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate" /f reg delete "HKLM\COMPONENTS\PendingXmlIdentifier" /f reg delete "HKLM\COMPONENTS\NextQueueEntryIndex" /f reg delete "HKLM\COMPONENTS\AdvancedInstallersNeedResolving" /f :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: Add keys in the Registry. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Adding values in the Registry. echo. reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v AppData /t REG_EXPAND_SZ /d "%USERPROFILE%\AppData\Roaming" /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v AppData /t REG_EXPAND_SZ /d "%USERPROFILE%\AppData\Roaming" /f reg add "HKU\.DEFAULT\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v AppData /t REG_EXPAND_SZ /d "%USERPROFILE%\AppData\Roaming" /f reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate" /v AllowOSUpgrade /t REG_DWORD /d 1 /f reg add "HKLM\SYSTEM\CurrentControlSet\Control\BackupRestore\FilesNotToBackup" /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\update" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\update" /v https /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\windowsupdate" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\update.microsoft.com" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\update.microsoft.com" /v https /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windowsupdate.com" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windowsupdate.microsoft.com" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\download.microsoft.com" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windowsupdate.com" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windowsupdate.com" /v https /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windowsupdate.com\download" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windowsupdate.com\download" /v https /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\download.windowsupdate.com" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\download.windowsupdate.com" /v https /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windows.com\wustat" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\wustat.windows.com" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\ntservicepack" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\ntservicepack.microsoft.com" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\ws" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\ws" /v https /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\ws.microsoft.com" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\ws.microsoft.com" /v https /t REG_DWORD /d 2 /f :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: End process. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo The operation completed successfully. echo. echo Press any key to continue . . . pause>nul goto Menu :: ------------------------------------------------------------------------ :: /*************************************************************************************/ :: Run the reset Windows Update components. :: /*************************************************************************************/ :Reset :: ------------------------------------------------------------------------ :: Stopping the Windows Update services. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Stopping the Windows Update services. echo. net stop bits cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Stopping the Windows Update services. echo. net stop wuauserv cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Stopping the Windows Update services. echo. net stop appidsvc cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Stopping the Windows Update services. echo. net stop cryptsvc :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: Checking the services status. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Checking the services status. echo. sc query bits | findstr /I /C:"STOPPED" If not %errorlevel%==0 ( echo Failed to stop the BITS service. echo. echo Press any key to continue . . . pause>nul goto Close ) cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Checking the services status. echo. sc query wuauserv | findstr /I /C:"STOPPED" if not %errorlevel%==0 ( echo Failed to stop the Windows Update service. echo. echo Press any key to continue . . . pause>nul goto Close ) cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Checking the services status. echo. sc query appidsvc | findstr /I /C:"STOPPED" if not %errorlevel%==0 ( sc query appidsvc | findstr /I /C:"OpenService FAILED 1060" if not %errorlevel%==0 ( echo Failed to stop the Application Identity service. echo. echo Press any key to continue . . . pause>nul goto Close ) ) cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Checking the services status. echo. sc query cryptsvc | findstr /I /C:"STOPPED" If not %errorlevel%==0 ( echo Failed to stop the Cryptographic Services service. echo. echo Press any key to continue . . . pause>nul goto Close ) :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: Delete the qmgr*.dat files. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Deleting the qmgr*.dat files. echo. del /s /q /f "%ALLUSERSPROFILE%\Application Data\Microsoft\Network\Downloader\qmgr*.dat" :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: Renaming the softare distribution folders backup copies. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Renaming the softare distribution folders backup copies. echo. cd /d %SYSTEMROOT% if exist "%SYSTEMROOT%\winsxs\pending.xml" takeown /f "%SYSTEMROOT%\winsxs\pending.xml" if exist "%SYSTEMROOT%\winsxs\pending.xml" attrib -r -s -h "%SYSTEMROOT%\winsxs\pending.xml" if exist "%SYSTEMROOT%\winsxs\pending.xml.bak" del /s /q /f "%SYSTEMROOT%\winsxs\pending.xml.bak" if exist "%SYSTEMROOT%\winsxs\pending.xml" ren "%SYSTEMROOT%\winsxs\pending.xml" pending.xml.bak if exist "%SYSTEMROOT%\SoftwareDistribution" attrib -r -s -h "%SYSTEMROOT%\SoftwareDistribution" if exist "%SYSTEMROOT%\SoftwareDistribution.bak" rmdir /s /q "%SYSTEMROOT%\SoftwareDistribution.bak" if exist "%SYSTEMROOT%\SoftwareDistribution" ren "%SYSTEMROOT%\SoftwareDistribution" SoftwareDistribution.bak if exist "%SYSTEMROOT%\system32\Catroot2" attrib -r -s -h "%SYSTEMROOT%\system32\Catroot2" if exist "%SYSTEMROOT%\system32\Catroot2.bak" rmdir /s /q "%SYSTEMROOT%\system32\Catroot2.bak" if exist "%SYSTEMROOT%\system32\Catroot2" ren "%SYSTEMROOT%\system32\Catroot2" Catroot2.bak if exist "%SYSTEMROOT%\WindowsUpdate.log" attrib -r -s -h "%SYSTEMROOT%\WindowsUpdate.log" if exist "%SYSTEMROOT%\WindowsUpdate.log.bak" del /s /q /f "%SYSTEMROOT%\WindowsUpdate.log.bak" if exist "%SYSTEMROOT%\WindowsUpdate.log" ren "%SYSTEMROOT%\WindowsUpdate.log" WindowsUpdate.log.bak :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: Reset the BITS service and the Windows Update service to the default security descriptor. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Reset the BITS service and the Windows Update service to the default security descriptor. echo. sc.exe sdset bits D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU) sc.exe sdset wuauserv D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU) :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: Reregister the BITS files and the Windows Update files. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Reregister the BITS files and the Windows Update files. echo. cd /d %WINDIR%\system32 regsvr32.exe /s atl.dll regsvr32.exe /s urlmon.dll regsvr32.exe /s mshtml.dll regsvr32.exe /s shdocvw.dll regsvr32.exe /s browseui.dll regsvr32.exe /s jscript.dll regsvr32.exe /s vbscript.dll regsvr32.exe /s scrrun.dll regsvr32.exe /s msxml.dll regsvr32.exe /s msxml3.dll regsvr32.exe /s msxml6.dll regsvr32.exe /s actxprxy.dll regsvr32.exe /s softpub.dll regsvr32.exe /s wintrust.dll regsvr32.exe /s dssenh.dll regsvr32.exe /s rsaenh.dll regsvr32.exe /s gpkcsp.dll regsvr32.exe /s sccbase.dll regsvr32.exe /s slbcsp.dll regsvr32.exe /s cryptdlg.dll regsvr32.exe /s oleaut32.dll regsvr32.exe /s ole32.dll regsvr32.exe /s shell32.dll regsvr32.exe /s initpki.dll regsvr32.exe /s wuapi.dll regsvr32.exe /s wuaueng.dll regsvr32.exe /s wuaueng1.dll regsvr32.exe /s wucltui.dll regsvr32.exe /s wups.dll regsvr32.exe /s wups2.dll regsvr32.exe /s wuweb.dll regsvr32.exe /s qmgr.dll regsvr32.exe /s qmgrprxy.dll regsvr32.exe /s wucltux.dll regsvr32.exe /s muweb.dll regsvr32.exe /s wuwebv.dll :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: Resetting Winsock. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Resetting Winsock. echo. netsh winsock reset :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: Resetting WinHTTP Proxy. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Resetting WinHTTP Proxy. echo. netsh winhttp reset proxy :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: Starting the Windows Update services. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Starting the Windows Update services. echo. net start bits cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Starting the Windows Update services. echo. net start wuauserv cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Starting the Windows Update services. echo. net start appidsvc cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Starting the Windows Update services. echo. net start cryptsvc :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: End process. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo The operation completed successfully. echo. echo Press any key to continue . . . pause>nul goto Menu :: ------------------------------------------------------------------------ :: /*************************************************************************************/ :: Delete temporary files in Windows. :: /*************************************************************************************/ :Temp cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Deleting temporary files in Windows. echo. cd /d %TEMP% del /s /f /q *.* echo. echo Press any key to continue . . . pause>nul goto Menu :: /*************************************************************************************/ :: Open the Internet Explorer options. :: /*************************************************************************************/ :Historic cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Opening the Internet Explorer options. echo. start InetCpl.cpl goto Menu :: /*************************************************************************************/ :: Reset Winsock setting. :: /*************************************************************************************/ :Winsock :: ------------------------------------------------------------------------ :: Reset Winsock control. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Restoring TPC/IP. echo. netsh int ip reset cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Restoring Winsock. echo. netsh winsock reset cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Restoring default policy settings. echo. netsh advfirewall reset cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Restoring the DNS cache. echo. ipconfig /flushdns cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Restoring the Proxy. echo. netsh winhttp reset proxy :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: End process. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo The operation completed successfully. echo. echo Press any key to continue . . . pause>nul goto Menu :: ------------------------------------------------------------------------ :: /*************************************************************************************/ :: Search Updates. :: /*************************************************************************************/ :Search cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Looking for updates. echo. echo Take a few minutes. echo. echo Press any key to continue . . . pause>nul if %version%==10.0.10240 ( start ms-settings:windowsupdate ) else ( if %version%==10.0.10547 ( start ms-settings:windowsupdate ) else ( start wuapp.exe ) ) cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Looking for updates. echo. echo Wait . . . echo. wuauclt /resetauthorization /detectnow goto Menu :: /*************************************************************************************/ :: Explore other local solutions. :: /*************************************************************************************/ :Local cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Looking for solutions in this PC. echo. start control.exe /name Microsoft.Troubleshooting goto Menu :: /*************************************************************************************/ :: Explore other online solutions. :: /*************************************************************************************/ :Online cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Looking for solutions Online. echo. start https://support.microsoft.com/en-us/gp/windows-update-issues/ goto Menu :: /*************************************************************************************/ :: Reboot the system. :: /*************************************************************************************/ :Restart cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. start shutdown.exe /r /t 30 /c "The system reboot in 30 seconds. Please save all open documents." echo The system reboot in 30 seconds. echo Please save all open documents. echo. echo Press any key to continue . . . pause>nul goto Menu :: /*************************************************************************************/ :: End tool. :: /*************************************************************************************/ :Close exit :: /*************************************************************************************/ DL https://gallery.technet.microsoft.com/scriptcenter/Reset-Windows-Update-Agent-d824badc#content Note: This is not mine. I haven't tested it or anything, I'm just passing/sharing the script...
you really shoudl take a look at call commands.. that would reduce your batch about 50% if you do it the right way.
Those are just a few examples... and doesn't cover all things I get in mind but i think you get the point... This is more pseudocode than running/real code. Code: - I don't see any need for this part: - All parts with Windows Version or Windows Edition text.. no need. :: Set variables. :: /************************************************************************************/ :Variables -It's recommended to write errorlevels from big to small as you're than able to run several actions (if not one exclusive like with goto). -Create a small structure for textoutput. Example: call :TopText "The titel of the section or whatever you want" call :ActionX call :ButtomText "Here select something..." :TopText echo. echo "%~1" echo. goto :EOF -Variable for redundant information: e.g.: reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\update" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\update" /v https /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\microsoft.com\windowsupdate" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\update.microsoft.com" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\update.microsoft.com" /v https /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windowsupdate.com" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\windowsupdate.microsoft.com" /v http /t REG_DWORD /d 2 /f reg add "HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains\download.microsoft.com" /v http /t REG_DWORD /d 2 /f to something like: :ChangeSomeSettings set RegKey=HKLM\Software\Microsoft\Windows\CurrentVersion\Internet Settings\ZoneMap\Domains call :AddRegValue "microsoft.com\update" "http" "2" call :AddRegValue "microsoft.com\update" "https" "2" etc. etc.... goto :EOF :AddRegValue reg add "%RegKey%\%~1" /v "%~2" /t REG_DWORD /d "%~3" /f goto :EOF In this specific example if would do it quite different but anyway. I think you see what's going on... -If exist... instead of: if exist "%SYSTEMROOT%\winsxs\pending.xml" takeown /f "%SYSTEMROOT%\winsxs\pending.xml" if exist "%SYSTEMROOT%\winsxs\pending.xml" attrib -r -s -h "%SYSTEMROOT%\winsxs\pending.xml" if exist "%SYSTEMROOT%\winsxs\pending.xml.bak" del /s /q /f "%SYSTEMROOT%\winsxs\pending.xml.bak" if exist "%SYSTEMROOT%\winsxs\pending.xml" ren "%SYSTEMROOT%\winsxs\pending.xml" pending.xml.bak if exist "%SYSTEMROOT%\SoftwareDistribution" attrib -r -s -h "%SYSTEMROOT%\SoftwareDistribution" if exist "%SYSTEMROOT%\SoftwareDistribution.bak" rmdir /s /q "%SYSTEMROOT%\SoftwareDistribution.bak" if exist "%SYSTEMROOT%\SoftwareDistribution" ren "%SYSTEMROOT%\SoftwareDistribution" SoftwareDistribution.bak if exist "%SYSTEMROOT%\system32\Catroot2" attrib -r -s -h "%SYSTEMROOT%\system32\Catroot2" if exist "%SYSTEMROOT%\system32\Catroot2.bak" rmdir /s /q "%SYSTEMROOT%\system32\Catroot2.bak" if exist "%SYSTEMROOT%\system32\Catroot2" ren "%SYSTEMROOT%\system32\Catroot2" Catroot2.bak if exist "%SYSTEMROOT%\WindowsUpdate.log" attrib -r -s -h "%SYSTEMROOT%\WindowsUpdate.log" if exist "%SYSTEMROOT%\WindowsUpdate.log.bak" del /s /q /f "%SYSTEMROOT%\WindowsUpdate.log.bak" if exist "%SYSTEMROOT%\WindowsUpdate.log" ren "%SYSTEMROOT%\WindowsUpdate.log" WindowsUpdate.log.bak to: try this: call :RenFile "%SYSTEMROOT%\winsxs\pending.xml" call :RenFile "%SYSTEMROOT%\WindowsUpdate.log" call :RenFile "%SYSTEMROOT%\system32\Catroot2" "Folder" call :RenFile "%SYSTEMROOT%\SoftwareDistribution" :RenFile if exit "%~1" ( takeown /f "%~1" attrib -r -s -h "%~1" if /i [%~2] == [Folder] (rmdir "%~1.bak") else (del /s /q /f "%~1.bak") ren "%~1" ) goto :EOF Of course you can do it different or create an own "function" but I wouldn't see the need as most of the -code- is identical. this are all just untested examples/recommendations. I agree it's not easier to read but you can implement more functions WAY better and more consistent. If you find an error you fix all errors that belong the a function/section.
Code: :: Resetting Winsock. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Resetting Winsock. echo. netsh winsock reset :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: Resetting WinHTTP Proxy. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Resetting WinHTTP Proxy. echo. netsh winhttp reset proxy :: ------------------------------------------------------------------------ :: ------------------------------------------------------------------------ :: Starting the Windows Update services. cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo Starting the Windows Update services. echo. net start bits To: call :SomeOtherInfoStuff "Resetting Winsock.""netsh winsock reset" call :SomeOtherInfoStuff "Resetting WinHTTP Proxy.""netsh winhttp reset proxy" call :SomeOtherInfoStuff " Starting the Windows Update services.""net start bits" :SomeOtherInfoStuff cls echo. echo Microsoft %name% [Versi¢n: %version%] echo Reset Windows Update Components Tool. echo. echo %~1 echo. %~2 goto :EOF