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 ]