How to program a time to automatically shut down the computer with a batch file

1

I'm following a tutorial from the Super User site of the Stack Exchange site network, with the idea of programming the my computer to auto-shut down by passing X time, after running or double-clicking a .bat file, instead of using a random program to do this.

As explained in the answer, we first have to create a Batch file (% with%) and inside it add the code below, just after .bat :

shutdown -s -t 1800

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

shutdown -a

Then I created a Batch file and inside it I 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?

    
asked by anonymous 01.11.2015 / 23:38

1 answer

1

Missing line break

@ECHO OFF
shutdown -s -t 1800

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

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

To "debug" the output of the run you can use pause like this:

@ECHO OFF
shutdown -s -t 1800
pause

In this way .bat will not close itself.

    
02.11.2015 / 00:07