本帖最后由 koi1 于 2024-3-13 10:44 编辑
某一天在win10需要用at shutdown -s 来定时关机时发现at命令已被弃用。于时才写了这个。
自定关机.bat
@echo off
title 自定时间关机 & color 02 & mode con: COLS=60 LINES=20
echo.
goto chooseday
:setdown
set nxdy=%1
set s=0
set m=0
set h=0
set seth=0
set setm=0
set ab=关机时间:
set abb=现在时间:
set ab1=后关机,设定后若重启无效
set bc1=取消关机:shutdown -a
echo.
set /p seth=输入要关机的时:
if %nxdy% equ 0 (
call:isint %seth% 1 0 )
if %nxdy% equ 1 (
call:isint %seth% 1 1 )
set /p setm=输入要关机的分:
if %nxdy% equ 0 (
call:isint %setm% 2 0 )
if %nxdy% equ 1 (
call:isint %setm% 2 1 )
set h1=%time:~0,2%
set m1=%time:~3,2%
set s1=%time:~6,2%
if %nxdy% equ 0 if %seth% lss %h1% (
echo. 只能设定当天的
goto chooseday )
if %nxdy% equ 0 if %seth% equ %h1% (
if %setm% lss %m1% (
echo. 只能设定当天的
goto chooseday ) )
CLS
if %nxdy% equ 0 (
set /a needh=%seth%-%h1% )
if %nxdy% equ 1 (
set /a needh=24-%h1%+%seth% )
if %setm% lss %m1% (
set /a needh=%needh%-1
set /a needm=%setm%+60-%m1% )
if %setm% geq %m1% (set /a needm=%setm%-%m1%)
set /a hs=%needh%*60*60
set /a ms=%needm%*60
set /a needs=%hs%+%ms%-%s1%
echo.
echo. %abb% %h1%:%m1%:%s1%
echo. %needh%时%needm%分%ab1%
echo. %ab% %seth%:%setm%
echo.
echo.
shutdown -s -f -t %needs%
goto chooseday
:canceldown
shutdown -a
set cc=已取消关机
if %errorlevel% equ 0 (
echo. %cc% )
goto chooseday
:mychooce1
set /p mysel=设置/取消关机(Y/N):
if "%mysel%" == "Y" (call:setdown 0 )
if "%mysel%" == "y" (call:setdown 0 )
if "%mysel%" == "N" (goto canceldown )
if "%mysel%" == "n" (goto canceldown )
goto mychooce1
:mychooce2
set /p mysel=设置/取消关机(Y/N):
if "%mysel%" == "Y" (call:setdown 1 )
if "%mysel%" == "y" (call:setdown 1 )
if "%mysel%" == "N" (goto canceldown )
if "%mysel%" == "n" (goto canceldown )
goto mychooce2
:chooseday
set dp=%~dp0
::set ndy=nextdy.bat
set atk=stdwtask.bat
set /p daysel=选择当日/跨日/计划任务每天,定时关机(D/M/E):
if "%daysel%" == "D" ( goto mychooce1 )
if "%daysel%" == "d" ( goto mychooce1 )
if "%daysel%" == "M" ( goto mychooce2 )
if "%daysel%" == "m" ( goto mychooce2 )
if "%daysel%" == "E" ( call %dp%%atk% )
if "%daysel%" == "e" ( call %dp%%atk% )
goto chooseday
:isint
set intst=%1
set hm=%2
set dyy=%3
set /a isn=intst
if %isn% neq %intst% (
echo. 不是整数,重新输入
if %dyy% equ 0 (
call:setdown 0 ) else (
call:setdown 1 )
) else (
if %intst% lss 0 (
echo. 小于0,重新输入
if %dyy% equ 0 (
call:setdown 0 ) else (
call:setdown 1 )
)
if %hm% equ 1 (
if %intst% geq 24 (
echo. 大于等于24,重新输入
if %dyy% equ 0 (
call:setdown 0 ) else (
call:setdown 1 )
)
)
if %hm% equ 2 (
if %intst% geq 60 (
echo. 大于等于60,重新输入
if %dyy% equ 0 (
call:setdown 0 ) else (
call:setdown 1 )
)
)
)
goto eof
:eof
运行图:
第三个选项计划任务每天定时关机脚本在17楼
|