Home > Blockchain >  Simple Shutdown script
Simple Shutdown script

Time:10-18

So I'm simply trying to write a short batch that lets me input a time before the computer shuts down.

@echo on
title Auto Shutdown

echo Choose hours, minutes or seconds (h/m/s)
set /p unit=

IF /i "%unit%"=="h" goto unitH
IF /i "%unit%"=="m" goto unitM
IF /i "%unit%"=="s" goto unitS
goto stupid

:unitH
echo Enter number of hours to wait until shutdown:
set /p time=
set /a finaltime=%time%*60*60
goto sd

:unitM
echo Enter number of minutes to wait until shutdown:
set /p time=
set /a finaltime=%time%*60
goto sd

:unitS
echo Enter number of seconds to wait until shutdown:
set /p time=
set /a finaltime=%time%*1
goto sd

:sd
Echo Final step!
pause

shutdown -s -t %finaltime% goto done

:stupid
echo You're stupid...
pause

:done
echo Job Done!
pause

Now I've added some extra things, like the :done and :stupid, but those were generally just to make sure that it worked. It all seems to work, except for when hitting the "shutdown" part. Then it simply returns to the top and starts over, doesn't even goto "done". I've seen some other scripts for this online but none of them seem to work... Is a timer the solution instead of adding the time to the shutdown itself?

CodePudding user response:

Don't name your files things that could confuse the system... Changed the file name from Shutdown.bat to AutoDeath.bat, and suddenly it works. Thanks Stephan.

  • Related