*** If you tried this script out, please remember to rate it *** Also if you are going to give this a negative rating, please post a comment explaining why because perhaps there is a way to handle whatever you don't like. Simply giving something a 1/5 star rating without an explanation is of no help to anyone.

After an in-place-upgrade from Windows Server 2008 Standard Edition w/ SP2 to Windows Server 2008 R2 Standard Edition w/ SP1, the task scheduler on the server kept reporting "The task image is corrupt or has been tampered with." for all of the default Microsoft supplied scheduled tasks.

Expanding on the code created by JimFlyer for repairing Windows 7 scheduled tasks after an in-place-upgrade in the post http://social.technet.microsoft.com/Forums/en-US/w7itproinstall/thread/5e3849da-e186-40c3-acb5-238342c642b8/#fe9204ea-f938-4ad6-b160-90aa7e8ebe6e, I added more logic to perform all of the removal and replacement steps in KB article http://support.microsoft.com/kb/2305420 and replaced the tasks in his script to be those specific to the Windows Server version I was dealing with.


  1. REG.EXE must be installed on the server running this batch file. If it isn't already in the PATH, then update the script to reflect its correct location. It was included with Windows 2008 R2 but can be downloaded from Microsoft for older versions of Windows.
  2. SetACL.EXE must be installed on the server running this batch file. If it isn't already in the PATH, then update the script to reflect its correct location. It is available from http://sourceforge.net/projects/setacl/
  3. The person running the script must be a member of the local Administrators group on the computer, and if UAC is enabled the Windows Command prompt must be "Run as administrator".
  4. Each individual task reporting the error must be manually recorded in the batch file in the format of CALL :LOOP "Microsoft\Windows\AppID\PolicyConverter". NOTE: tasks not reporting the error can be skipped as they are probably fine. To obtain the full path of each problem task, use the following steps:
    1. Open the Task Scheduler and acknowledge all of the pop-up errors.
    2. Navigate to the "Task Scheduler Library" folder and expand it.
    3. Crawl each folder below that point until you get to the end of that folder hierarchy.
    4. When you get another pop-up error, you have hit a folder that contains a scheduled task that is having issues.
    5. Record the exact task name in the pop-up after the word "Task" and before the ":" character. For example in the popup "Task AD RMS Rights Policy Template Management (Manual): The task image is corrupt or has been tampered with.", the task name is "AD RMS Rights Policy Template Management (Manual)".
    6. Record the exact folder path that the pop-up for the task occurred in. Using the example from the step above the folder path would be "Microsoft\Windows\Active Directory Rights Management Services Client\AD RMS Rights Policy Template Management (Manual)".
    7. Join the folder path and the task name into a single line, and add it as a CALL :LOOP in the script. Using the example from above, the entry would be: CALL :LOOP "Microsoft\Windows\Active Directory Rights Management Services Client\AD RMS Rights Policy Template Management (Manual)".

I was unable to tell how to query the registry for the scheduled tasks having the issue, otherwise I would have completely automated the whole process.

Once all of the tasks have been manually recorded correctly, run the script and it will perform the following actions on each task defined as a CALL :LOOP:

  1. Find the GUID of the task.
  2. Find out which one of the three TaskCache registry sub-keys the GUID is stored in. NOTE: It is apparently not possible to surppress the REG.EXE not being able to find a registry key, so on every task you will see two REG QUERY failures - this is OK.
  3. Copy out the original task file to a temporary location on the server. NOTE: If the specified task name (including the full folder path) is off by one character, the script will skip trying to fix that task and move on to the next one.
  4. Remove the original task file.
  5. Remove the 3 related registry keys for the task.
  6. Re-add the task to the system.

This script was written in Windows Command Shell (batch file) because it was originally started as such by JimFlyer, and because taking ownership and setting permissions of registry keys in something like PowerShell is not something I have experience with yet and this needed to be fixed ASAP on the server we in-place-upgraded.

Since this script is blowing away registry entries and files, I STRONGLY suggest you try this on one scheduled task at a time until you are comfortable with it. In other words use at your own risk.


Windows Shell Script
REM Name: TaskRepair.CMD 
REM Author: Daniel Sheehan 
REM Requires: REG.EXE if it is not included with the OS and SetACL.EXE from http://sourceforge.net/projects/setacl/ 
REM Summary: Removes and repairs manually specified scheduled task entries so they will not generate "The task image is corrupt or has been tampered with" errors. 
REM Summary: This scrpt was inspired by JimFlyer from the forum post http://social.technet.microsoft.com/Forums/en-US/w7itproinstall/thread/5e3849da-e186-40c3-acb5-238342c642b8/#fe9204ea-f938-4ad6-b160-90aa7e8ebe6e 
REM Summary: The steps in this script following the instructions in the KB article - http://support.microsoft.com/kb/2305420 
REM List all the scheduled tasks that have the error reflecting their folder membership under the "Task Scheduler Library"CALL :LOOP "Microsoft\Windows\Active Directory Rights Management Services Client\AD RMS Rights Policy Template Management (Automated)" 
CALL :LOOP "Microsoft\Windows\Active Directory Rights Management Services Client\AD RMS Rights Policy Template Management (Manual)" 
CALL :LOOP "Microsoft\Windows\AppID\PolicyConverter" 
CALL :LOOP "Microsoft\Windows\AppID\VerifiedPublisherCertStoreCheck" 
CALL :LOOP "Microsoft\Windows\Application Experience\AitAgent" 
CALL :LOOP "Microsoft\Windows\Application Experience\ProgramDataUpdater" 
CALL :LOOP "Microsoft\Windows\Autochk\Proxy" 
CALL :LOOP "Microsoft\Windows\CertificateServicesClient\SystemTask" 
CALL :LOOP "Microsoft\Windows\CertificateServicesClient\UserTask" 
CALL :LOOP "Microsoft\Windows\CertificateServicesClient\UserTask-Roam" 
CALL :LOOP "Microsoft\Windows\Customer Experience Improvement Program\Consolidator" 
CALL :LOOP "Microsoft\Windows\Customer Experience Improvement Program\KernelCeipTask" 
CALL :LOOP "Microsoft\Windows\Customer Experience Improvement Program\UsbCeip" 
CALL :LOOP "Microsoft\Windows\Customer Experience Improvement Program\Server\ServerRoleUsageCollector" 
CALL :LOOP "Microsoft\Windows\Customer Experience Improvement Program\Server\ServerRoleCollector" 
CALL :LOOP "Microsoft\Windows\Customer Experience Improvement Program\Server\ServerCeipAssistant" 
CALL :LOOP "Microsoft\Windows\Defrag\ScheduledDefrag" 
CALL :LOOP "Microsoft\Windows\MemoryDiagnostic\CorruptionDetector" 
CALL :LOOP "Microsoft\Windows\MemoryDiagnostic\DecompressionFailureDetector" 
CALL :LOOP "Microsoft\Windows\MUI\LPRemove" 
CALL :LOOP "Microsoft\Windows\Multimedia\SystemSoundsService" 
CALL :LOOP "Microsoft\Windows\NetTrace\GatherNetworkInfo" 
CALL :LOOP "Microsoft\Windows\Power Efficiency Diagnostics\AnalyzeSystem" 
CALL :LOOP "Microsoft\Windows\RAC\RacTask" 
CALL :LOOP "Microsoft\Windows\Ras\MobilityManager" 
CALL :LOOP "Microsoft\Windows\Registry\RegIdleBackup" 
CALL :LOOP "Microsoft\Windows\Server Manager\ServerManager" 
CALL :LOOP "Microsoft\Windows\SoftwareProtectionPlatform\SvcRestartTask" 
CALL :LOOP "Microsoft\Windows\Task Manager\Interactive" 
CALL :LOOP "Microsoft\Windows\Tcpip\IpAddressConflict1" 
CALL :LOOP "Microsoft\Windows\Tcpip\IpAddressConflict2" 
CALL :LOOP "Microsoft\Windows\termsrv\licensing\TlsWarning" 
CALL :LOOP "Microsoft\Windows\TextServicesFramework\MsCtfMonitor" 
CALL :LOOP "Microsoft\Windows\Time Synchronization\SynchronizeTime" 
CALL :LOOP "Microsoft\Windows\UPnP\UPnPHostConfig" 
CALL :LOOP "Microsoft\Windows\User Profile Service\HiveUploadTask" 
CALL :LOOP "Microsoft\Windows\WDI\ResolutionHost" 
CALL :LOOP "Microsoft\Windows\Windows Error Reporting\QueueReporting" 
CALL :LOOP "Microsoft\Windows\Windows Filtering Platform\BfeOnServiceStartTypeChange" 
CALL :LOOP "Microsoft\Windows\WindowsColorSystem\Calibration Loader" 
ECHOECHO All tasks have been repaired, and a reboot is now recommended. 
ECHO Exiting the Task Repair script. 
REM Set the TASKNAME variable to the task name in quotes including the full folder pathSET TASKNAME=%1 
ECHO Grabbing the registry information for scheduled task %TASKNAME%. 
REM Per the KB Step 1 sub-step 3 - Grab the GUID of the task from the registry. 
FOR /F "tokens=2 delims={}" %%a IN ('REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\%TASKNAME:~1,-1%" /v Id'DO SET REGID={%%a} 
REM Per the KB Step 1 sub-step 4 - determine which TaskCache key the GUID is listed in and record it to the REGCLEANUP variable. 
REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Plain\%REGID%" >Nul 
IF %ERRORLEVEL%==0 SET REGCLEANUP="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Plain\%REGID%" 
REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Logon\%REGID%" >Nul 
IF %ERRORLEVEL%==0 SET REGCLEANUP="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Logon\%REGID%" 
REG QUERY "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Boot\%REGID%" >Nul 
IF %ERRORLEVEL%==0 SET REGCLEANUP="HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Boot\%REGID%" 
ECHO Temporarily removing the task from the system. 
REM Per the KB Step 2 - copy the task file to a temporary folder in the system designated TEMP folder. 
ECHO F | XCOPY "%SYSTEMDRIVE%\Windows\System32\Tasks\%TASKNAME:~1,-1%" "%TEMP%\Tasks\%TASKNAME:~1,-1%">Nul 
IF ERRORLEVEL 1 ECHO There was a problem copying the scheduled task file for %TASKNAME:~1,-1%, skipping this task.&ECHO.&GOTO :EOF 
REM Assuming there were no issues copying the task file, per the KB Step 3 sub-step 1 remove it from the Tasks folder on the SYSTEMDRIVE. 
DEL "%SYSTEMDRIVE%\Windows\System32\Tasks\%TASKNAME:~1,-1%" >Nul 
REM Grant the local Administrators group ownership of the registry keys about to be deleted, otherwise the permissions can't be modified. 
SetACL -on "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\%TASKNAME:~1,-1%" -ot reg -actn setowner -ownr "n:Administrators;s:N" >Nul 
SetACL -on "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\%REGID%" -ot reg -actn setowner -ownr "n:Administrators;s:N" >Nul 
SetACL -on %REGCLEANUP% -ot reg -actn setowner -ownr "n:Administrators;s:N" >Nul 
REM Grant the local Administrators group full control on the registry keys about to be deleted. 
SetACL -on "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\%TASKNAME:~1,-1%" -ot reg -actn ace -ace "n:Administrators;p:full" >Nul 
SetACL -on "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\%REGID%" -ot reg -actn ace -ace "n:Administrators;p:full" >Nul 
SetACL -on %REGCLEANUP% -ot reg -actn ace -ace "n:Administrators;p:full" >Nul 
REM Per the KB Step 3 sub-steps 2-4 - remove the three registry keys associated with the task. 
REG DELETE "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\%TASKNAME:~1,-1%" /f >Nul 
REG DELETE "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks\%REGID%" /f >Nul 
REM Per the KB Step 4 - recreate the sceduled task from the temporary file in the TEMP folder. 
Schtasks.exe /CREATE /TN %TASKNAME% /XML "%TEMP%\Tasks\%TASKNAME:~1,-1%" 
While this has only been tested on a Windows 2008 R2 server, it should work on other versions of Windows. I hope this helps those of you who perform an in-place upgrade.