LLI Wiki — My Digital Knowledge Base

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

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

Mastodon LLIMastodon SocialFosstodon