Detecting a scheduled shutdown Detecting a scheduled shutdown windows windows

Detecting a scheduled shutdown


I have the same problem, I searched all over, but did not find anything useful.

Eventually I just started messing around with different things I could think of. I can think of two workarounds for our problem.

The event viewer can tell you that a shutdown has been scheduled, but not WHEN it was scheduled.

One idea is to query the event viewer for the most recent system shutdown, the most recent scheduled shutdown, and the most recent cancellation of a scheduled shutdown. If the scheduled shutdown is more recent than either the most recent cancellation or shutdown then there is one in progress.The Event IDs are: 1074 for a started scheduled shutdown, 1075 for a canceled scheduled shutdown, under Windows Logs/System12 for system start up13 for system shutdown(all under Windows Logs/System)

I was too lazy to do this in a batch file, I know it is possible though.

So this is what I ended up doing:Rather than schedule a shutdown, just try to abort it. If no shutdown is in progress it will throw an error (Unable to abort the system shutdown because no shutdown was in progress.(1116)). Much better I think than freaking out a user by scheduling a shutdown.

Here is a copy of the code I wrote for a simple auto shutdown script, it toggles between cancelling and starting a scheduled shutdown.

@echo offshutdown /aif errorlevel 1 call:shutdowngoto end:shutdown    set /p choice=Shutdown in how many minutes?     set /a mod=60    set /a mod*=%choice%    shutdown /s /t %mod%:end

EDIT - I am revisiting this answer as I have more info to add.

The Above solution will detect if a shutdown has been scheduled via the shutdown.exe command using the /t argument.

If you need to determine if Windows has schedule a shutdown (as it does automatically after some Windows Updates) then there is a registry entry that is set which you can query. The below is in PowerShell, but you can write a batch file to do the same.

Test-Path 'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending'

Note: this will not return true if a reboot in scheduled using shutdown.exe, it will only return true if Windows says your computer need to be rebooted.


You can use:

Shutdown /a "for aborting the scheduled"

then use shutdown again to create another schedule.


I suppose you could use the Task Scheduler API to enumerate the scheduled tasks and see if any of them invoke shutdown.exe. But I"m not sure that's robust. There are probably multiple ways to schedule a shutdown.