|
lulala
初级用户
 
积分 44
发帖 17
注册 2006-9-5
状态 离线
|
『楼 主』:
求1个有如下功能的批处理程序
使用 LLM 解释/回答一下
操作系统2000,执行一次批处理命令,提示用户在dos中输入每天关机时间,然后保存退出。到那个时间就调用另外一个批处理在那时间自动关机,最好是快速的关机那种,可以做到吗?
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?
|
|
2006-9-22 04:46 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
set /p time
at time
shutdown /s /f
set /p time
at time
shutdown /s /f
|
|
2006-9-22 07:32 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
注意: win2000下没有shutdown命令, 要使用下面的批处理, 请楼主请先在winxp的%windir%\sysytem32目录下拷贝shutdown.exe到win2000的相应目录.
@echo off
:index
cls
echo ====================================================
echo.
echo 请在下面输入每天关机的时间. 格式:(08:22)
echo.
echo 取消定时关机请直接回车
echo.
echo ====================================================
echo.
echo.
set time_=
set /p time_=请输入关机时间后按回车键:
if "%time_%"=="" goto cancel
:: 判断错误输入___________________________________________________
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 对不起你的输入有误, 请重新输入!
echo.
pause
goto index
:: 生成定时关机脚本_______________________________________________
: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 每天定时关机已启动.
echo =======================
echo.
echo.
pause
exit
:: 取消定时关机__________________________________________________
: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 定时关机已取消.
echo ==================
echo.
echo.
pause
草草写了段, 在XP下测试, 还很不完善. 不足的地方请指正!
Last edited by pengfei on 2006-9-23 at 04:37 ]
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 ]
|

业精于勤而荒于嬉,形成于思而毁于随。 |
|
2006-9-22 09:26 |
|
|
lulala
初级用户
 
积分 44
发帖 17
注册 2006-9-5
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
谢谢你啊,发现个问题一定要重新启动机器后才能实现自动关机,开着的时候把电脑时间再往预备关机时间前调一点就不能关机了
还有好象自动关机的时候读5秒后就黑屏了,看的见鼠标能动,但是就是关不掉,有什么办法吗
Last edited by lulala on 2006-9-22 at 11:42 ]
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 ]
|
|
2006-9-22 11:13 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
你好!
1. 一定要重启机器才能实现关机, 是因为只有重新启动才能激活计划任务. 修改了代码可以不用重启就激活定时关机的脚本, 但要是你的计划任务没有开启, 还是需要重启电脑的.
2. 把时间再往预备关机时间前调一点就不能关机了. 我想这可能是计划任务的问题. 或者是你测试的时候在两天的临界点
3. 读5秒后就黑屏, 执行了5秒强制关机. 可能系统出了点问题, 这里改为了30自动关闭, 好让应用程序先结束进程, 安全些.
Last edited by pengfei on 2006-9-23 at 02:45 ]
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 ]
|

业精于勤而荒于嬉,形成于思而毁于随。 |
|
2006-9-22 20:24 |
|
|
lulala
初级用户
 
积分 44
发帖 17
注册 2006-9-5
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
我应该谢谢你才对,问题已经解决,程序非常好,太谢谢拉!!
就是在2000下面的时候系统提示您可以安全的关闭计算机了,还要按电源再关,而不是自己关,有什么办法吗
Last edited by lulala on 2006-9-22 at 21:46 ]
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 ]
|
|
2006-9-22 21:34 |
|
|
jieok3375
中级用户
  
积分 282
发帖 130
注册 2006-9-20 来自 广东
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
好好学习。。天天向上啊。。。
偶收了,,慢慢看。。。
Study hard. Make progress every day.
Got it, I'll take my time to read.
|
|
2006-9-22 23:08 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
Originally posted by lulala at 2006-9-22 21:34:
就是在2000下面的时候系统提示您可以安全的关闭计算机了,还要按电源再关,而不映...
这个我也没测试过. 建议楼主把标题改一下, 如win2000下的定时关机脚本...
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...
|

业精于勤而荒于嬉,形成于思而毁于随。 |
|
2006-9-23 01:46 |
|
|
lulala
初级用户
 
积分 44
发帖 17
注册 2006-9-5
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
我懂拉,就是每次重新启动后,任务里就多出个任务,原来的任务还在,有at1,at2,at3....,会自动删除吗
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?
|
|
2006-9-23 04:04 |
|
|
pengfei
银牌会员
    
积分 1218
发帖 485
注册 2006-7-21 来自 湖南.娄底
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
是的, 如果你一天反复启动几次电脑, 所添加的计划任务将向后移.
新建一个计划任务同时删除先前任务的代码已经加入.
at /delete /yes
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
|
|
2006-9-23 04:39 |
|
|
lulala
初级用户
 
积分 44
发帖 17
注册 2006-9-5
状态 离线
|
|
2006-9-23 10:23 |
|
|
lotus516
高级用户
    论坛上抢劫的
积分 551
发帖 246
注册 2006-9-21
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
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
)
)
)
)
高手们这几代码不太看的懂,请解释一下!!
```
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!!
|
|
2006-9-25 11:56 |
|
|
namejm
荣誉版主
       batch fan
积分 5226
发帖 1737
注册 2006-3-10 来自 成都
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Re lotus516:
pengfei那段代码的功能是检测小时数和分钟数的输入是否正确。
因为小时数最大不能超过23,分钟数最大不能超过59,而且,输入格式要求,如果小时数如果小于10的话,前面必须带一个0,所以,就用 for 语句中的 /l 开关来取100到123的数字,然后通过在小时数的开头添个1来和 %%i 的值来做比较,如果在那个范围之内,则表明小时数输入正确;对分钟数的输入检测也是同样的道理。
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没商量。
考虑问题复杂化,解决问题简洁化。 |
|
2006-9-25 12:35 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
我也来一个:
@echo off
set 密码=
setlocal EnableDelayedExpansion
:index
cls
echo.
echo ====================================================
echo.
echo 请在下面输入每天关机的时间。 格式:(08:08)
echo.
echo 取消定时关机请直接回车 (输入“D”显示计划任务)
echo.
echo ====================================================
echo.
echo.
set time_=
set /p time_=请输入关机时间后按回车键: %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=(输入“%time_%”的时间格式错误!)
goto index
:timing
echo.
for /f "skip=3 tokens=1,2* delims= " %%i in ('schtasks') do (
if "%%i"=="定时关机" set start=%%j
echo “定时关机”计划任务已存在,于每天 !start:~0,-4! 定时关机!
echo 如要重新设置,请先取消“定时关机”计划任务。
pause>nul&exit)
schtasks /Create /SC DAILY /TN "定时关机" /ST %time_%:00 /RU %username% /RP %密码% /TR notepad
echo.&echo 系统于每天 %time_% 定时关机!&pause>nul&exit
:cancel
echo.
for /f "skip=3 tokens=1,2* delims= " %%i in ('schtasks') do (
if "%%i"=="定时关机" set start=%%j
schtasks /Delete /TN "定时关机" /F
echo 系统删除每天 !start:~0,-4! 定时关机的“定时关机”计划任务。
pause>nul&exit)
echo 没有“定时关机”计划任务!&pause>nul&exit
使用“任务计划”来执行,不需要重启系统即可生效
先“开始菜单-附件-系统工具-计划任务-高级菜单-开始启用高级计划任务程序”,已经开启计划任务的就不用设置了
注意,“schtasks”、“任务计划”需要当前用户设置密码才能使用
“set 密码=”设置密码,也可以后期输入
借用 pengfei 一部分代码修改(效率高些):
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))
先判断输入的时间格式是否是包含有“:”的格式,再判断“小时”是否超过“23”,判断“小时”正确后再判断分钟数是否超过“59”
Last edited by zxcv on 2006-9-25 at 14:17 ]
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 ]
|
|
2006-9-26 02:13 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
貌似还需要检查下 任务计划的服务有 没有开吧!
It seems that we still need to check whether the Task Scheduler service is enabled!
|
|
2006-9-26 02:18 |
|
|