Windows Update Multiple Fix Script

I made a simple batch file to help fix Windows Update errors on our Windows Servers at work (both 2003 and 2008 / R2). It is based on some advice for various Windows Update errors that were on the internal knowledge base, which was no doubt gathered from information online somewhere. It performs a series of steps, saving a great deal of time over having to perform them manually.

Word of warning: The script will attempt to copy pending.xml before deleting it. If it cannot copy it it will delete it. Personally I have never been able to copy the file; most likely because I have not rebooted the server after taking ownership and granting myself full permissions to the file. I should add however that in all my use of this script I have not suffered any problems when deleting the file. Windows Update will recreate it the next time you/the computer downloads required updates.

:: Windows Update Multiple Fix Script
:: v1.00
@echo off
cd "C:\Windows\WinSxS"
echo Taking ownership of pending.xml
takeown /f C:\Windows\WinSxS\pending.xml
echo;
echo;
echo Granting you permissions on pending.xml
cacls C:\Windows\WinSxS\pending.xml /G %Username%:F
echo;
echo;
echo Attempting to copy pending.xml to user's home directory
copy "C:\Windows\WinSxS\pending.xml" "%HOMEPATH%\pending.xml"
echo;
echo;
echo Deleting pending.xml
del "C:\Windows\WinSxS\pending.xml"
echo;
echo;
echo Exporting HKEY_LOCAL_MACHINE\COMPONENTS to C:\HKLM_backup.reg
REG EXPORT HKLM\Components C:\HKLM_backup.reg
echo;
echo;
echo Removing noted problematic registry keys
REG DELETE HKLM\Components /v AdvancedInstallersNeedResolving
REG DELETE HKLM\Components /v PendingXmlIdentifier
REG DELETE HKLM\Components /v NextQueueEntryIndex
echo;
echo;
echo Restarting Windows Update related services...
net stop "Background Intelligent Transfer Service"
net start "Background Intelligent Transfer Service"
net stop "Cryptographic Services"
net start "Cryptographic Services"
net stop "Windows Update"
net start "Windows Update"
echo;
echo;
echo Please try running Windows Update / patching again.
echo;
echo;
PAUSE

Copy the code and save it as a batch file, running as administrator of course :)

2 thoughts on “Windows Update Multiple Fix Script

  1. This is a great script. The procedures are captured in the script which is awesome. The reason that you are not able to copy the file because the script is giving you access to the file by taking ownership and then granting permission on the resource. The problem is you do not have rights to actually create an object inside that folder, so you can either copy it to another location or take ownership of the folder and add your account rights to modify whatever, not recommended administrators have read only access here for a reason, but that would provide the ability to create a new object in the folder.

    Again great article.

    1. Hi Rob, thanks for the feedback and your explanation makes sense of course! I’ve updated the code to copy it to the user’s home directory instead :)

Leave a Reply to Robin Cancel reply