[
  {
    "path": "CHANGELOG.md",
    "content": "# CHANGELOG\n\n> Name: Windows Update Loop Fix  \n> Author: aakkam22  \n> Last Updated : 17 December 2019\n\n## 5.X\n\n### 5.0\n\n* Rewrote the whole script\n* Updated documentation on GitHub\n\n## 4.X\n\n### 4.1.2\n\n* Project moved *OpenSource* to [GitHub](https://github.com/aakkam22/windowsUpdateLoopFix)\n* Added FAQ to documentation\n* Fixed a bug in the Administrator manifest\n\n### 4.1.1\n\n* Fixed an issue where the wizard would report insufficient privileges even when run as administrator\n* Minor improvements\n\n### 4.1\n\n* Major code audit and cleanup\n* Added %errorlevel%==2 for wusa.exe in stage 3\n* Improved the reliability of the file download code\n\n\n### 4.0\n\n* 32 and 64-bit sources merged into one script\n* Required updates are now downloaded directly from Internet (BETA)\n* UX and code improvements\n\n\n## 3.X\n\n* Compiled the program contents into a single .exe file for ease of use\n* UX and code improvements\n\n## 2.X\n\n* Added advanced options\n* Rewrote documentation\n* UX and code improvements\n\n## 1.X\n\n### 1.2\n\n* UX and code improvements\n\n### 1.1\n\n* Added prompt reminding users to extract the zip folder\n\n### 1.0\n\n* Initial Release\n"
  },
  {
    "path": "FAQ.md",
    "content": "# FAQ\n\n#### Don't see your problem? [Open an issue](https://github.com/aakkam22/windowsUpdateLoopFix/issues/new) on the GitHub repository.\n\n## Stage 3 hangs when installing the updates\n\nDepending on your configuration, the installation could take a long time to complete. If you've waited a reasonable amount of time, try these steps in order:\n\n**Perform a clean boot**\n\nAnother process might be interfering with or blocking installation, so run the wizard in a clean boot environment. A clean boot starts Windows with only the core system services and processes running. See [this](https://support.microsoft.com/en-us/help/929135/how-to-perform-a-clean-boot-in-windows) Microsoft Support article for instructions on performing a clean boot.\n\n**Install the System Update Readiness Tool**\n\nThe SURT was released by Microsoft in October 2014. It will check for and patch any known issues in your Windows Update data store that might be preventing other updates from installing. You can download the SURT [here](https://support.microsoft.com/en-us/help/947821/fix-windows-update-errors-by-using-the-dism-or-system-update-readiness).\n\n## The command prompt window hangs on \"Requesting administrative privileges\" after a reboot\n\nAfter your computer reboots, it is busy loading all of the services and startup items, and the script takes the lowest priority. Depending on your configuration, you may need to wait a minute or two to receive the UAC prompt.\n\n## My anti-virus program is flagging and removing the download. Does it contain malware?\n\nYou can read a detailed description of how this script works and how the .exe file was created in [README.MD.](README.MD)\n\nThis package was created with official 7-Zip modules and scanned with the latest anti-virus definitions before being uploaded to GitHub. However, some anti-virus programs' heuristics may err on the side of caution and flag it as malware. Please be assured it is not malware.\n\n## I get \"Unsupported Operating System\" but I am running Windows 7. \n\nMake sure that you have Service Pack 1 installed. You can download SP1 [here](https://www.microsoft.com/en-us/download/details.aspx?id=5842).\n"
  },
  {
    "path": "README.md",
    "content": "# Windows Update Loop Fix\n\n> An automated script to fix the \"Checking for Updates\" loop on Windows 7 SP1  \n\n## Overview\n\nAfter installing a fresh copy of Windows 7, Windows Update will hang when trying to check for updates. This problem occurs because a fresh copy of Windows 7 doesn't have the required updates to interface with Microsoft's servers. The fix is to download and install the following updates:\n\n- April 2015 servicing stack update for Windows 7 and Windows Server 2008 R2 (KB3020369)\n- July 2016 update rollup for Windows 7 SP1 and Windows Server 2008 R2 SP1 (KB3172605)\n- The latest Windows Update Agent for Windows 7 (v7.6.7600.256)\n\nThis script was written to automate the process. It is divided into three stages:\n\n1. Downloads the updates and resets all Windows Update components\n2. Installs the latest Windows Update Agent\n3. Installs KB3020369 and KB3172605\n\nYou can download and install the updates yourself, but running the script ensures that any previous Windows Update issues are cleared out before the updates are applied, and that the packages are installed in the correct order.\n\n## Compatibility\n\nTo install these updates or run this script, you should have Windows 7 with Service Pack 1 installed.\n\n## Instructions\n\n1. Download the latest release from [here](https://github.com/aakkam22/windowsUpdateLoopFix/releases)\n2. Exit any running applications\n3. Double-click the UpdateFix.exe file and follow the instructions\n\n###\n\n* The **\"Custom (Advanced Users Only)\"** option allows you to skip to a specific stage of the fix \n\n* For the best results, choose **\"Express Fix (Recommended)\"** to run through all the stages in order\n\nAn Internet Connection is required to download the updates, however, it is recommended to disconnect from the Internet once the updates have been downloaded. Doing so prevents Windows Update from attempting to connect while it is being serviced.\n\n## Package Safety\n\nThis script is comprised of three (3) individual batch files. The batch files were archived into .7z format and then the archive was used to create a 7-Zip Self-Extracting Archive using the official modules provided by Igor Pavlov. The .exe file was scanned with Windows Defender using the latest definitions available at the time of upload to GitHub.\n\n## How The Script Works\n\nWhen it is double-clicked, the self-extracting .exe file extracts three batch files to the Windows TEMP directory:\n\n- master.cmd\n- updates.cmd\n- cleanup.cmd\n\nAs its name suggests, \"master.cmd\" is the main batch file. It:\n\n1. Downloads the updates from Microsoft and stores them in C:\\packages\n2. Copies \"updates.cmd\" and \"cleanup.cmd\" to C:\\packages\n3. Resets Windows Update Components\n4. Installs the Windows Update Agent\n5. Sets the RunOnce registry key to run the next file, \"updates.cmd\" after the restart\n\nAfter the restart, updates.cmd unpacks the .msu files for KB3020369 and KB3172605 and installs them using DISM. A log file is created at C:\\install.log. It also sets the RunOnce registry key to run the final file, \"cleanup.cmd\".\n\nAfter the final restart, \"cleanup.cmd\" deletes the files in the C:\\packages folder, provides the user a summary of the operations, and then deletes itself.\n\n## Help\n\n* With the sunset of Windows 7, version 5.0 is likely the last version, unless a bug needs to be fixed.\n\n* See [FAQ.md](https://github.com/aakkam22/windowsUpdateLoopFix/blob/master/FAQ.md) for a list of frequently encountered problems and solutions.\n\n* See [CHANGELOG.md](https://github.com/aakkam22/windowsUpdateLoopFix/blob/master/CHANGELOG.md) for development history.\n\n* For all other feedback, please [open an issue](https://github.com/aakkam22/windowsUpdateLoopFix/issues/new) on the GitHub repository. Include error codes, screen-shots, and system details.\n\n## Terms of Use\n\nThis script will modify sensitive system files. Please ensure that your files are backed up before running this script. This script has been tested extensively. The author is not responsible for any data loss. \n"
  },
  {
    "path": "cleanup.cmd",
    "content": "@echo off\n\nREM NAME: Windows Update Loop Fix\nREM VERSION: 5.0\nREM BUILD DATE: 17 December 2019\nREM AUTHOR: aakkam22\n\nREM Function to elevate privileges\n:checkAdmin\nfsutil dirty query %systemdrive% >nul\n\tif '%errorlevel%' NEQ '0' (\n\t\techo Requesting administrative privileges...\n\t\tgoto uacPrompt\n\t) else ( goto gotAdmin )\n\n:uacPrompt\necho Set UAC = CreateObject^(\"Shell.Application\"^) > \"%temp%\\getadmin.vbs\"\nset params = %*:\"=\"\"\necho UAC.ShellExecute \"cmd.exe\", \"/c %~s0 %params%\", \"\", \"runas\", 1 >> \"%temp%\\getadmin.vbs\"\n\n\"%temp%\\getadmin.vbs\"\ndel \"%temp%\\getadmin.vbs\"\nexit /B\n\n:gotAdmin\npushd \"%CD%\"\nCD /D \"%~dp0\"\n\ncall :setWindow\ngoto cleanup\n\nREM Function to set the window properties\n:setWindow\ntitle Windows Update Loop Fix\nmode con cols=80 lines=40\ngoto :eof\n\nREM Function to print header\n:printHeader\ncls\necho.\necho %screen%\necho.\ngoto :eof\n\n:cleanup\nset screen=Cleanup\ncall :printHeader\necho The script is deleting leftover files...\nrmdir %systemdrive%\\packages\\3020369 /s /q >nul 2>&1\nrmdir %systemdrive%\\packages\\3172605 /s /q >nul 2>&1\ndel /q %systemdrive%\\packages\\3020369.msu >nul 2>&1\ndel /q %systemdrive%\\packages\\3172605.msu >nul 2>&1\ndel /q %systemdrive%\\packages\\wua.exe >nul 2>&1\ndel /q %systemdrive%\\packages\\updates.cmd >nul 2>&1\ndel /q %systemdrive%\\packages\\master.cmd >nul 2>&1\ngoto summary\n\n:summary\nset screen=Summary\ncall :printHeader\necho The script has finished running. You can now check for Windows Updates. \necho.\necho Please be patient when checking for updates for the first time. \necho Windows Update might still be registering brand new components.\necho.\necho NOTE: A DISM.EXE log for the update installations was created at:\necho.\necho.\t\"%systemdrive%\\install.log\"\necho.\necho Please choose an option:\necho.\necho.\t+-------------------------------+\necho.\t^|\t\t\t    \t^|\necho.\t^|  [1] Open Windows Update\t^|\necho.\t^|  [2] Go to GitHub Repository\t^|\necho.\t^|  [3] Exit\t\t   \t^|\necho.\t^|\t\t\t      \t^|\necho.\t+-------------------------------+\nchoice /c 123 /n\n\tif %errorlevel% EQU 1 start wuapp.exe && goto :sumarry\n\tif %errorlevel% EQU 2 start https://github.com/aakkam22/windowsUpdateLoopFix && goto :summary\n\tif %errorlevel% EQU 3 goto quit\n\n:quit\nSETLOCAL >nul 2>&1\nSET someOtherProgram=SomeOtherProgram.exe >nul 2>&1\nTASKKILL /IM \"%someOtherProgram%\" >nul 2>&1\nDEL \"%~f0\" >nul 2>&1\nexit \n"
  },
  {
    "path": "master.cmd",
    "content": "@echo off\n\nREM NAME: Windows Update Loop Fix\nREM VERSION: 5.0\nREM BUILD DATE: 17 December 2019\nREM AUTHOR: aakkam22\n\nREM check for elevated privileges\n:checkAdmin\nfsutil dirty query %systemdrive% >nul\n\tif '%errorlevel%' NEQ '0' (\n\t\techo Administrative privileges not detected. Now exiting...\n\t\ttimeout /t 7\n\t\texit\n\t) else ( goto setWindow )\n\nREM Function to set the window properties\n:setWindow\ntitle Windows Update Loop Fix\nmode con cols=80 lines=40\ngoto verifyOS\n\nREM Function verifies the the OS is Windows 7 with Service Pack 1\n:verifyOS\nfor /f \"tokens=4-5 delims=[] \" %%a in ('ver') do set version=%%a%%b\nfor %%a in (%version%) do set version=%%a\n\tif %version% == 6.1.7601 (\n\t\tgoto mainMenu\n\telse\n\t\tgoto invalidOS\n\t)\n\n:invalidOS\necho.\necho Unsupported Operating System Detected\necho.\necho This fix only applies to Windows 7 SP1. \necho If you are running Windows 7, please download Service Pack 1.\necho.\necho Press any key to exit.\npause>nul\nexit\n\nREM Function to print header\n:printHeader\ncls\necho.\necho %screen%\necho.\ngoto :eof\n\nREM Main menu options\n:mainMenu\ncls\nmode con cols=80 lines=40\necho.\necho Windows Update Loop Fix\necho Version 5.0\necho.\necho This script was written to fix the \"Checking for Updates\" loop that occurs on\necho Windows 7 systems.\necho.\necho Please choose an option:\necho.\necho.\t+------------------------------------------------+\necho.\t^|\t\t\t       \t\t\t ^|\necho.\t^|  [1] Express Fix (Recommended)\t         ^|\necho.\t^|\t\t\t       \t\t\t ^|\necho.\t^|  [2] Advanced Options (Advanced Users Only)    ^|\necho.\t^|\t\t\t       \t\t\t ^|\necho.\t^|  [3] Help\t\t        \t\t ^|\necho.\t^|\t\t\t       \t\t\t ^|\necho.\t^|  [4] Go to GitHub Repository  \t\t ^|\necho.\t^|\t\t\t       \t\t\t ^|\necho.\t^|\t\t\t       \t\t\t ^|\necho.\t^|  [5] Exit\t\t       \t\t\t ^|\necho.\t^|\t\t\t       \t\t\t ^|\necho.\t+------------------------------------------------+\nchoice /c 1234 /n\n\tif %errorlevel% EQU 1 set custom=false && goto termsOfUse\n\tif %errorlevel% EQU 2 goto chooseCustom\n\tif %errorlevel% EQU 3 start https://github.com/aakkam22/windowsUpdateLoopFix/blob/master/README.md && goto :mainMenu\n\tif %errorlevel% EQU 4 start https://github.com/aakkam22/windowsUpdateLoopFix && goto :mainMenu\n\tif %errorlevel% EQU 5 exit\n\t\n:chooseCustom\nset screen=Advanced Options (Advanced Users Only)\ncall :printHeader\necho This script is divided into 3 stages. Use this menu to start the script at a\necho specific stage.\necho.\necho.\t+---------------------------------------------------+\necho.\t^|\t\t\t\t\t\t    ^|\necho.\t^|  [1] Reset all Windows Update Components\t    ^|\necho.\t^|\t\t\t\t\t\t    ^|\necho.\t^|  [2] Install the latest Windows Update Agent      ^|\necho.\t^|\t\t\t\t\t\t    ^|\necho.\t^|  [3] Install KB3020369 and KB3172605              ^|\necho.\t^|\t\t\t\t\t\t    ^|\necho.\t^|\t\t\t\t\t\t    ^|\necho.\t^|  [4] Back\t\t\t\t  \t    ^|\necho.\t^|\t\t\t\t\t\t    ^|\necho.\t+---------------------------------------------------+\nchoice /c 1234 /n\n\tif %errorlevel% EQU 1 set custom=false && goto termsOfUse\n\tif %errorlevel% EQU 2 set custom=2 && goto termsOfUse\n\tif %errorlevel% EQU 3 set custom=3 && goto termsOfUse\n\tif %errorlevel% EQU 4 goto mainMenu\n\n:termsOfUse\nset screen=Important Information\ncall :printHeader\necho This script will modify sensitive system files. \necho Please ensure that your files are backed up before continuing.\necho The author of this script is not responsible for data loss.\necho.\necho An Internet connection is required to download the updates.\necho.\necho Press [A] to agree or [E] to exit.\nchoice /c AE /n\n\tif %errorlevel% EQU 1 goto determineArc\n\tif %errorlevel% EQU 2 exit\n\nREM determine whether the system is 32 or 64-bit\n:determineArc\nreg Query \"HKLM\\Hardware\\Description\\System\\CentralProcessor\\0\" | find /i \"x86\" > NUL && set arc=32BIT || set arc=64BIT >nul 2>&1\n\tif %arc%==32BIT goto download32\n\tif %arc%==64BIT goto download64\n\nREM function to clear the BITS queue and create the directories to store the updates to download\n:initializeDownload\necho Initializing...\n\nREM stop the Windows Update and BITS service so we can work with their file stores\nnet stop bits >nul 2>&1\nnet stop wuauserv >nul 2>&1\n\nREM flush the DNS cache\nipconfig /flushdns >nul 2>&1\n\nREM rename the old bits datastores, this clears any stuck jobs\nren \"%ALLUSERSPROFILE%\\Application Data\\Microsoft\\Network\\Downloader\\qmgr0.dat\" qmgr0.dat.old >nul 2>&1\nren \"%ALLUSERSPROFILE%\\Application Data\\Microsoft\\Network\\Downloader\\qmgr1.dat\" qmgr1.dat.old >nul 2>&1\n\nREM restart the BITS service, leave Windows Update off so it doesn't interfere with standalone installations\nnet start bits >nul 2>&1\n\nREM remove the packages directory if it's there and recreate it\nrmdir %systemdrive%\\packages /s /q >nul 2>&1\nmd %systemdrive%\\packages >nul 2>&1\n\nREM this variable will be used to detect download errors\nset downErr=false\ngoto :eof\t\n\t\nREM bits transfers for 32-bit systems\n:download32\nset screen=Downloading Updates\ncall :printHeader\necho Please wait while the updates are downloaded to the installation folders.\necho This could take several minutes depending on your connection speed.\necho.\necho Destination Directory: \"%systemdrive%\\packages\"\necho.\necho.\ncall :initializeDownload\necho Done!\necho.\n\necho Downloading Update for Windows 7 (KB3020369)...\nbitsadmin /transfer kb3020369 https://download.microsoft.com/download/C/0/8/C0823F43-BFE9-4147-9B0A-35769CBBE6B0/Windows6.1-KB3020369-x86.msu \"%systemdrive%\\packages\\3020369.msu\" >nul 2>&1\n\tif %errorlevel% EQU 0 echo Success!\n\tif %errorlevel% NEQ 0 set downErr=true && echo Download failed.\necho.\n\necho Downloading Update for Windows 7 (KB3172605)...\nbitsadmin /transfer kb3172605 https://download.microsoft.com/download/C/D/5/CD5DE7B2-E857-4BD4-AA9C-6B30C3E1735A/Windows6.1-KB3172605-x86.msu \"%systemdrive%\\packages\\3172605.msu\" >nul 2>&1\n\tif %errorlevel% EQU 0 echo Success!\n\tif %errorlevel% NEQ 0 set downErr=true && echo Download failed.\necho.\n\necho Downloading Windows Update Agent v7.6...\nbitsadmin /transfer wua http://download.windowsupdate.com/windowsupdate/redist/standalone/7.6.7600.320/windowsupdateagent-7.6-x86.exe \"%systemdrive%\\packages\\wua.exe\" >nul\n\tif %errorlevel% EQU 0 echo Success!\n\tif %errorlevel% NEQ 0 set downErr=true && echo Download failed.\necho.\n\necho Copying script files...\nxcopy /v /y updates.cmd %systemdrive%\\packages >nul 2>&1\nxcopy /v /y cleanup.cmd %systemdrive%\\packages >nul 2>&1\n\nREM take a count of the files in the packages directory to make sure all files are present\nset cnt=0\nfor %%A in (%systemdrive%\\packages\\*) do set /a cnt+=1\n\tif %cnt% NEQ 5 set downErr=true\necho.\n\nif %downErr%==true goto downFail\nif %downErr%==false goto downSuccess\n\nREM bits transfers for 64-bit systems\n:download64\nset screen=Downloading Updates\ncall :printHeader\necho Please wait while the updates are downloaded to the installation folder.\necho This could take several minutes depending on your connection speed.\necho.\necho Destination Directory: \"%systemdrive%\\packages\"\necho.\necho.\ncall :initializeDownload\necho Done!\necho.\n\necho Downloading Update for Windows 7 for x64-based Systems (KB3020369)...\nbitsadmin /transfer kb3020369 https://download.microsoft.com/download/5/D/0/5D0821EB-A92D-4CA2-9020-EC41D56B074F/Windows6.1-KB3020369-x64.msu \"%systemdrive%\\packages\\3020369.msu\" >nul 2>&1\n\tif %errorlevel% EQU 0 echo Success!\n\tif %errorlevel% NEQ 0 set downErr=true && echo Download failed.\necho.\n\necho Downloading Update for Windows 7 for x64-based Systems (KB3172605)...\nbitsadmin /transfer kb3172605 https://download.microsoft.com/download/5/6/0/560504D4-F91A-4DEB-867F-C713F7821374/Windows6.1-KB3172605-x64.msu \"%systemdrive%\\packages\\3172605.msu\" >nul 2>&1\n\tif %errorlevel% EQU 0 echo Success!\n\tif %errorlevel% NEQ 0 set downErr=true && echo Download failed.\necho.\n\necho Downloading Windows Update Agent v7.6...\nbitsadmin /transfer wua http://download.windowsupdate.com/windowsupdate/redist/standalone/7.6.7600.320/windowsupdateagent-7.6-x64.exe \"%systemdrive%\\packages\\wua.exe\" >nul\n\tif %errorlevel% EQU 0 echo Success!\n\tif %errorlevel% NEQ 0 set downErr=true && echo Download failed.\necho.\n\necho Copying script files...\nxcopy /v /y updates.cmd %systemdrive%\\packages >nul 2>&1\nxcopy /v /y cleanup.cmd %systemdrive%\\packages >nul 2>&1\n\nREM take a count of the files in the packages directory to make sure all files are present\nset cnt=0\nfor %%A in (%systemdrive%\\packages\\*) do set /a cnt+=1\n\tif %cnt% NEQ 5 set downErr=true\necho.\n\nif %downErr%==true goto downFail\nif %downErr%==false goto downSuccess\n\nREM if the download failed, exit the script\n:downFail\necho One or more of the required files could not be downloaded or copied.\necho Please contact the developer for help.\necho.\necho Press any key to exit.\npause>nul\nexit\n\n:downSuccess\ntimeout /t 2 /nobreak>nul\necho All files were downloaded successfully.\ntimeout /t 7\ngoto ready\n\nREM prompt the user to begin the fix process\n:ready\nset screen=Ready to Continue\ncall :printHeader\nif %custom% NEQ false echo (Advanced Option Selected - Will begin at Stage %custom%) && echo.\necho The script is now ready to run. Your computer will restart several times\necho during this process.\necho.\necho NOTE: It is strongly recommended to disconnect from the Internet now. \necho This prevents Windows Update from attempting to connect while it is \necho being serviced.\necho.\necho Save your work, close any open programs, and press any key to continue.\npause>nul\nif %custom% EQU false goto reset\nif %custom% EQU 2 goto wuaInstall\nif %custom% EQU 3 (\n\tcall %systemdrive%\\packages\\updates.cmd\n\texit\n)\n\nREM reset Windows Update components\n:reset\nset screen=Stage 1 of 3 (Resetting Windows Update Components)\ncall :printHeader\necho Please wait while the following actions are run:\necho.\necho.\n\necho.-^> Stopping Windows Update, BITS, and Cryptographic Services...\nnet stop bits /y >nul 2>&1\nnet stop wuauserv /y >nul 2>&1\nnet stop appidsvc /y >nul 2>&1\nnet stop cryptsvc /y >nul 2>&1\necho.\n\necho.-^> Deleting qmgr*.dat files...\nDel \"%ALLUSERSPROFILE%\\Application Data\\Microsoft\\Network\\Downloader\\qmgr*.dat\">nul 2>&1\necho.\n\necho.-^> Deleting SoftwareDistribution folders...\ncd /d %SYSTEMROOT%>nul 2>&1\n\tif exist \"%SYSTEMROOT%\\winsxs\\pending.xml.bak\" (\n\t\tdel /s /q /f \"%SYSTEMROOT%\\winsxs\\pending.xml.bak\">nul 2>&1\n\t)\n\tif exist \"%SYSTEMROOT%\\SoftwareDistribution.bak\" (\n\t\trmdir /s /q \"%SYSTEMROOT%\\SoftwareDistribution.bak\">nul 2>&1\n\t)\n\tif exist \"%SYSTEMROOT%\\system32\\Catroot2.bak\" (\n\t\trmdir /s /q \"%SYSTEMROOT%\\system32\\Catroot2.bak\">nul 2>&1\n\t)\n\tif exist \"%SYSTEMROOT%\\WindowsUpdate.log.bak\" (\n\t\tdel /s /q /f \"%SYSTEMROOT%\\WindowsUpdate.log.bak\">nul 2>&1\n\t)\n\tif exist \"%SYSTEMROOT%\\winsxs\\pending.xml\" (\n\t\ttakeown /f \"%SYSTEMROOT%\\winsxs\\pending.xml\">nul 2>&1\n\t\tattrib -r -s -h /s /d \"%SYSTEMROOT%\\winsxs\\pending.xml\">nul 2>&1\n\t\tren \"%SYSTEMROOT%\\winsxs\\pending.xml\" pending.xml.bak>nul 2>&1\n\t)\n\tif exist \"%SYSTEMROOT%\\SoftwareDistribution\" (\n\t\tattrib -r -s -h /s /d \"%SYSTEMROOT%\\SoftwareDistribution\">nul 2>&1\n\t\tren \"%SYSTEMROOT%\\SoftwareDistribution\" SoftwareDistribution.bak>nul 2>&1\n\t)\n\tif exist \"%SYSTEMROOT%\\system32\\Catroot2\" (\n\t\tattrib -r -s -h /s /d \"%SYSTEMROOT%\\system32\\Catroot2\">nul 2>&1\n\t\tren \"%SYSTEMROOT%\\system32\\Catroot2\" Catroot2.bak>nul 2>&1\n\t)\n\tif exist \"%SYSTEMROOT%\\WindowsUpdate.log\" (\n\t\tattrib -r -s -h /s /d \"%SYSTEMROOT%\\WindowsUpdate.log\">nul 2>&1\n\t\tren \"%SYSTEMROOT%\\WindowsUpdate.log\" WindowsUpdate.log.bak>nul 2>&1\n\t)\necho.\t\n\necho.-^> Resetting BITS and WUAUSERV to default security descriptors...\nsc.exe sdset bits D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)>nul 2>&1\nsc.exe sdset wuauserv D:(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCLCSWLOCRRC;;;AU)(A;;CCLCSWRPWPDTLOCRRC;;;PU)>nul 2>&1\necho.\n\necho.-^> Reregistering BITS and Windows Update files...\ncd /d %WINDIR%\\system32\nregsvr32.exe /s atl.dll\nregsvr32.exe /s urlmon.dll\nregsvr32.exe /s mshtml.dll\nregsvr32.exe /s shdocvw.dll\nregsvr32.exe /s browseui.dll\nregsvr32.exe /s jscript.dll\nregsvr32.exe /s vbscript.dll\nregsvr32.exe /s scrrun.dll\nregsvr32.exe /s msxml.dll\nregsvr32.exe /s msxml3.dll\nregsvr32.exe /s msxml6.dll\nregsvr32.exe /s actxprxy.dll\nregsvr32.exe /s softpub.dll\nregsvr32.exe /s wintrust.dll\nregsvr32.exe /s dssenh.dll\nregsvr32.exe /s rsaenh.dll\nregsvr32.exe /s gpkcsp.dll\nregsvr32.exe /s sccbase.dll\nregsvr32.exe /s slbcsp.dll\nregsvr32.exe /s cryptdlg.dll\nregsvr32.exe /s oleaut32.dll\nregsvr32.exe /s ole32.dll\nregsvr32.exe /s shell32.dll\nregsvr32.exe /s initpki.dll\nregsvr32.exe /s wuapi.dll\nregsvr32.exe /s wuaueng.dll\nregsvr32.exe /s wuaueng1.dll\nregsvr32.exe /s wucltui.dll\nregsvr32.exe /s wups.dll\nregsvr32.exe /s wups2.dll\nregsvr32.exe /s wuweb.dll\nregsvr32.exe /s qmgr.dll\nregsvr32.exe /s qmgrprxy.dll\nregsvr32.exe /s wucltux.dll\nregsvr32.exe /s muweb.dll\nregsvr32.exe /s wuwebv.dll\necho.\n\necho.-^> Resetting Winsock...\nnetsh winsock reset >nul 2>&1\necho.\n\necho.-^> Resetting WinHTTP proxy...\nnetsh winhttp reset proxy >nul 2>&1\necho.\n\n\necho.-^> Configuring service startup types...\nsc config wuauserv start= auto  >nul 2>&1\nsc config bits start= auto  >nul 2>&1\nsc config DcomLaunch start= auto  >nul 2>&1\nsc config appidsvc start= auto  >nul 2>&1\nsc config cryptsvc start=auto >nul 2>&1\necho. \n\necho.-^> Restarting services...\nnet start bits >nul 2>&1\nnet start wuauserv >nul 2>&1\nnet start appidsvc >nul 2>&1\nnet start cryptsvc >nul 2>&1\nnet start DcomLaunch >nul 2>&1\n\necho.\ntimeout /t 7\ngoto wuaInstall\n\nREM install Windows Update Agent\n:wuaInstall\nset screen=Stage 2 of 3 (Installing Windows Update Agent)\ncall :printHeader\necho Please wait while the Windows Update Agent is installed. \necho This could take several minutes to complete.\ncall %systemdrive%\\packages\\wua.exe /wuforce /quiet /norestart\necho.\n\tIF %errorlevel%==1609 IF NOT %errorlevel%==0 (\n\tgoto corrupt\n\t)\n\tIF %errorlevel%==3010 IF NOT %errorlevel%==0 (\n\tgoto success\n\t)\n\tIF %errorlevel%==0 (\n\tgoto success\n\t)\n\tIF %errorlevel%==2359302 IF NOT %errorlevel%==0 (\n\tgoto alreadyInstalled\n\t)\n\tIF NOT %errorlevel%==0 IF NOT %errorlevel%==2359302 (\n\tgoto installFail\n\t)\t\n\nREM error codes\n:corrupt\necho The package is corrupt or missing.\necho.\necho Press any key to continue.\npause>nul\ngoto restart\n\n:success\necho Success!\necho.\ntimeout /t 7\ngoto restart\n\n:alreadyInstalled\necho The latest agent is already installed.\necho.\ntimeout /t 7\ngoto restart\n\n:installFail\necho The agent could not be installed. The error code was %errorlevel%.\necho.\necho Press any key to continue.\npause>nul\ngoto restart\n\nREM set the RunOnce registry key to execute the updates.cmd script, then restart the computer\n:restart\nset screen=Restart Computer\ncall :printHeader\necho Your computer needs to restart to continue. \necho The script will continue after you log back on.\necho.\ntimeout /t 7\nreg add HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce /v updatesinstall /t REG_EXPAND_SZ /d %systemdrive%\\packages\\updates.cmd >nul 2>&1\nshutdown -r -t 0\n"
  },
  {
    "path": "updates.cmd",
    "content": "@echo off\n\nREM NAME: Windows Update Loop Fix\nREM VERSION: 5.0\nREM BUILD DATE: 17 December 2019\nREM AUTHOR: aakkam22\n\nREM Function to elevate privileges\n:checkAdmin\nfsutil dirty query %systemdrive% >nul\n\tif '%errorlevel%' NEQ '0' (\n\t\techo Requesting administrative privileges...\n\t\tgoto uacPrompt\n\t) else ( goto gotAdmin )\n\n:uacPrompt\necho Set UAC = CreateObject^(\"Shell.Application\"^) > \"%temp%\\getadmin.vbs\"\nset params = %*:\"=\"\"\necho UAC.ShellExecute \"cmd.exe\", \"/c %~s0 %params%\", \"\", \"runas\", 1 >> \"%temp%\\getadmin.vbs\"\n\n\"%temp%\\getadmin.vbs\"\ndel \"%temp%\\getadmin.vbs\"\nexit /B\n\n:gotAdmin\npushd \"%CD%\"\nCD /D \"%~dp0\"\n\ncall :setWindow\ngoto determineArc\n\nREM Function to set the window properties\n:setWindow\ntitle Windows Update Loop Fix\nmode con cols=80 lines=40\ngoto :eof\n\nREM Function to print header\n:printHeader\ncls\necho.\necho %screen%\necho.\ngoto :eof\n\nREM determine whether the system is 32 or 64-bit\n:determineArc\nreg Query \"HKLM\\Hardware\\Description\\System\\CentralProcessor\\0\" | find /i \"x86\" > NUL && set arc=32BIT || set arc=64BIT >nul 2>&1\n\tif %arc%==32BIT goto firstInstall32\n\tif %arc%==64BIT goto firstInstall64\n\n:updateHeader\nset screen=Stage 3 of 3 (Installing Updates)\ncall :printHeader\necho Please wait while the updates are installed.\necho.\ngoto :eof\n\nREM kb3020369 installation for 32-bit systems\n:firstInstall32\ncall :updateHeader\necho Installing KB3020369...\ntimeout /t 5 /nobreak>nul\nREM check if previous directory exists and remove it\nrmdir %systemdrive%\\packages\\3020369 /s /q >nul 2>&1 \nmd %systemdrive%\\packages\\3020369\nexpand -f:* \"%systemdrive%\\packages\\3020369.msu\" \"%systemdrive%\\packages\\3020369\" >nul 2>&1\n\ndism.exe /online /add-package /packagepath:\"%systemdrive%\\packages\\3020369\\Windows6.1-KB3020369-x86.cab\" /norestart /logpath:\"%systemdrive%\\install.log\"\ntimeout /t 5 /nobreak>nul\ngoto secondInstall32\n\nREM kb3172605 installation for 32-bit systems\n:secondInstall32\ncall :updateHeader\necho Installing KB3172605...\nREM check if previous directory exists and remove it\nrmdir %systemdrive%\\packages\\3172605 /s /q >nul 2>&1\nmd %systemdrive%\\packages\\3172605\nexpand -f:* \"%systemdrive%\\packages\\3172605.msu\" \"%systemdrive%\\packages\\3172605\" >nul 2>&1\n\ndism.exe /online /add-package /packagepath:\"%systemdrive%\\packages\\3172605\\Windows6.1-KB3172605-x86.cab\" /norestart /logpath:\"%systemdrive%\\install.log\"\necho.\ntimeout /t 7\ngoto restart\n\nREM kb3020369 installation for 64-bit systems\n:firstInstall64\ncall :updateHeader\necho Installing KB3020369...\ntimeout /t 5 /nobreak>nul\nREM check if previous directory exists and remove it\nrmdir %systemdrive%\\packages\\3020369 /s /q >nul 2>&1 \nmd %systemdrive%\\packages\\3020369\nexpand -f:* \"%systemdrive%\\packages\\3020369.msu\" \"%systemdrive%\\packages\\3020369\" >nul 2>&1\n\ndism.exe /online /add-package /packagepath:\"%systemdrive%\\packages\\3020369\\Windows6.1-KB3020369-x64.cab\" /norestart /logpath:\"%systemdrive%\\install.log\"\ntimeout /t 5 /nobreak>nul\ngoto secondInstall64\n\nREM kb3172605 installation for 64-bit systems\n:secondInstall64\ncall :updateHeader\necho Installing KB3172605...\nREM check if previous directory exists and remove it\nrmdir %systemdrive%\\packages\\3172605 /s /q >nul 2>&1\nmd %systemdrive%\\packages\\3172605\nexpand -f:* \"%systemdrive%\\packages\\3172605.msu\" \"%systemdrive%\\packages\\3172605\" >nul 2>&1\n\ndism.exe /online /add-package /packagepath:\"%systemdrive%\\packages\\3172605\\Windows6.1-KB3172605-x64.cab\" /norestart /logpath:\"%systemdrive%\\install.log\"\necho.\ntimeout /t 7\ngoto restart\n\nREM set the RunOnce registry key to execute the cleanup.cmd script, then restart the computer\n:restart\nset screen=Restart Computer\ncall :printHeader\necho Your computer needs to restart to continue. \necho The script will continue after you log back on.\necho.\ntimeout /t 7\nreg add HKCU\\Software\\Microsoft\\Windows\\CurrentVersion\\RunOnce /v updatesinstall /t REG_EXPAND_SZ /d %systemdrive%\\packages\\cleanup.cmd >nul 2>&1\nshutdown -r -t 0\n"
  }
]