1.Win10定时关机(如17:10)
作者:
狼少丷 | 来源:发表于
2024-02-25 15:18 被阅读0次@echo off
set /p shutdown_time=请输入关机时间(格式为HH:MM):
echo 将要在%shutdown_time%进行关机!
rem 延迟多少秒执行
@REM timeout /t 3 > nul
REM 将输入的关机时间转换为秒数并减去当前时间的秒数
for /f "tokens=1-2 delims=: " %%a in ("%shutdown_time%") do (
set /a shutdown_hours=%%a
set /a shutdown_minutes=1%%b-100
)
rem 获取当前时间的小时和分钟
for /f "tokens=1-2 delims=: " %%a in ("%time%") do (
set /a current_hours=%%a
set /a current_minutes=1%%b-100
)
rem 转换成当前时间的总秒数
set /a current_seconds=(current_hours * 3600) + (current_minutes * 60)
set /a shutdown_seconds=((shutdown_hours * 3600) + (shutdown_minutes * 60)) - current_seconds
shutdown /s /t %shutdown_seconds%
:: 两种执行方式
@REM shutdown -s -t %shutdown_seconds% -f ::定时任务
@REM schtasks /create /sc once /tn "Shutdown" /tr "shutdown -s -f -t 00" /st %shutdown_time% ::创建定时任务
setlocal
:loop
set /p choice=是否要继续? (y/n):
if "%choice%" == "y" (
rem 执行关机
echo 将执行关机任务.
) else if "%choice%" == "n" (
rem 取消关机计划
echo 关机任务已取消.
shutdown /a
) else (
rem 重新选择
echo 无效的选择。请选择 y 或 n.
goto loop
)
endlocal
本文标题:1.Win10定时关机(如17:10)
本文链接:https://www.haomeiwen.com/subject/qesaadtx.html
网友评论