Save this as a file with a .bat extension:
Code: Select all
set i=0
:BEGINCHECK
rem Check for powercfg requests to keep the PC awake. If one is found,
rem goto WAITSOMETIME to wait 60 seconds before trying again. If you
rem want, you can add more checks for other processes by simply adding
rem another pair of powercfg/if statements like what is shown below.
powercfg -requests | find "ehrec.exe"
if %ERRORLEVEL% == 0 goto :WAITSOMETIME
powercfg -requests | find "ehshell.exe"
if %ERRORLEVEL% == 0 goto :WAITSOMETIME
rem Finally, let's check to see if a Media Center update is in progress.
rem we don't want to reboot until that's finished.
tasklist /FI "IMAGENAME eq mcupdate.exe" | find "mcupdate.exe"
if %ERRORLEVEL% == 0 goto :WAITSOMETIME
rem If we got here, then none of the processes above are running and
rem it is safe to reboot the PC.
shutdown /r /t 0
goto :FINISH
:WAITSOMETIME
rem Increment the counter "i". If it is greater than the first argument,
rem then give up. Otherwise, use the choice command to force the script
rem to wait 60 seconds before checking again.
set /A i=%i% + 1
if %i% GTR %1 goto :FINISH
choice /C YN /T 60 /D Y
goto :BEGINCHECK
:FINISH