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-02 04:42
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Please provide the specific functional requirements of the batch program so that I can help you translate and generate the corresponding batch program description or code. View 1,503 Replies 14
Original Poster Posted 2006-09-22 04:46 ·  中国 上海 上海乾万网络(QianWan_Network)有限公司(电信出口)
初级用户
Credits 44
Posts 17
Joined 2006-09-05 13:00
19-year member
UID 61900
Status Offline
Operating system 2000, execute a batch command once, prompt the user to enter the daily shutdown time in DOS, then save and exit. When that time comes, call another batch to automatically shut down at that time, preferably the quick shutdown kind. Can this be done?
Floor 2 Posted 2006-09-22 07:32 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
set /p time
at time
shutdown /s /f
Floor 3 Posted 2006-09-22 09:26 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
Note: There is no shutdown command under Win2000. To use the following batch script, the poster please first copy shutdown.exe from the %windir%\sysytem32 directory under WinXP to the corresponding directory under Win2000.

@echo off
:index
cls
echo ====================================================
echo.
echo Please enter the daily shutdown time below. Format: (08:22)
echo.
echo To cancel the scheduled shutdown, just press Enter
echo.
echo ====================================================
echo.
echo.
set time_=
set /p time_=Please enter the shutdown time and press Enter:
if "%time_%"=="" goto cancel
:: Judge incorrect input___________________________________________________
for /l %%i in (100,1,123) do (
for /l %%a in (100,1,159) do (
if "1%time_:~0,2%"=="%%i" (
if "1%time_:~3,2%"=="%%a" (
goto start
)
)
)
)
cls
echo Sorry, your input is incorrect, please re-enter!
echo.
pause
goto index
:: Generate scheduled shutdown script_______________________________________________
:start
if not exist "%ProgramFiles%\timeshut" md "%ProgramFiles%\timeshut"
(echo @echo off
echo shutdown -s -f -t 30
)>"%ProgramFiles%\timeshut\shut.bat"
(echo @echo off
echo at /delete /yes
echo at %time_% "%ProgramFiles%\timeshut\shut.bat"
)>"%ProgramFiles%\timeshut\time.bat"
(echo Windows Registry Editor Version 5.00
echo.
echo
echo "timeshut"="%systemdrive%\\Program Files\\timeshut\\time.bat"
echo.
echo
echo "Start"=dword:00000002
)>run.reg
regedit /s run.reg
del run.reg
call "%ProgramFiles%\timeshut\time.bat"
cls
echo =======================
echo Daily scheduled shutdown has been started.
echo =======================
echo.
echo.
pause
exit
:: Cancel scheduled shutdown__________________________________________________
:cancel
if exist "%ProgramFiles%\timeshut" rd /s /q "%ProgramFiles%\timeshut"
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /f /v timeshut
cls
echo ==================
echo Scheduled shutdown has been canceled.
echo ==================
echo.
echo.
pause


Coded in a hurry, tested under XP, still very imperfect. Please point out the不足之处!

[ Last edited by pengfei on 2006-9-23 at 04:37 ]
业精于勤而荒于嬉,形成于思而毁于随。
Floor 4 Posted 2006-09-22 11:13 ·  中国 上海 黄浦区 电信
初级用户
Credits 44
Posts 17
Joined 2006-09-05 13:00
19-year member
UID 61900
Status Offline
Thank you. There is a problem that the automatic shutdown can only be achieved after restarting the machine. If you adjust the computer time a little earlier than the scheduled shutdown time while it's on, it won't shut down. Also, it seems that when it automatically shuts down, it goes black after 5 seconds of reading, and the mouse can move but it just can't shut down. Is there any way to fix this?

[ Last edited by lulala on 2006-9-22 at 11:42 ]
Floor 5 Posted 2006-09-22 20:24 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
Hello!

1. You must restart the machine to achieve a shutdown because only a restart can activate the scheduled task. The code has been modified so that the script for scheduled shutdown can be activated without restarting, but if your scheduled task is not enabled, you still need to restart the computer.

2. Adjusting the time a bit earlier than the scheduled shutdown time prevents it from shutting down. I think this might be an issue with the scheduled task. Or maybe you were testing near the boundary of two days.

3. It goes black after reading for 5 seconds and then a forced shutdown is executed after 5 seconds. There might be an issue with the system. Here, it's changed to 30 seconds for automatic shutdown to allow applications to end processes first, which is safer.

[ Last edited by pengfei on 2006-9-23 at 02:45 ]
业精于勤而荒于嬉,形成于思而毁于随。
Floor 6 Posted 2006-09-22 21:34 ·  中国 上海 上海乾万网络(QianWan_Network)有限公司(电信出口)
初级用户
Credits 44
Posts 17
Joined 2006-09-05 13:00
19-year member
UID 61900
Status Offline
I should thank you instead. The problem has been solved, and the program is very good. Thank you so much!! It's just that when it's under 2000, the system prompts that you can safely shut down the computer, but you still need to press the power button to turn it off instead of it shutting down by itself. Is there any way to do it?

[ Last edited by lulala on 2006-9-22 at 21:46 ]
Floor 7 Posted 2006-09-22 23:08 ·  中国 广东 东莞 电信
中级用户
★★
Credits 282
Posts 130
Joined 2006-09-20 22:25
19-year member
UID 63201
From 广东
Status Offline
Study hard. Make progress every day.

Got it, I'll take my time to read.
Floor 8 Posted 2006-09-23 01:46 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
Originally posted by lulala at 2006-9-22 21:34:
It is when under 2000 that the system prompts you that you can safely shut down the computer, but you still need to press the power button to turn it off, and it doesn't respond...


I haven't tested this either. It is suggested that the owner of the post change the title, such as a scheduled shutdown script under win2000...
业精于勤而荒于嬉,形成于思而毁于随。
Floor 9 Posted 2006-09-23 04:04 ·  中国 上海 上海乾万网络(QianWan_Network)有限公司(电信出口)
初级用户
Credits 44
Posts 17
Joined 2006-09-05 13:00
19-year member
UID 61900
Status Offline
I understand. It's just that every time I restart, there's an extra task in the task list, and the original task is still there, with at1, at2, at3.... Will it be automatically deleted?
Floor 10 Posted 2006-09-23 04:39 ·  中国 湖南 娄底 新化县 电信
银牌会员
★★★
Credits 1,218
Posts 485
Joined 2006-07-21 21:24
20-year member
UID 58987
From 湖南.娄底
Status Offline
Yes, if you restart the computer several times a day, the added scheduled task will be moved back.

The code to create a new scheduled task and delete the previous task has been added.

at /delete /yes
Floor 11 Posted 2006-09-23 10:23 ·  中国 上海 黄浦区 电信
初级用户
Credits 44
Posts 17
Joined 2006-09-05 13:00
19-year member
UID 61900
Status Offline
Floor 12 Posted 2006-09-25 11:56 ·  中国 江西 赣州 电信
高级用户
★★
论坛上抢劫的
Credits 551
Posts 246
Joined 2006-09-21 12:35
19-year member
UID 63270
Status Offline
```
for /l %%i in (100,1,123) do (
for /l %%a in (100,1,159) do (
if "1%time_:~0,2%"=="%%i" (
if "1%time_:~3,2%"=="%%a" (
goto start
)
)
)
)
```
Hey guys, I don't quite understand these few lines of code. Please explain it!!
Floor 13 Posted 2006-09-25 12:35 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Re lotus516:

  The function of pengfei's那段 code is to detect whether the input of hours and minutes is correct.

  Because the maximum number of hours cannot exceed 23, and the maximum number of minutes cannot exceed 59, and the input format requires that if the number of hours is less than 10, a 0 must be added in front. So, use the /l switch in the for statement to take numbers from 100 to 123, then add a 1 at the beginning of the number of hours and compare it with the value of %%i. If it is within that range, it means the input of hours is correct; the same principle applies to the detection of the input of minutes.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 14 Posted 2006-09-26 02:13 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
I also come to one:
@echo off
set password=
setlocal EnableDelayedExpansion

:index
cls
echo.
echo ====================================================
echo.
echo Please enter the daily shutdown time below. Format: (08:08)
echo.
echo To cancel the scheduled shutdown, just press Enter (enter "D" to display the scheduled task)
echo.
echo ====================================================
echo.
echo.
set time_=
set /p time_=Please enter the shutdown time and press Enter: %Display%

if "%time_%"=="" goto cancel
for %%i in (d D) do if "%time_%"=="%%i" schtasks&pause>nul&exit
if "%time_:~2,1%"==":" (
for /l %%h in (100,1,123) do if "1%time_:~0,2%"=="%%h" (
for /l %%m in (100,1,159) do if "1%time_:~3,2%"=="%%m" goto timing))
set Display=(The time format of "%time_%" is incorrect!)
goto index

:timing
echo.
for /f "skip=3 tokens=1,2* delims= " %%i in ('schtasks') do (
if "%%i"=="Scheduled Shutdown" set start=%%j
echo The "Scheduled Shutdown" scheduled task already exists, and it will be shut down daily at !start:~0,-4!!
echo If you want to reset it, please cancel the "Scheduled Shutdown" scheduled task first.
pause>nul&exit)
schtasks /Create /SC DAILY /TN "Scheduled Shutdown" /ST %time_%:00 /RU %username% /RP %password% /TR notepad
echo.&echo The system will be shut down daily at %time_%!&pause>nul&exit

:cancel
echo.
for /f "skip=3 tokens=1,2* delims= " %%i in ('schtasks') do (
if "%%i"=="Scheduled Shutdown" set start=%%j
schtasks /Delete /TN "Scheduled Shutdown" /F
echo The system deletes the "Scheduled Shutdown" scheduled task that shuts down daily at !start:~0,-4!
pause>nul&exit)
echo There is no "Scheduled Shutdown" scheduled task!&pause>nul&exit


Use "Task Scheduler" to execute, and it will take effect without restarting the system
First, "Start Menu - Accessories - System Tools - Task Scheduler - Advanced Menu - Start Advanced Scheduled Task Program". If the task scheduler has been enabled, there is no need to set it
Note that "schtasks" and "Task Scheduler" require the current user to set a password to use

"set password=" sets the password, which can also be entered later
Borrow part of pengfei's code and modify it (more efficient):
if "%time_:~2,1%"==":" (
for /l %%h in (100,1,123) do if "1%time_:~0,2%"=="%%h" (
for /l %%m in (100,1,159) do if "1%time_:~3,2%"=="%%m" goto timing))

First, judge whether the input time format is a format containing ":", then judge whether the "hour" exceeds "23", and after judging that the "hour" is correct, then judge whether the minute number exceeds "59"

[ Last edited by zxcv on 2006-9-25 at 14:17 ]
Floor 15 Posted 2006-09-26 02:18 ·  中国 甘肃 张掖 电信
金牌会员
★★★★
Credits 4,103
Posts 1,744
Joined 2006-01-20 13:00
20-year member
UID 49241
Gender Male
From 甘肃.临泽
Status Offline
It seems that we still need to check whether the Task Scheduler service is enabled!
Forum Jump: