admin管理员组

文章数量:1582030

bat实现自动关机命令

实现只支持整数数字输入,以及0001此类参数还原

@echo off &setlocal enabledelayedexpansion
color a
title 系统定时注销
ECHO.             〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
ECHO.             ■   定时关机命令   ■
ECHO.             〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
echo.
echo.             〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
echo.             ■   桔子 - 2024-1-9    ■
echo.             〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
:start_text
echo.
echo.
set /p str=■ 请输入设定关机的时间 (单位秒) 并按下回车键开始计时:
call :stringlenth %str% num
::echo 字符串长度为:%num%
if "%num%"=="" goto error
set /a stat=num-1
set key=false
set /a KeyNumber=0
for /l %%i in (0,1,%stat%) do (
set res=!str:~%%i,1!
set flag=false
echo !res! |findstr [0-9] >nul && set flag=true
if not !flag!==true goto error
if !res!==0 (
if %%i==0 (
set key=true
set /a KeyNumber+=1
) else if !key!==true (
set /a KeyNumber+=1
)
) else (
set key=false
)
if !key!==false (
set keyString=!keyString!!res!
)
if %%i==%stat% (
set key=false
set /a str1=!keyString!+1
title 系统将在 !keyString! 秒后注销关机
echo.
echo.
echo.             〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
echo.             ■ !keyString! 秒后注销关机设置已完成 ■
echo.             〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓〓
echo.
echo.
shutdown -s -t !str1!
set str2=""
set/p str2=■ 按【 Y 】键取消计划任务,或按任意键退出脚本...
if /i "!str2!"=="y" (
title 系统计划关机已取消.
echo ■ 系统计划关机已取消.
shutdown -a
pause >nul && exit /b
) else (
exit /b
)
)
)
endlocal
:error
echo ■ 输入的 %str% 格式错误!可能包含空格   参数需要为整数数字...
goto :start_text
cls
:StringLenth
set theString=%~1
if not defined theString goto :eof
set Return=0
:StringLenth_continues
set /a Return+=1
set thestring=%thestring:~0,-1%
if defined thestring goto StringLenth_continues
if not \"%2\"==\"\" set %2=%Return%
goto :eof

本文标签: 自动关机命令bat