CODE: [Copy to clipboard]
@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
使用“任务计划”来执行,不需要重启系统即可生效