|
okmhy
新手上路

积分 15
发帖 7
注册 2006-6-23
状态 离线
|
『楼 主』:
求一个定时自动关机的批处理?
使用 LLM 解释/回答一下
本人太垃圾了,求一个定时自动关机的批处理:
要求:
1.开机自动检测是上午还是下午,是上午设定在12点自动关机.下午设定在17点自动关机.
2.在上午8点以前,12点到13点,晚上17点以后开机自动关机..或者不能开机?
请各位大侠指点迷津,小弟先谢谢了!
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!
|
|
2007-6-12 20:28 |
|
|
jamesbond
新手上路

积分 4
发帖 2
注册 2007-6-6
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
用AT命令就行了啊.看你说的够复杂的
Just use AT commands. You make it sound so complicated.
|
|
2007-6-12 23:59 |
|
|
baomaboy
银牌会员
    
积分 1513
发帖 554
注册 2005-12-30
状态 离线
|
|
2007-6-13 00:10 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
代码贴错了,汗水,修改一下。
@echo off
rem 开机自动检测是上午还是下午,是上午设定在12点自动关机.下午设定在17点自动关机.
rem 在上午8点以前,12点到13点,晚上17点以后开机自动关机..或者不能开机?
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 ]
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 ]
|
|
2007-6-13 12:55 |
|
|
okmhy
新手上路

积分 15
发帖 7
注册 2006-6-23
状态 离线
|
『第 5 楼』:
非常感谢~!
使用 LLM 解释/回答一下
非常感谢3楼和4楼的答复.学习了
Thank you very much for the replies from the 3rd and 4th floors. I've learned something.
|
|
2007-6-13 19:05 |
|
|
okmhy
新手上路

积分 15
发帖 7
注册 2006-6-23
状态 离线
|
『第 6 楼』:
有点看不懂
使用 LLM 解释/回答一下
4楼的这句:rem set t=%time:~0,2%有点看不懂
set 是设置T=
后面:%time:~,0,2%这句看不懂.能不能解释一下参数
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.
|
|
2007-6-13 19:21 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
4楼的代码已经改正过来啦
Last edited by HAT on 2007-6-13 at 09:14 PM ]
The code on the 4th floor has been corrected.
Last edited by HAT on 2007-6-13 at 09:14 PM ]
|
|
2007-6-13 21:06 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
//后面:%time:~,0,2%这句看不懂.能不能解释一下参数
set t=%time:~0,2%
这句的意思是取当前系统时间的前两位(也就是小时的值)
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 ]
```
//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 ]
```
|
|
2007-6-13 21:08 |
|
|
aaa2117
初级用户
 
积分 30
发帖 15
注册 2007-5-30
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
没有开系统服务时就不行了
It doesn't work when the system service isn't started
|
|
2007-11-1 16:44 |
|
|
ldr2zjj
初级用户
 
积分 167
发帖 95
注册 2007-5-6
状态 离线
|
|
2007-11-1 20:21 |
|