1

I want to make a batch file that takes a user input in minutes, and will shutdown the computer after the time is up.

I know how to shutdown the computer after a set amount of time is up, I've just been having trouble setting that time to the user input.

7 Answers 7

5

I think this will do what you want.

@echo off
set /p mins=Enter number of minutes to wait until shutdown:
set /a mins=%mins%*60

shutdown /s /t:%mins%

According to http://ss64.com/nt/shutdown.html the most you can wait is 10 minutes, so if you need to wait longer you would need to add some sort of artificial timer, most likely using something like TIMEOUT if your system supports it (mine doesn't) or ping.

@echo off
set /p mins=Enter number of minutes to wait until shutdown:

for /L %%a in (0,1,%mins%) do (
    PING -n 60 127.0.0.1>nul
)
shutdown /s
2
  • Considering the first one does not even contain a loop I don't know what to tell you. It sounds like you have some system specific issue. I tested both of them on my own system and both worked as expected. set /p simply prompts for input so if you want you can use a normal set and manually edit the batch when you want to set the time duration. "set mins=30" or something to that effect.
    – Maynza
    Jun 27, 2011 at 12:48
  • slight confusing .
    – user4023394
    Apr 20, 2017 at 17:37
2

Check out this thread.

https://superuser.com/questions/215531/windows-7-shut-down-pc-after-specified-amount-of-time

Put this code in it after the @echo off line:

shutdown -s -t 1800

2
  • There's nothing on this page about user input, that app looks ok, but I was really just looking for a super basic batch file, not any software.
    – Owen
    Jun 24, 2011 at 9:07
  • The precise link Trevor means is here: superuser.com/a/215566/429839 You just need to create a ".bat" file with "@echo off" as the first line and "shutdown -s -t 1800" for the second line. Save the bat file, double click and off you go.
    – Dib
    Nov 14, 2016 at 16:41
2
@echo off
title Shutdown Input

set /p mins=Enter number of minutes to wait until shutdown:
set /a mins=%mins%*60

shutdown.exe -s -t %mins%
1
  1. Create a file with bat as extension (such as delayed.bat).
    You can use the Editor under Accessoires for that.
  2. Write the following lines into the file and save it (The file has to end with .bat) :
@echo off
set /p time=minutes:
set /a time=%time%*60
shutdown /a
shutdown /s /f /t %time%
  • set /p lets the user input something
  • set /a interprets expressions (calculations)
  • /a aborts earlier shutdown (counter)
  • /s stands for shutdown
  • /f stands for force programs to close (optional).
  • /t stands for the time in seconds. (for example: 60s * 10 = 10 min)

    1. Doubleclick the file and enter after how many minutes you computer shuts down.
    2. To abort shutdown: enter a big number (such as 10000000).
0

Create a batch file, and put this code in it after the @echo off line:

shutdown -s -t 1800

The computer will shutdown 30 minutes (1800 seconds) after running the batch file.

To cancel a shutdown initiated by that batch file, you can go to Start → Run and type:

shutdown -a

Or put that in its own separate batch file, then run it to cancel a shutdown.

Referred From Here

0

Put this in a batch file and run.

@echo off
@setlocal
color 1E
echo  ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ
echo  Ý                                          ÚÄÄÄ¿Þ
echo  Ý       SHUTDOWN COMPUTER WITH TIMER       ³ û ³Þ
echo  Ý                                          ÀÄÄÄÙÞ
echo. ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß
echo.
echo.
echo ----------------------------------------
Set /P _abort=abort shutdown? (y, *):
echo ----------------------------------------
    If /i "%_abort%"=="y" shutdown /a
    If /i "%_abort%"=="y" goto step1
Set /P _timer=shutdown computer after minutes: 
    echo ------------------------
    set /a _result= _timer * 60
    shutdown /s /t %_result%
:step1
    echo Job Done!
    pause
0

If you're on Windows 10, use this simple script:

shutdown -s -t 100

Note: Set the "100" to whatever you want etc. 40

1
  • Other answers already mentionned that solution.
    – XouDo
    Mar 24, 2022 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.