Cancel a pending reboot scheduled by Windows Update
Detect and delete the scheduled reboot task created by Windows Update, using a batch script that only acts with the /apply switch.
Windows Update can create the scheduled task \Microsoft\Windows\UpdateOrchestrator\Reboot, which triggers an automatic restart when a restart is pending. The batch script below reports whether this task exists. It deletes the task only when it is run with the /apply switch, and it does so as SYSTEM through PsExec.
Script
@echo off
if not "%~1" == "/apply" (
echo.
echo Usage : Ce script permet de supprimer la tâche planifiée créée automatiquement par les Windows Updates
echo.
echo %0 /apply
echo.
schtasks.exe /query /tn "\Microsoft\Windows\UpdateOrchestrator\Reboot" 2>1>NUL
if %ERRORLEVEL% == 0 (
schtasks.exe /query /tn "\Microsoft\Windows\UpdateOrchestrator\Reboot" | findstr /i "Disabled" 2>1>NUL || (
echo.
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo Attention :
echo La tâche planifiée de redémarrage a été détectée
echo Veuillez exécuter ce même script avec le paramètre /apply
echo !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo.
)
)
goto :EOF
)
schtasks.exe /query /tn "\Microsoft\Windows\UpdateOrchestrator\Reboot" 2>NUL >NUL && (
psexec /acceptEula -s schtasks.exe /Delete /F /TN "\Microsoft\Windows\UpdateOrchestrator\Reboot"
) || (
echo.
echo Il n'y a pas de tâche planifiée de reboot automatique.
echo.
)
Usage
- Without a parameter, the script changes nothing. It only reports whether the restart task is present and enabled.
- With
/apply, it deletes the restart task.
rem Check only
<script>.bat
rem Delete the task
<script>.bat /apply
PsExec (Sysinternals) must be available in the PATH or in the current folder. Run the script from an administrator prompt.
Notes
- The messages printed by the script are in French and are kept as they are in the source. Accented characters garbled by the source encoding were restored.
- The query lines
schtasks ... 2>1>NULredirect the error output to a file named1in the current folder. The intended redirection is2>NUL. The code is kept as in the source; fix this redirection if the file1is a problem.