Skip to content

Instantly share code, notes, and snippets.

@desbest
Last active December 27, 2023 13:56
Show Gist options
  • Save desbest/c276649333fff0d46f09a5de3ef71dde to your computer and use it in GitHub Desktop.
Save desbest/c276649333fff0d46f09a5de3ef71dde to your computer and use it in GitHub Desktop.
Reset Windows Update Agent

This Script allow reset the Windows Update Agent resolving issues with Windows Update

official website

Description

This script allow reset the Windows Update Agent resolving issues with Windows Update. Details

MD5: 80aafb099804c94709aba68908e88956

SHA1: ab5e743bb3347feba42655c5888125d9a124da8b

File size: 127.18 KB

File type: ZIP

Requirements

Windows XP, Windows Vista, Windows 7, Windows 8, Windows 8.1, Windows 10 and Windows 10 Insider Preview.

Infomation Development

The Reset Windows Update Tool brings changes in its latest version. Changes have been made to the code, it is now compatible with Windows 10 Creative Update and a change is proposed to make it a complete executable tool.

This script can be modificated to be compatible with others operative systems.

For more information about the version of system click here.

For more information about Windows Update Components click here.

For Spanish version click here.

:: Explore other online solutions.
:: void online();
:: /*************************************************************************************/
:online
call :print Looking for solutions Online.
start https://support.microsoft.com/en-us/gp/windows-update-issues/
goto :eof
:: /*************************************************************************************/
:: ==================================================================================
:: NAME: Reset Windows Update Tool.
:: DESCRIPTION: This script reset the Windows Update Components.
:: AUTHOR: Manuel Gil.
:: VERSION: 10.5.3.7
:: WEBSITE: http://wureset.com
:: ==================================================================================
:: Set console.
:: void mode();
:: /************************************************************************************/
:mode
echo off
title Reset Windows Update Tool.
mode con cols=80 lines=34
color 17
cls
goto getValues
goto :eof
:: /************************************************************************************/
:: Print Top Text.
:: @param - text = the text to print (%*).
:: void print(string text);
:: /*************************************************************************************/
:print
cls
echo.
echo.%name% [Version: %version%]
echo.Reset Windows Update Tool.
echo.
echo.%*
echo.
goto :eof
:: /*************************************************************************************/
:: Add Value in the Registry.
:: @param - key = the key or entry to be added (%~1).
:: value = the value to be added under the selected key (%~2).
:: type = the type for the registry entry (%~3).
:: data = the data for the new registry entry (%~4).
:: void addReg(string key, string value, string type, string data);
:: /*************************************************************************************/
:addReg
reg add "%~1" /v "%~2" /t "%~3" /d "%~4" /f
goto :eof
:: /*************************************************************************************/
:: Load the system values.
:: void getValues();
:: /************************************************************************************/
:getValues
for /f "tokens=4-5 delims=[] " %%a in ('ver') do set version=%%a%%b
for %%a in (%version%) do set version=%%a
if %version% EQU 5.1.2600 (
:: Name: "Microsoft Windows XP"
set name=Microsoft Windows XP
:: Family: Windows 5
set family=5
:: Compatibility: Yes
set allow=Yes
) else if %version% EQU 5.2.3790 (
:: Name: "Microsoft Windows XP Professional x64 Edition"
set name=Microsoft Windows XP Professional x64 Edition
:: Family: Windows 5
set family=5
:: Compatibility: Yes
set allow=Yes
) else if %version% EQU 6.0.6000 (
:: Name: "Microsoft Windows Vista"
set name=Microsoft Windows Vista
:: Family: Windows 6
set family=6
:: Compatibility: Yes
set allow=Yes
) else if %version% EQU 6.0.6001 (
:: Name: "Microsoft Windows Vista SP1"
set name=Microsoft Windows Vista SP1
:: Family: Windows 6
set family=6
:: Compatibility: Yes
set allow=Yes
) else if %version% EQU 6.0.6002 (
:: Name: "Microsoft Windows Vista SP2"
set name=Microsoft Windows Vista SP2
:: Family: Windows 6
set family=6
:: Compatibility: Yes
set allow=Yes
) else if %version% EQU 6.1.7600 (
:: Name: "Microsoft Windows 7"
set name=Microsoft Windows 7
:: Family: Windows 7
set family=7
:: Compatibility: Yes
set allow=Yes
) else if %version% EQU 6.1.7601 (
:: Name: "Microsoft Windows 7 SP1"
set name=Microsoft Windows 7 SP1
:: Family: Windows 7
set family=7
:: Compatibility: Yes
set allow=Yes
) else if %version% EQU 6.2.9200 (
:: Name: "Microsoft Windows 8"
set name=Microsoft Windows 8
:: Family: Windows 8
set family=8
:: Compatibility: Yes
set allow=Yes
) else if %version% EQU 6.3.9200 (
:: Name: "Microsoft Windows 8.1"
set name=Microsoft Windows 8.1
:: Family: Windows 8
set family=8
:: Compatibility: Yes
set allow=Yes
) else if %version% EQU 6.3.9600 (
:: Name: "Microsoft Windows 8.1 Update 1"
set name=Microsoft Windows 8.1 Update 1
:: Family: Windows 8
set family=8
:: Compatibility: Yes
set allow=Yes
) else (
ver | find "10.0." > nul
if %errorlevel% EQU 0 (
:: Name: "Microsoft Windows 10"
set name=Microsoft Windows 10
:: Family: Windows 10
set family=10
:: Compatibility: Yes
set allow=Yes
) else (
:: Name: "Unknown"
set name=Unknown
:: Compatibility: No
set allow=No
)
)
call :print %name% detected . . .
if %allow% EQU Yes goto permission
call :print Sorry, this Operative System is not compatible with this tool.
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 :eof
:: /************************************************************************************/
:: Run the reset Windows Update components.
:: void components();
:: /*************************************************************************************/
:components
:: ----- Stopping the Windows Update services -----
call :print Stopping the Windows Update services.
net stop bits
call :print Stopping the Windows Update services.
net stop wuauserv
call :print Stopping the Windows Update services.
net stop appidsvc
call :print Stopping the Windows Update services.
net stop cryptsvc
call :print Canceling the Windows Update process.
taskkill /im wuauclt.exe /f
:: ----- Checking the services status -----
call :print Checking the services status.
sc query bits | findstr /I /C:"STOPPED"
if %errorlevel% NEQ 0 (
echo. Failed to stop the BITS service.
echo.
echo.Press any key to continue . . .
pause>nul
goto :eof
)
call :print Checking the services status.
sc query wuauserv | findstr /I /C:"STOPPED"
if %errorlevel% NEQ 0 (
echo. Failed to stop the Windows Update service.
echo.
echo.Press any key to continue . . .
pause>nul
goto :eof
)
call :print Checking the services status.
sc query appidsvc | findstr /I /C:"STOPPED"
if %errorlevel% NEQ 0 (
sc query appidsvc | findstr /I /C:"OpenService FAILED 1060"
if %errorlevel% NEQ 0 (
echo. Failed to stop the Application Identity service.
echo.
echo.Press any key to continue . . .
pause>nul
if %family% NEQ 6 goto :eof
)
)
call :print Checking the services status.
sc query cryptsvc | findstr /I /C:"STOPPED"
if %errorlevel% NEQ 0 (
echo. Failed to stop the Cryptographic Services service.
echo.
echo.Press any key to continue . . .
pause>nul
goto :eof
)
:: ----- Delete the qmgr*.dat files -----
call :print Deleting the qmgr*.dat files.
del /s /q /f "%ALLUSERSPROFILE%\Application Data\Microsoft\Network\Downloader\qmgr*.dat"
del /s /q /f "%ALLUSERSPROFILE%\Microsoft\Network\Downloader\qmgr*.dat"
:: ----- Renaming the softare distribution folders backup copies -----
call :print Deleting the old software distribution backup copies.
cd /d %SYSTEMROOT%
if exist "%SYSTEMROOT%\winsxs\pending.xml.bak" (
del /s /q /f "%SYSTEMROOT%\winsxs\pending.xml.bak"
)
if exist "%SYSTEMROOT%\SoftwareDistribution.bak" (
rmdir /s /q "%SYSTEMROOT%\SoftwareDistribution.bak"
)
if exist "%SYSTEMROOT%\system32\Catroot2.bak" (
rmdir /s /q "%SYSTEMROOT%\system32\Catroot2.bak"
)
if exist "%SYSTEMROOT%\WindowsUpdate.log.bak" (
del /s /q /f "%SYSTEMROOT%\WindowsUpdate.log.bak"
)
call :print Renaming the software distribution folders.
if exist "%SYSTEMROOT%\winsxs\pending.xml" (
takeown /f "%SYSTEMROOT%\winsxs\pending.xml"
attrib -r -s -h /s /d "%SYSTEMROOT%\winsxs\pending.xml"
ren "%SYSTEMROOT%\winsxs\pending.xml" pending.xml.bak
)
if exist "%SYSTEMROOT%\SoftwareDistribution" (
attrib -r -s -h /s /d "%SYSTEMROOT%\SoftwareDistribution"
ren "%SYSTEMROOT%\SoftwareDistribution" SoftwareDistribution.bak
if exist "%SYSTEMROOT%\SoftwareDistribution" (
echo.
echo. Failed to rename the SoftwareDistribution folder.
echo.
echo.Press any key to continue . . .
pause>nul
goto :eof
)
)
if exist "%SYSTEMROOT%\system32\Catroot2" (
attrib -r -s -h /s /d "%SYSTEMROOT%\system32\Catroot2"
ren "%SYSTEMROOT%\system32\Catroot2" Catroot2.bak
)
if exist "%SYSTEMROOT%\WindowsUpdate.log" (
attrib -r -s -h /s /d "%SYSTEMROOT%\WindowsUpdate.log"
ren "%SYSTEMROOT%\WindowsUpdate.log" WindowsUpdate.log.bak
)
:: ----- Reset the BITS service and the Windows Update service to the default security descriptor -----
call :print Reset the BITS service and the Windows Update service to the default security descriptor.
sc.exe sdset wuauserv D:(A;;CCLCSWLOCRRC;;;AU)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCDCLCSWRPWPDTLCRSDRCWDWO;;;SO)(A;;CCLCSWRPWPDTLOCRRC;;;SY)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;WD)
sc.exe sdset bits D:(A;;CCLCSWLOCRRC;;;AU)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCDCLCSWRPWPDTLCRSDRCWDWO;;;SO)(A;;CCLCSWRPWPDTLOCRRC;;;SY)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;WD)
sc.exe sdset cryptsvc D:(A;;CCLCSWLOCRRC;;;AU)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCDCLCSWRPWPDTLCRSDRCWDWO;;;SO)(A;;CCLCSWRPWPDTLOCRRC;;;SY)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;WD)
sc.exe sdset trustedinstaller D:(A;;CCLCSWLOCRRC;;;AU)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)(A;;CCDCLCSWRPWPDTLCRSDRCWDWO;;;SO)(A;;CCLCSWRPWPDTLOCRRC;;;SY)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;WD)
:: ----- Reregister the BITS files and the Windows Update files -----
call :print Reregister the BITS files and the Windows Update files.
cd /d %SYSTEMROOT%\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 -----
call :print Resetting Winsock.
netsh winsock reset
:: ----- Resetting WinHTTP Proxy -----
call :print Resetting WinHTTP Proxy.
if %family% EQU 5 (
proxycfg.exe -d
) else (
netsh winhttp reset proxy
)
:: ----- Set the startup type as automatic -----
call :print Resetting the services as automatics.
sc.exe config wuauserv start= auto
sc.exe config bits start= delayed-auto
sc.exe config cryptsvc start= auto
sc.exe config TrustedInstaller start= demand
sc.exe config DcomLaunch start= auto
:: ----- Starting the Windows Update services -----
call :print Starting the Windows Update services.
net start bits
call :print Starting the Windows Update services.
net start wuauserv
call :print Starting the Windows Update services.
net start appidsvc
call :print Starting the Windows Update services.
net start cryptsvc
call :print Starting the Windows Update services.
net start DcomLaunch
:: ----- End process -----
call :print The operation completed successfully.
echo.Press any key to continue . . .
pause>nul
goto :eof
:: /*************************************************************************************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment