China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-06 10:12
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Please provide more details such as how many minutes to set for the automatic shutdown, etc. If you want to set it to shut down after 30 minutes, the following is a simple batch code: ```batch @echo off shutdown -s -t 1800 ``` Here, `-s` means to start the shutdown operation, and `-t` followed by 1800 means 1800 seconds, which is 30 minutes. If you want to set a different time, you just need to change the number after `-t`. For example, if you want to shut down after 60 minutes, change 1800 to 3600. View 1,959 Replies 9
Original Poster Posted 2007-06-12 20:28 ·  中国 广东 深圳 龙岗区 电信
新手上路
Credits 15
Posts 7
Joined 2006-06-23 13:36
20-year member
UID 57456
Status Offline
I am too rubbish. Please find a batch script for automatic shutdown at a scheduled time:
Requirements:
1. When the computer starts, automatically detect whether it is morning or afternoon. If it is morning, set automatic shutdown at 12 o'clock. If it is afternoon, set automatic shutdown at 17 o'clock.
2. If the computer is started before 8 o'clock in the morning, between 12 o'clock and 13 o'clock, or after 17 o'clock in the evening, automatically shut down. Or cannot start?
Please help me, thank you in advance, dear experts!
Floor 2 Posted 2007-06-12 23:59 ·  中国 吉林 通化 电信
新手上路
Credits 4
Posts 2
Joined 2007-06-06 22:49
19-year member
UID 90505
Gender Male
Status Offline
Just use AT commands. You make it sound so complicated.
Floor 3 Posted 2007-06-13 00:10 ·  中国 江苏 南京 电信
银牌会员
★★★
Credits 1,513
Posts 554
Joined 2005-12-30 00:50
20-year member
UID 48180
Gender Male
Status Offline
Floor 4 Posted 2007-06-13 12:55 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
The code was posted incorrectly, sweat, modify it.

@echo off
rem Automatically detect in the morning or afternoon at boot, if it's morning, set to auto - shutdown at 12 o'clock. If it's afternoon, set to auto - shutdown at 17 o'clock.
rem Before 8 o'clock in the morning, from 12 o'clock to 13 o'clock, and after 17 o'clock in the evening, auto - shutdown when booting.. Or can't boot?
set t=%time:~0,2%
if %t% lss 8 (
shutdown -s -t 0
) else if %t% geq 8 (
if %t% lss 12 (
at 12:00 shutdown -s -t 0
) else if %t% equ 12 (
shutdown -s -t 0
) else if %t% geq 13 (
if %t% lss 17 (
at 17:00 shutdown -s -t 0
) else (
shutdown -s -t 0
)
)
)


[ Last edited by HAT on 2007-6-13 at 09:13 PM ]
Floor 5 Posted 2007-06-13 19:05 ·  中国 广东 深圳 南山区 电信
新手上路
Credits 15
Posts 7
Joined 2006-06-23 13:36
20-year member
UID 57456
Status Offline
Thank you very much for the replies from the 3rd and 4th floors. I've learned something.
Floor 6 Posted 2007-06-13 19:21 ·  中国 广东 深圳 南山区 电信
新手上路
Credits 15
Posts 7
Joined 2006-06-23 13:36
20-year member
UID 57456
Status Offline
The `%time:~0,2%` is a substring extraction operation in batch scripting. In batch, for a variable that holds a time value, like `%time%`, the `~` is used for substring extraction. The syntax `%variable:~start,length%` means to extract a substring starting at position `start` with a length of `length`. Here, `%time:~0,2%` is extracting the first 2 characters from the `%time%` variable which represents the hour part of the time. So `set t=%time:~0,2%` is setting the variable `t` to the hour part of the current time.
Floor 7 Posted 2007-06-13 21:06 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
The code on the 4th floor has been corrected.

[ Last edited by HAT on 2007-6-13 at 09:14 PM ]
Floor 8 Posted 2007-06-13 21:08 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
```
//The part after : %time:~,0,2% I don't understand. Can you explain the parameters?

set t=%time:~0,2%
This means taking the first two digits of the current system time (that is, the hour value)


C:\>echo %time%
21:02:30.26

C:\>echo %time:~0,2%
21


[ Last edited by HAT on 2007-6-13 at 09:14 PM ]
```
Floor 9 Posted 2007-11-01 16:44 ·  中国 福建 福州 电信
初级用户
Credits 30
Posts 15
Joined 2007-05-30 23:51
19-year member
UID 89817
Gender Male
Status Offline
It doesn't work when the system service isn't started
Floor 10 Posted 2007-11-01 20:21 ·  中国 广东 深圳 电信
初级用户
★★
Credits 167
Posts 95
Joined 2007-05-06 09:19
19-year member
UID 87628
Gender Male
Status Offline
Forum Jump: