0

Following this answer I'm using a batch file to copy some files from my C: drive to another drive on shutdown. Due to the amount of the files this may take up to a few minutes. This is not a problem if I really shutdown my machine. But sometimes I need to just reboot and the batch file is then executed as well. Is there any possibility to find out in my batch file whether I'm rebooting or shutting down?

1 Answers1

2

How can I distinguish a shutdown from a reboot?

You can use the following script:

@echo off
for /f "tokens=3 delims= " %%i in ('wevtutil qe system /c:1 /rd:true /f:text /q:"*[System/EventID=1074]" ^| findstr /c:"Shutdown Type"') do (
    set shutdownType=%%i
)
if ["%shutdownType%"]==["shutdown"] (
    :: your shutdown code here
) else (
    :: if not a shutdown, do something else
)

enter image description here

Source: How to detect a shutdown or reboot?

As per comment from harrymc please also read and take note of this answer.

DavidPostill
  • 156,873