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-07-15 00:20
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] Post an automatic timing bat Please note that if the content involves specific code or more detailed context, please provide more information for a more accurate translation. The above is a basic translation based on the current content. View 4,243 Replies 12
Original Poster Posted 2007-01-13 23:21 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
The last time I came, someone asked how to make a program run after a set time. Today I wrote one and posted it, let's improve it together.




@echo off
:lp
cls
echo.
setlocal enabledelayedexpansion
echo The time now is: %time%
echo.
set si=%time%
echo Press any key to see the result.....
pause >nul

::Select var
set th=!si:~0,2!
rem select hour
set tm=!si:~3,2!
rem select minute
set ts=!si:~6,2!
rem select second
set tms=!si:~9,2!
rem select milisecond

:: add one minute to origin.
::Here, you can set by yourself how long to run a certain program
set /a tm%+=1

::Check output
if "%tm%" equ "60" (set /a th%+=1)
::If it is greater than 60 minutes, add one to the hour

echo.
echo The latest time is: %th%:%tm%:%ts%
echo Attention,the xxx program will run at this time!
pause>nul
goto :lp



[ Last edited by scriptor on 2007-9-14 at 04:07 PM ]
Floor 2 Posted 2007-01-14 03:06 ·  中国 甘肃 甘南藏族自治州 合作市 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
The building owner, this still depends on whether it's a 12-hour system or a 24-hour system, right!
Floor 3 Posted 2007-01-14 03:14 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
Oh, right.
I forgot.

Because mine is in 24-hour format.

Then let me think, whether to change it or not.
Floor 4 Posted 2007-01-14 03:18 ·  中国 北京 中国科学院研究生院
银牌会员
★★★
Credits 1,187
Posts 555
Joined 2006-12-21 07:35
19-year member
UID 74129
Gender Male
Status Offline
Please provide the specific content that needs to be translated. As you haven't provided the actual Chinese text to translate yet, I can't perform the translation. Please share the Chinese text that needs to be converted from Chinese to English.
Floor 5 Posted 2007-01-15 04:16 ·  中国 山东 济南 电信
新手上路
Credits 18
Posts 9
Joined 2007-01-04 04:36
19-year member
UID 75394
Gender Male
From 山东
Status Offline
Floor 6 Posted 2007-01-15 04:16 ·  中国 山东 济南 电信
新手上路
Credits 18
Posts 9
Joined 2007-01-04 04:36
19-year member
UID 75394
Gender Male
From 山东
Status Offline
Floor 7 Posted 2007-04-14 09:49 ·  中国 湖北 武汉 电信
初级用户
Credits 41
Posts 22
Joined 2007-04-12 09:29
19-year member
UID 84862
Gender Male
Status Offline
Floor 8 Posted 2007-04-14 09:49 ·  中国 湖北 武汉 电信
初级用户
Credits 41
Posts 22
Joined 2007-04-12 09:29
19-year member
UID 84862
Gender Male
Status Offline
Floor 9 Posted 2007-12-31 20:20 ·  中国 山东 青岛 联通
初级用户
Credits 77
Posts 45
Joined 2007-08-03 17:25
18-year member
UID 94584
Gender Male
Status Offline
Still not working...
因为喜欢,所以无悔!
Floor 10 Posted 2007-12-31 21:04 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Can the use of scheduled tasks (at or schtasks) not meet the requirements?
Floor 11 Posted 2007-12-31 22:54 ·  中国 广东 广州 天河区 电信
金牌会员
★★★★
一叶枝头,万树皆春
Credits 2,564
Posts 1,127
Joined 2006-12-25 22:57
19-year member
UID 74552
Gender Male
Status Offline
Scheduled tasks are a risky program
Floor 12 Posted 2008-04-14 15:12 ·  中国 广东 广州 黄埔区 电信
新手上路
Credits 12
Posts 5
Joined 2007-02-27 23:36
19-year member
UID 80339
Gender Male
Status Offline
if %time:~0,2% LEQ 5 echo It's time to do something
Floor 13 Posted 2008-04-14 19:28 ·  中国 广东 梅州 五华县 电信
初级用户
Credits 79
Posts 34
Joined 2008-04-02 23:20
18-year member
UID 114802
Gender Male
Status Offline
This is a scheduled shutdown bat I made by looking at others' batch processing.

@mode con cols=90 lines=35&color 1f
@echo off
call :cl
goto input
:1
title Scheduled Shutdown! made by: Xiao Ye
cls
echo Current time: %date% , %time%
echo\&echo Please enter the scheduled shutdown time. (Need 24-hour format, such as 17:30 : Please use English punctuation)&echo\&echo\
echo If you want to return to the menu function, press 0 and then enter!
echo.
set tim=
set /p tim=Please enter the shutdown time:
if "\%tim%\"=="\0\" call :cl&goto input
at %tim% /interactive shutdown -s -c "To cancel the shutdown, please select the cancel shutdown function in the function menu!!" >nul
if errorlevel 1 cls&echo * Incorrect input, please enter again! &goto 1
echo.
echo.
echo.
echo.
echo ================Settings successful!!!==============================
echo.
echo ======Remember to save documents or other things that need to be saved before shutdown! ^_^=====
ping -n 2 127.1>nul
call :cl
goto input
:2
shutdown -a
cls
echo.
echo.
echo.
title Shutdown canceled successfully! made by: Xiao Ye
echo.
echo=======================Shutdown canceled successfully!!!==================
echo.
echo.
echo.
ping -n 2 127.1>nul
goto input
:4
cls
title Function Description made by: Xiao Ye
echo.
echo.&echo.&echo.&echo.&echo.&echo.
echo ※※※※※※※※※※※※※※※※Function Description:※※※※※※※※※※※※※※※※※※※※※※
echo.
echo.
echo ◇◇◇◇Scheduled Shutdown: The scheduled shutdown function can only be used within the same day. It can enter multiple shutdown times within the same time period, and the system will automatically start the shutdown times in chronological order (that is, after the first shutdown time is canceled, the second shutdown time will be automatically started, and so on!). After setting the shutdown time, you can view the set shutdown time under "The shutdown time you set is: " in the function menu.
echo.
echo ◇◇◇◇Cancel Shutdown: Canceling the shutdown is only effective when the shutdown countdown window pops up!! Using it before the window pops up will show that the shutdown is canceled successfully, but the scheduled shutdown function is not actually canceled, and the scheduled shutdown function will still be started when the time comes! !
echo.
echo ◇◇◇◇Exit: Exit the program window! !
echo.
echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo.&echo\&echo.&echo.
pause
goto input

:3
cls&exit
:input
cls
title Function Code Number Selection!
cls
call :card
echo\&echo\&echo\
echo Please enter the function code number:
echo.
set sel=
set /p sel=
if "\%sel%\"=="" goto input
call :%sel%
if errorlevel 1 cls&echo\&echo\&echo\&echo\&echo ========= ☆★Incorrect command entered, trying to fool me?!★☆======&call :cl&goto input
:cl
for /l %%i in (1,1,40) do (
echo\
for /l %%a in (1,1,250) do ver>nul
)
goto :eof
:card
title Function Menu! made by: Xiao Ye
echo\&echo\&echo.
echo\&echo\&echo Function Menu:
echo ▲△△△△△△△△△△△△△△△△△△
echo ▲ ▲
echo ▲ 1=Scheduled Shutdown ▲
echo ▲ ▲
echo ▲ 2=Cancel Shutdown ▲
echo ▲ ▲
echo ▲ 3=Exit ▲
echo ▲ ▲
echo ▲ 4=Function Description ▲
echo ▲ ▲
echo △△△△△△△△△△△△△△△△△△▲
echo.
echo.
echo.
echo (Note: The code number on the left of the equal sign is the function code number, please enter the code number on the left!&echo\
echo The cancel shutdown function is only effective when the shutdown countdown window pops up! !)
echo.
echo.
echo.
echo The shutdown time you set is: %tim%

I tried it and the timing works, and canceling the shutdown also works, but as I explained, canceling the shutdown can only be done when the shutdown countdown window pops up. Is there a way to cancel the scheduled shutdown function by selecting the cancel shutdown key before the countdown window pops up after setting the time. Also, how to modify it so that the last statement is displayed in the function menu only after the set time.
Finally, I had such a situation with this bat. I set two shutdown times in the same time period and they were one minute apart. When the first shutdown time came, the shutdown program ran normally, but when it was halfway through the shutdown, a black screen phenomenon occurred. The computer didn't freeze, but couldn't exit the black screen. What's the reason?
Hope all the masters can give advice!!
Also, after setting the shutdown time, even if the computer restarts after shutdown, it will still shut down when the set time comes. Is that right?
Forum Jump: