Batch files to shut down the PC

Solved
tungsten -  
 aaaa -
Hello,

so here it is, I've been "programming" in batch for a while and I would like to do a little something special:
I've been trying for some time to make a script that automatically and without asking anything turns off the PC at a set time; I know it's possible to do it through scheduled tasks, but I really want to do it via batch.

Thank you!

9 réponses

thib0787 Posted messages 934 Status Membre 176
 
Hi,

to turn off the PC, it's
shutdown.exe -s

and you can add a timer in seconds before shutdown
shutdown.exe -s -t 60

(1 minute)
38
aaaa
 
aaaa
1
nounours
 
Hello,

try this:

batch 1:

@echo off
:START

for /F "tokens=1,2,3 delims=:, " %%A in ("%TIME%") do (
set Hour= %%A
set Minute= %%B
set Second= %%C
)

cls
set Hours= %Hour%:%Minute%:%Second%
set RebootHour= 15
set RebootMinute= 07
set RebootSecond= 05

echo %Hour%:%Minute%:%Second%

if NOT %Second%==%RebootSecond% GOTO START
if NOT %Minute%==%RebootMinute% GOTO START
if NOT %Hour%==%RebootHour% GOTO START

call batch2.bat

batch2:

shutdown
10
tungsten
 
Thank you,

I found something in the meantime after messing around, but for now it's not working... In fact, I create a variable:

bat1.bat
@echo off
if "%Time%"=="18/00/00" shutdown.exe
if not "%Time%"=="18/00/00" call bat2

bat2.bat

@echo off
if "%Time%"=="18/00/00" shutdown.exe
if not "%Time%"=="18/00/00" call bat1.bat

Actually, I thought these two files would call each other like this: bat1 => bat2 then bat1 stops bat2 => bat1 then bat2 stops

The thing is, it runs for about 5 seconds, then everything stops... I thought there might be an option/command to prevent the stop, but I couldn't find one... Does anyone have an idea?

Anyway, thanks thib0787, that could be useful to me ;)
10
tungsten
 
up
5
nounours
 
I forgot the end of batch2:

shutdown.exe -s -t 60
4
énigmatique
 
I forgot and then you do as usual
shutdown /t 15 /r
4
tungsten
 
OK, thank you very much, this will really help me :)
3
énigmatique
 
salut entre tout simplement cette commande et remplace le 2 par le temps en seconde
bye

choice /t:o,[temps en secondes] > nul
2
Pierre
 
If you want to shut down PCs on a network, use this batch:

@echo off
netview
shutdown -i
2