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-12 00:51
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to automatically shut down in multiple time periods with batch processing? View 3,566 Replies 20
Original Poster Posted 2009-01-28 22:53 ·  中国 浙江 杭州 阿里云
新手上路
Credits 7
Posts 3
Joined 2009-01-26 20:34
17-year member
UID 137453
Gender Male
Status Offline
Automatically shut down during the following three periods:

Morning: 11:45 - 12:45

Afternoon: 17:00 - 19:00

Evening: 21:30 - 6:00 in the morning

Thanks
Floor 2 Posted 2009-01-29 19:07 ·  中国 浙江 杭州 阿里云
新手上路
Credits 7
Posts 3
Joined 2009-01-26 20:34
17-year member
UID 137453
Gender Male
Status Offline
Experts have gone for the New Year
Hehe
Floor 3 Posted 2009-01-30 03:07 ·  中国 北京 联通
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
Originally posted by zlgzszh at 2009-1-28 22:53:
Automatically shut down within the following three time periods:
Morning: 11:45~12:45
Afternoon: 17:00~19:00
Evening: 21:30~6:00 in the morning
Thank you


This is easy to solve, use the task scheduler
First write a.bat for shutting down

For example, set up a task plan for automatic shutdown in the morning, from 11:44 to 12:45, execute the shutdown.bat every minute


Use shutdown to execute the shutdown command
Use schtasks to set up the task plan command

[ Last edited by yishanju on 2009-1-30 at 03:09 ]

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 4 Posted 2009-01-30 03:13 ·  中国 北京 联通
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
Must-read for learning the schtasks command: http://technet.microsoft.com/zh-cn/library/cc772785.aspx

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 5 Posted 2009-02-02 12:30 ·  中国 浙江 杭州 阿里云
中级用户
★★
Credits 310
Posts 97
Joined 2004-05-26 00:00
22-year member
UID 25372
Gender Male
Status Offline
Hehe

How to write this batch processing?
Floor 6 Posted 2009-02-02 12:37 ·  中国 北京 鹏博士长城宽带
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
I really admire this
Shut down batch processing saved as a.bat
shutdown -s -t 5 -f


Manually set the task plan, start at 11:45 to 12:45 run the.bat once per minute
The same operation for other time periods.

[ Last edited by yishanju on 2009-2-2 at 12:51 ]

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 7 Posted 2009-02-02 13:03 ·  中国 北京 鹏博士长城宽带
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
Batch script to set morning automatic task schedule:
If the system is 2003, you can use the following command to set the required task schedule
schtasks /create /sc minute /mo 1 /tn test /tr a.bat /st 11:11:00 /et 12:44:00 /k /ru "system"

The /ET parameter is actually not available for schtasks under XP SP3
If the operating system is XP, then you need to set the task schedule manually

[ Last edited by yishanju on 2009-2-2 at 19:35 ]

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 8 Posted 2009-02-02 19:45 ·  中国 北京 鹏博士长城宽带
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
I got a schtasks from a Windows 2003 SP1 system server.
I can create a task meeting the requirements on XP SP3.
schtasks /create /sc minute /mo 1 /tn test /tr a.bat /st 11:11:00 /et 12:44:00 /k /ru "system"

schtasks.rar download
http://upload.cn-dos.net/img/1286.rar

[ Last edited by yishanju on 2009-2-2 at 19:50 ]
Attachments
schtasks.rar (52.57 KiB, Credits to download 1 pts, Downloads: 16)

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 9 Posted 2009-02-03 13:23 ·  中国 浙江 温州 电信
高级用户
★★★
Credits 916
Posts 377
Joined 2004-03-08 00:00
22-year member
UID 19523
Gender Male
Status Offline
xcopy \\192.168.9.100\da\shutdown.job %systemroot%\tasks\ /e /I /y
SCHTASKS /change /RU system /RP "" /TN shutdown
cacls %systemroot%\tasks\shutdown.job /e /d onlyit
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RemoteComputer\NameSpace\{D6277990-4C6A-11CF-8D87-00AA0060F5BF}" /f
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\RemoteComputer\NameSpace\{2227A280-3AEA-1069-A2DE-08002B30309D}" /f

For XP, if some parameters are not supported, simply create the scheduled task manually and then copy it to %systemroot%\tasks. For Windows Server 2003, it's not in this location. Then specify the running account, reset the access permissions using cacls, and remove the ability to see the scheduled task through Network Neighborhood when sharing Windows. That's all.
Floor 10 Posted 2009-02-07 09:25 ·  中国 浙江 杭州 阿里云
新手上路
Credits 7
Posts 3
Joined 2009-01-26 20:34
17-year member
UID 137453
Gender Male
Status Offline
Thanks
But
It's better to use a batch file
Floor 11 Posted 2009-02-07 15:33 ·  中国 广东 江门 电信
新手上路
Credits 16
Posts 11
Joined 2009-02-04 00:07
17-year member
UID 137970
Gender Male
Status Offline
@echo off
if %time% gtr 11:45:00.00 if %time% lss 12:40:00.00 exit
if %time% gtr 17:00:00.00 if %time% lss 19:00:00.00 exit
if %time% gtr 21:00:00.00 if %time% lss 23:59:00.00 exit
if %time% gtr 00:00:00.00 if %time% lss 06:00:00.00 exit
shutdown -s -t 0 -f

When the system starts, run the BAT

[ Last edited by jmzhwf on 2009-2-7 at 15:34 ]
Floor 12 Posted 2009-02-07 15:39 ·  中国 广东 江门 电信
新手上路
Credits 16
Posts 11
Joined 2009-02-04 00:07
17-year member
UID 137970
Gender Male
Status Offline
Oh~~~~Sorry~I read the question wrong and wrote BAT backwards~~Hehe

@echo off
if %time% gtr 11:45:00.00 if %time% lss 12:40:00.00 shutdown -s -t 0 -f
if %time% gtr 17:00:00.00 if %time% lss 19:00:00.00 shutdown -s -t 0 -f
if %time% gtr 21:00:00.00 if %time% lss 23:59:00.00 shutdown -s -t 0 -f
if %time% gtr 00:00:00.00 if %time% lss 06:00:00.00 shutdown -s -t 0 -f
exit

It should be written like this to be okay

Since there is no test, if it can't run, you can change shutdown -s -t 0 -f to: (shutdown -s -t 0 -f)
Floor 13 Posted 2009-02-07 16:25 ·  中国 北京 联通
银牌会员
★★★★
[b]看你妹啊[/b]
Credits 1,488
Posts 1,357
Joined 2006-05-20 12:00
20-year member
UID 55770
Status Offline
I thought about it. If it's only set to execute the batch file once at startup, imagine I power on or restart at 11:40:00.00. Can it still shut down at the specified time?

[ Last edited by yishanju on 2009-2-7 at 16:26 ]

有问题请发论坛或者自行搜索,再短消息问我的统统是SB
Floor 14 Posted 2009-02-07 18:26 ·  中国 广东 江门 电信
新手上路
Credits 16
Posts 11
Joined 2009-02-04 00:07
17-year member
UID 137970
Gender Male
Status Offline
Just add a line at the beginning of the batch file:

copy %0 "%USERPROFILE%\「Start」Menu\Programs\Startup"

Also, it's difficult for humans to be precise to 11:40:00.00.

If you're still not at ease, you can replace GTR with GEQ and LSS with LEQ.
Floor 15 Posted 2009-02-07 18:30 ·  中国 广东 江门 电信
新手上路
Credits 16
Posts 11
Joined 2009-02-04 00:07
17-year member
UID 137970
Gender Male
Status Offline
As for the automatic shutdown problem~~~

Adding a few more AT commands can solve it

Or adding a loop is also okay

[ Last edited by jmzhwf on 2009-2-7 at 18:33 ]
Forum Jump: