![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-02 03:32 |
48,037 topics / 350,122 posts / today 2 new / 48,250 members |
| 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. |
| Printable Version 1,501 / 14 |
| Floor1 lulala | Posted 2006-09-22 04:46 |
| 初级用户 Posts 17 Credits 44 | |
|
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?
|
|
| Floor2 vkill | Posted 2006-09-22 07:32 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
|
set /p time
at time shutdown /s /f |
|
| Floor3 pengfei | Posted 2006-09-22 09:26 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
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 ] |
|
| Floor4 lulala | Posted 2006-09-22 11:13 |
| 初级用户 Posts 17 Credits 44 | |
|
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 ] |
|
| Floor5 pengfei | Posted 2006-09-22 20:24 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
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 ] |
|
| Floor6 lulala | Posted 2006-09-22 21:34 |
| 初级用户 Posts 17 Credits 44 | |
|
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 ] |
|
| Floor7 jieok3375 | Posted 2006-09-22 23:08 |
| 中级用户 Posts 130 Credits 282 From 广东 | |
|
Study hard. Make progress every day.
Got it, I'll take my time to read. |
|
| Floor8 pengfei | Posted 2006-09-23 01:46 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
Originally posted by lulala at 2006-9-22 21:34: 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... |
|
| Floor9 lulala | Posted 2006-09-23 04:04 |
| 初级用户 Posts 17 Credits 44 | |
|
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?
|
|
| Floor10 pengfei | Posted 2006-09-23 04:39 |
| 银牌会员 Posts 485 Credits 1,218 From 湖南.娄底 | |
|
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 |
|
| Floor11 lulala | Posted 2006-09-23 10:23 |
| 初级用户 Posts 17 Credits 44 | |
| Floor12 lotus516 | Posted 2006-09-25 11:56 |
| 高级用户 Posts 246 Credits 551 | |
|
```
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!! |
|
| Floor13 namejm | Posted 2006-09-25 12:35 |
| 荣誉版主 Posts 1,737 Credits 5,226 From 成都 | |
|
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. |
|
| Floor14 zh159 | Posted 2006-09-26 02:13 |
| 金牌会员 Posts 1,467 Credits 3,687 | |
|
I also come to one:
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%"==":" ( 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 ] |
|
| Floor15 vkill | Posted 2006-09-26 02:18 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
|
It seems that we still need to check whether the Task Scheduler service is enabled!
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |