How to set a time to automatically shut down your computer with a Batch file

Asked

Viewed 839 times

1

I am following a tutorial from the site Super User of the network of Stack Exchange sites, with the idea of programming my computer to shut down by passing X time, after we have run or double click on a file .bat, instead of using a random program to do this.

As explained in the answer, first we have to create a batch file (.bat) and inside it add the code below, just after the @echo off:

shutdown -s -t 1800

which will shut down the computer after 30 minutes (1800 seconds) after running the file.
To cancel this action, just exchange the above code for the below code (or create a new file) and run it with the following code:

shutdown -a

So I created a Batch file and within it added the following line of code:

@ECHO OFF shutdown -s -t 1800

But when I run the file, nothing happens. Am I doing something wrong?

  • What do you mean the question is out of the scope? The question is about programming and even there are own tags related to the question and other questions asked on the same topic (.bat/batch) as an example: 1, 2, 3 and so on onward. Maybe it can be a less talked about topic that people aren’t used to seeing, but I don’t think it’s outside the scope.

  • 1

    I understood your point of view, but note that in the case of the questions you quoted, (in my view) only this within the scope, the others not. It doesn’t mean that because there are open questions that are within the scope, they usually pass "beaten" :) - I was the one who voted to close, but even so I tried to provide you with an answer, however looking well, your question really seems within the scope, because it speaks of . bat and not used commands, vote to close withdrawn and +1

1 answer

1


Missed a line break

@ECHO OFF
shutdown -s -t 1800

Note that everything that comes after a specific command (the ECHO for example) is not executed is considered its parameter, so the line break is required.

The only ways to execute 2 or more commands on the same line is to use & or | for example (I don’t know much about batch).

To "debug" the result of the execution you can use the pause thus:

@ECHO OFF
shutdown -s -t 1800
pause

This way . bat will not close alone.

  • 1

    Thank you William, now it worked right! :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.